Clear Filters
Clear Filters

MODBUS communication error/timeout when trying to read from a MODBUS device over serial port

30 views (last 30 days)
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

Answers (1)

Tristan Yang
Tristan Yang on 2 Jan 2018
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').
  1 Comment
Gareth Jenkins
Gareth Jenkins on 8 Jan 2018
Thanks for the reply. I did try increasing the timeout to 20 secs with the same result. I also tried using 'inputregs' instead of 'holdingregs' with no luck.
One thing which puzzles me is that I can't find any mention in the documentation as to performing either an LRC or CRC (longitudinal redundancy check or cyclic redundancy check).
My device definitely requires LRC but maybe Matlab is doing CRC or something else (or nothing at all)?
Could this be the problem?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!