2410_LSS100100/LSS100200_SW_03.0

Modbus RTU Configuration Commands

To configure Modbus RTU communication in the controller, follow these steps:

  1. Create a Modbus RTU object:

    require('luamodbus') 
    mb = luamodbus.rtu()

  2. Open Modbus RTU connection:

    • Set the communication parameters (baud rate, parity, data bits, stop bits, and duplex mode).

    • Example (19200 baud rate, even parity, 8 data bits, 1 stop bit, half duplex):

      mb:open('/dev/RS485', 19200, 'E', 8, 1, 'H')
      mb:connect()

  3. Terminal name:

    • The terminal name is /dev/RS485.

  4. Supported baud rates:

    • Choose from the following baud rates:

      • 300 bit/s

      • 600 bit/s

      • 1200 bit/s

      • 2400 bit/s

      • 4800 bit/s

      • 9600 bit/s

      • 19200 bit/s

      • 38400 bit/s

      • 57600 bit/s

      • 115200 bit/s

      • 230400 bit/s

  5. Parity:

    • Set the parity mode:

      • “N” (None)

      • “E” (Even)

      • “O” (Odd)

  6. Data bits and stop bits:

    • Data bits: Choose from 5, 6, 7, or 8.

    • Stop bits: Choose either 1 or 2.

    • Duplex mode:

      • “H” (Half duplex)

      • “F” (Full duplex, not supported in RS-485)

  7. Baud rate considerations:

    • The baud rate affects communication distance:

      • 9600 bit/sec: Max distance for 1-15 Modbus RTU devices is 1200 meters.

      • 19200 bit/sec: Max distance is 900 meters (typical with Belden 3105A cables).

        Baudrate setting

        Maximum communication distance for 1 to 15 Modbus RTU devices (Typical with Belden 3105A cables)

        9600 bit/sec

        1200 m

        19200 bit/sec

        900 m

  8. Parity explanation:

    • Parity checks for successful transmission.

    • Odd parity: Odd number of 1s.

    • Even parity: Even number of 1s.

    • Both gateway and meter must match (odd, even, or none).

  9. Delay between frames:

    • Some devices need extra time after a response.

    • Use the delay command (e.g., os.sleep(1.5)).

  10. Set extension address:

    • Set slave address (e.g., mb:setslave(123)).

  11. Read registers:

    • Read from address 1000 and store the value:

      value = mb:readregisters(1000)
  12. Close Modbus connection:

    mb:close()
  13. Timeout intervals:

    • Adjust timeout intervals as needed:

      • Byte timeout: 

        mb:getbytetimeout()
        mb:setbytetimeout(timeout)

      • Response timeout: 

        mb:getresponsetimeout()
        mb:setresponsetimeout(timeout)

      • Receive timeout (extension mode only): 

        mb:getreceivetimeout()
        mb:setreceivetimeout(timeout)

  14. Example initialization:

    • Initialize Modbus on first script execution:

      if not mb then
           require('luamodbus')
           mb = luamodbus.rtu()
           mb:open('/dev/RS485', 38400, 'E', 8, 1, 'H')
           mb:connect()
       end
       mb:setslave(30)
       mb:flush()

QR Code is a registered trademark of DENSO WAVE INCORPORATED in Japan and other countries.

Was this helpful?