Closing an RS232 serial port connection, if open

2 visualizaciones (últimos 30 días)
Jason
Jason el 12 de Mzo. de 2015
Comentada: Jason el 13 de Mzo. de 2015
Hello. I am using the following code to open, send a command and receive a response - it works fine:
s = serial('COM1');
set(s,'BaudRate',4800);
fopen(s);
fprintf(s,'o')
out = fscanf(s);
What is the best way to close, delete or remove the serial object to prevent my external device hanging up:
I have an exit button where I would need to pass the s serial object and then do what ever is the appropriate operation. However, not all of the times I open the coms port, so I would need to account for cases where the coms port is not open.
Thanks for any advice. Jason
  1 comentario
Jason
Jason el 13 de Mzo. de 2015
Just to add I have used:
fclose(s)
delete(s)
But this causes matlab to hang.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by