Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Modbus Slave response -> Timeout and Insufficient bytes received

tramanah
2019-08-16
2019-08-18
  • tramanah - 2019-08-16

    Hi, good day.

    I did setup raspberry pi 3B+ on Codesys with the interface to TRI plc via RS485. Raspberry pi as master, I do manage pull data from TRI plc on Modbus RTU without any error. While setup Modbus slave on same raspberry pi shows successful but while trying pulling data via pc with using Modbus Poll, an error message shows "Timeout" and "Insufficient bytes received", one after one.
    I did use USB dongle (USB-RS485) 2 units for both communications.

    Modbus Poll : Setup as follow:-
    Serial port setup : COM 1 / 9600 / 8 / None / 1
    Slave id :2
    Function : Read holding Register (4x)
    Address : 0
    Quantity : 4
    Scan Rate : 1000 ms

    Communication Traffice: -
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Rx: 21 F7
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Tx: 02 03 00 00 00 04 44 3A
    Rx: 21 F7

    so on...

    IMG: pic1.png

     
  • tramanah - 2019-08-18

    Hi Guys,

    After trying all the chances and went through most of the forums on Modbus communication, finally, manage to resolve. I did test the Modbus slave first. Make sure the connection setting are correct and manage to read data from raspberry pi.

    CODESYS setup as follow:-
    Modbus_COM->Serial Port Configuration: <Comport: 1><Baudrate:9600><parity:none><databits:8><stopbits<1>
    Modbus_Serial_Device-><unitid:1> and the rest up to your setting</unitid:1></stopbits<1></databits:8></parity:none>

    In raspberry pi setting at: etc/CODESYSControl.cfg

    [SysCom]Linux.Devicefile=/dev/ttyUSB
    while in terminal ls /dev: make sure USB device are ttyUSB0

    In PC, use any Modbus Master software to pull data. Make sure able to read data.

    Next, set up the Modbus Master in CODESYS to pull data from Tri-PLC

    CODESYS setup as follow:-
    Modbus_COM_1->Serial Port Configuration: <Comport: 2><Baudrate:38400><parity:none><databits:8><stopbits<1>
    Modbus_MASTER_COM_Port-> In General tab, enable Auto-restart communication and rest leave as default
    Modbus_Slave_COM_Port -> In General tab, set the tri-plc device id and setup the Modbus channel and Modbus Mapping.</stopbits<1></databits:8></parity:none>

    No changes in Raspberry pi setting
    while in terminal ls /dev: make sure USB device are ttyUSB1

    That's it.

    But if power reset on raspberrypi than we have issues on ttyUSB0 and ttyUSB1, its been swapped. How to resolve this?

     
  • tramanah - 2019-08-18

    Hi Good day,

    I did try out syslink on the following link:

    https://unix.stackexchange.com/questions/395962/kernels-path-for-usb-device-connected-to-hub

    after adding in the KERNELS for both USB port accordingly, I did update with the following command:-

    ln -s ttyUSB0 ttyRPI0
    ln -s ttyUSB1 ttyRPI1

    you may check the name will appear on command: ls /dev

    Note: incase if you want to remove the syslink the command is: rm ttyRPI0 or rm ttyRPI1 than remove the KERNELS

    In raspberry pi setting at: etc/CODESYSControl.cfg

    [SysCom]
    Linux.Devicefile=/dev/ttyRPI
    I did restart multiple time and the system works well now.

     

Log in to post a comment.