MATLAB Answers

What is the correct way to close a serialport connection in App Designer?

33 views (last 30 days)
Nolan King
Nolan King on 9 Mar 2020
Commented: Nolan King on 30 Mar 2020
As per the the serialport documentation, the way to create and delete a serial connection should be
s = serialport(device,baudrate);
clear s;
However, in app designer, I want multiple functions to be able to read/write to the port, so I have made s a property of the app. You can't clear an app property thought. So what is the correct way free app.s so it can be reconnected to the same device later?
Failing to clear s gives the usual error of "Unable to connect". Setting app.s to some other value, and then creating a new serialport object doesn't close the old connection (i suppose it overwrites the location of the serialport object).

  0 Comments

Sign in to comment.

Answers (1)

Harsha Priya Daggubati
Harsha Priya Daggubati on 27 Mar 2020
Edited: Harsha Priya Daggubati on 27 Mar 2020
Hi,
I guess you can set app.s to an empty value, after all the intended work is done.
Link to a similar question:
Hope this helps!

  1 Comment

Nolan King
Nolan King on 30 Mar 2020
Unfortunatly that doesn't close the serial connection, which is the point of clearing the variable.

Sign in to comment.

Sign in to answer this question.