Search code examples
rubymodbus

Formatting Modbus requests in ruby


I have a modbus device I am trying to communicate with using an ethernet to RS485 device. I'm not sure whether the device uses modbus ASCII or RTU.

I am trying to format a request to a device with address 1. The command code is 11h. I'm not sure I'm formatting the request properly

Here is the string I am using for ASCII - ":010B000000000C\x0D\x0A"

Here is the hex I'm using for RTU: "\x01\x0B\x00\x00\x00\x00\x0B\xA4"

When I send this command it is echoed back but I'm not getting responses. I've been through the modbus documentation and I think I have the correct byte structure. I'm wondering if I'm encoding it right for ruby?


Solution

  • It turned out my ethernet to RS485 device wasn't capable of the correct timing for modbus. Once I purchased a new unit the ascii strings worked.