Hello all
I am currently trying to develop an instrumentation and control panel for an experiment which interfaces using Modbus RTU. I have a code snippet below for the logging. However ideally, I would also like to be able change some digital output on the device by clicking a button on the computer. The only way I can think of doing this is with an App with callbacks any time the button is pressed. However, since I need to poll the device I can't use a callback for the logging and so can't work out to keep it running continually. Any advice would be greatly appreciated.
Thanks,
Martin
close all
m = modbus('serialrtu', 'COM4');
m.Timeout = 3;
serverId = 2;
data = read(m, 'holdingregs', 1, 1, serverId, 'int16');
t = 0
tic
while 1==1
data = [data;read(m, 'holdingregs', 1, 1, serverId, 'int16')];
t = [t,toc];
plot(t,data)
drawnow
pause(1)
end
clear m

 채택된 답변

Martin O'Connor
Martin O'Connor 2021년 1월 21일

0 개 추천

I have done some further digging and realised I should probably use a timer object. Apologies for the preemptive post.
https://uk.mathworks.com/matlabcentral/answers/297381-how-to-implement-a-timer-in-appdesigner

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Modbus Communication에 대해 자세히 알아보기

제품

릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by