Serial to SerialPort Object conversion

1 Ansicht (letzte 30 Tage)
Jason
Jason am 6 Jan. 2020
Im porting my RS232 code from serial to the new serialport as suggested in 2019b.
I had previously used to check if any ports are open and if they are then close via:
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
delete(s) % s is my serial object (s=serial('Com1', etc...))
end
The documentation suggests not to use instrfind but serialportlist.
How would the above be achieved using this new command?
I also ran into an error using fopen & fclose with the new serialport object, but fortunately found this post from Walter!
The new serialport() interface does not use fopen() or fclose() . You just delete the object to close it.
I prefer the fopen() / fclose() interface myself... but then I used to write modem control programs where it was common to want to configure a port and open and close it while not deleting it.

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by