WIKI : Sample apps with Modbus protocol over serial port

Hello all,

Just a message to share with you small application who use a FDTI USB serial port and modbus protocole.

This is a good base if you want to implement data access with serial port over modbus protocol.
Only function 3 and 16 are implemented with CRC calculation but it’s easy to add more.

I use le_fdMonitor_Create() to pollin into a handler incomming modbus messages. Apps use a circular buffer to “eject” bad data and read only a good modbus frame. You will find example to read/write data to a C Struct over modbus.

This was tested with MAngoh red and WP76 / R9 and legato 18.05. Driver for FDTI USB serial port is loaded at apps startup.

wiiq3Monitor.zip (162.9 KB)

Example : connect a USB FDTI serial converter to main USB connector

start apps

open a terminal at 115200bps (I use Hercules terminal for ex)
send this modbus frame :

{01}{03}{12}{4D}{00}{10}{D1}{69}
-> Slave address = 0x01 function 0x03 address 0x124D and read 16 registers (0x0010) CRC frame is 0xD169

-> check the answer
{01}{03}{20}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{00}{92}{7A}

-> 0x01 slave address
-> 0x03 function 0x03
-> 0x20 is 16 registers of 2 bytes = 32 bytes
-> after is data mapped to the CStruct at 0x124D
-> 0x927A is the CRC

Have a nice day.
Francis.

2 Likes

Hi

Probably this is the only example out there on Legato for serial port communications. I have used this code for basic serial port communication. Picked serial.c/.h and relevant configurations. Built and uploaded the code in to mangOH Red.

Application exits because it could not find comport. (error no 2). I have added the /dev/ttyHS0 and /dev/ttyHSL1 for R/W. But open port fails always. Tested on both ports.

Both ports are available in /dev folder. If the ports are already in use, I think the error no. should have been something like ‘access denied’. Actual plan is to use the console USB to push data into PC (testing phase only)

Is there anything I am missing?

Thanks

Can try with unsandboxed apps?
I use Ftdi usb serial converter without any issue.

My apps are unsandboxed.

Francis

Thank you Francis. I will try unsandboxing.

Unsandboxing did the trick. It works now and I am able to get the Apps serial out on the console port.

Thanks Francis.

1 Like

Any updates you can share on your Modbus implementation?
…would be most appreciated!
Thanks