MODBUS communication error/timeout when trying to read from a MODBUS device over serial port
29 次查看(过去 30 天)
显示 更早的评论
Hi
I am trying to connect Matlab to a detector which uses the MODBUS protocol over a serial port. I can connect via a terminal program and read and write commands manually (e.g. :000301020002f8 will read register address 258) and I can also do this in Matlab using the instrument control toolbox to open a serial port connection in the same way.
I then try to create a modbus object using the MODBUS command: m = modbus('serialrtu','COM13','Baudrate',57600) which seems to work.
However, I can't read any data from it. e.g. read(m,'holdingregs',258,1) will give the error: A communication error occurred while reading from the Modbus server: Timeout occurred waiting for a response.
I am a Matlab and MODBUS novice so it is possible I have fundamentally misunderstood something but I can't find any clues in the documentation.
I just want to make a simple script to control the detector and had hoped the MODBUS support would simplify this effort (e.g. so I don't need to calculate the LRC each time) but maybe it is not so straightforward?
Any help or advice would be much appreciated.
Best regards
Gareth
0 个评论
回答(1 个)
Tristan Yang
2018-1-2
Hi Gareth,
The syntax of the usage seems to be right. Please try to set the timeout to a longer period and make sure the target area argument is setting correctly ('inputregs' vs. 'holdingregs').
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modbus Communication 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!