1]Change variable value during script is running 2] while running Script in loop does not update variable value in workspace
조회 수: 5 (최근 30일)
이전 댓글 표시
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
David Powers
2015년 8월 6일
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.
답변 (1개)
Walter Roberson
2012년 11월 6일
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
Walter Roberson
2012년 11월 6일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!