Modbus ASCII Communication

Hi all!

I'm having a difficult time to find sources regarding Modbus ASCII Communication using Arduino. I need to read data from a magnetic sensor which allows only Modbus ASCII with RS232.

I found a library ( Arduino/MODBUS/ASCII/libraries at master · pepsilla/Arduino · GitHub ) but there is no example program or anything. I know that Modbus ASCII became old-fashioned, but it is my only chance.

Also, I wanna know how to send ": 01 04 20C1 0002 LRC CRLF" hex data.

I'd be grateful for any lead, idea that you guys could give.

I found a library ( Arduino/MODBUS/ASCII/libraries at master · pepsilla/Arduino · GitHub ) but there is no example program or anything.

There is an example sketch but the example is very confusing because it contains more stuff that should be in the slave than in the master. But you can use it that way. As you failed to provide a link to the actual device you want to read it's up to you to adapt the example to your needs.

pylon:
There is an example sketch but the example is very confusing because it contains more stuff that should be in the slave than in the master. But you can use it that way. As you failed to provide a link to the actual device you want to read it’s up to you to adapt the example to your needs.

It is MGSW1600 model magnetic sensor of Roboteq’s. I attached the necessary images below.

It is MGSW1600 model magnetic sensor of Roboteq's. I attached the necessary images below.

Using the information Google finds for this sensor I'm not sure it supports Modbus. The datasheet says CAN bus, USB and serial but nothing about Modbus or Modbus ASCII.

Have you tried the example to read some registers?

What type of Arduino are you using? Keep in mind that baud rates of 115200 can only be handled using the hardware serial interface and will fail with a serial emulation.

That's why I was mistaken to buy the sensor. They did not provide any data about the details of the communication protocol. Writing an e-mail to tech support, I then learned about the communication protocol being Modbus ASCII.

I wasn't able to try any examples since the equipment I ordered hasn't reached me yet. I'm currently trying to learn about how Arduino establishes serial communication and if it is possible to send ": 01 04 20C1 0002 LRC CRLF" and read ": 01 04 04 00001234 LRC CRLF" as a whole.

I'm using an original Arduino Mega 2560, and don't plan to use any software emulator.

hi, are you resolved this problem ?

Modbus is simply a packet protocol and can be used with several physical layers (RS-232, UART, TCP/IP, etc.). In short, there is not "Modbus Connector", so you may have actually have accurate documentation. I'm sure if you properly wire up and power the sensor, you could do the following to establish communication:

char packet[] = ":0104040000123431\r"
Serial.print(packet);