1]Change variable value during script is running 2] while running Script in loop does not update variable value in workspace
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am controlling a pilot plant of boiler through Matlab using modbus RTU (serial communication).I am running my control program (in editor) for 45 mins through a loop but I am facing two problems 1] I can't change any variable value while running program which is deadly needed. 2] I am unable to see real time data in workspace while running script. It updates all variables after finishing execution time. For my application I want data to appear for every iteration.
I couldn't solve them so I switched to simulink but that was even more frustrating.In simulink i used user defined blocks (embedded Matlab function) to generate modbus address PDU which does not support to in-built matlab functions (like dec2hex).Will please someone let me know in simulink, serail send/receive support which data formate?(ASCII/HEX/DEC)
Will please someone guide me for these problems? I am near to end my patience.
Thank you in advance.
1 commentaire
David Powers
le 6 Août 2015
Really need to write our own gui to do this. But you can use the debugger using dbstop, e.g. stop every 10th time it reaches line 8: dbstop in test_workspace.m at 8 if mod(X,10)==0
You can change variables and continue.
A better approach is to use input which allows you to evaluate an expression and input it to a variable.
But still it requires stopping - but you might be able to use pmode and have one thread for enquiry while the others continue.
Réponses (1)
Walter Roberson
le 6 Nov 2012
In order to change variable values, the control program needs to retrieve the value from a shared location, and the control program needs to occasionally give the GUI a chance to interrupt for a moment in order allow the GUI to set the shared value. Then you have a callback in the GUI that sets the new value. The routine that the control program needs to use in order to give the GUI a chance to update values is drawnow().
To have data appear every iteration, disp() it, or fprintf() it.
3 commentaires
Walter Roberson
le 6 Nov 2012
If the changed data is coming from the serial port, you could use the serial object BytesAvailableFcn callback to set a shared variable that your computation code specifically looks at from time to time.
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!