App designer: serialport blocks assignin?

5 views (last 30 days)
Hi all,
I'm making an app using matlab app designer - it needs to communicate over serial with an arduino.
At some point I'd like to send collected data to the base (whilst keeping the serial port open preferably) - assignin would be ideal. However, it seems like creating a serial port, even if you are not using it, prevents assignin from working? For instance, I could add these few lines of code into the startup function of an app (otherwise completely empty.) The three variables arrive together in the base after the final 10 seconds of pausing, rather than when I call them.
a = serialport('/dev/tty.usbmodem14201',9600) %for arduino mega
assignin("base", "test1",1);
pause(1)
assignin("base", "test2",2);
pause(1)
assignin("base", "test3",3);
pause(10)
I don't mind if the solution is writing to a file/closing and reopening the serialport (but how do you do that with the new serialport functions?) or even rebooting the app - any ideas would be appreciated.
(I've been told by some that sometimes assignin isn't reliable, but by others that this particular use of assignin is fine)
(I'm new to matlab so sorry if I've missed something, and sorry if I haven't used the forum correctly!)

Answers (1)

Walter Roberson
Walter Roberson on 2 Aug 2022
You are mistaken. The result of assignin() happen immediately, before the next operation.
What does not happen immediately is that the Workspace Browser is not updated until control is returned to the command line. That does not mean that the assignment did not happen, just that the debugging view does not get changed for efficiency reasons.
  4 Comments
Lawrence Schofield
Lawrence Schofield on 2 Aug 2022
Thanks for your suggestion. I've tried using keyboard and quit, but the variables still only become visible when I close the app, rather than whilst I'm still using it. Sorry!
Walter Roberson
Walter Roberson on 3 Aug 2022
Correction: use dbcont rather than "exit" or "quit" !!
... It is working when I test using keyboard(), having opened the workspace browser before starting the code. Though it looks to me as if
evalin('base', 'workspace')
should be able to open the workspace browser to the base workspace at run-time -- though with testing I notice that the contents of the browser will not get updated until the program returns to the command line.

Sign in to comment.

Categories

Find more on Desktop in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!