Serial to SerialPort Object conversion

1 次查看(过去 30 天)
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.

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by