G-code
Special commands

Modbus

9min

Modbus command can be used to communicate with other devices over Modbus protocol.

Please note that your controller board needs to have the Modbus feature and that the controller board has to be the master device.

ModBus <s> <f> <a> <n> <v> <u> <b> <fb>

Parameters

  • s defines the slave number.
  • f function number
  • a address
  • n number of bits or registers
  • v value
  • u user variable
  • b baud rate
    • If not specified, baud rate of 115200 is used
  • fb parity / stop bits configuration designation
    • If not specified, no parity and 2 stop bits are used

Supported baud rates

  • 9600
  • 19200
  • 38400
  • 57600
  • 76800
  • 115200

Supported function numbers







1

RMC

Read Multiple Coils

2

RDI

Read Discrete Inputs

3

RMR

Read Multiple Registers

4

RMIR

Read Multiple Input Registers

5

WSI

Write Single Coil

6

WSR

Write Single Registers

15

WMC

Write Multiple Coils

16

WMR

Write Multiple Registers

17

RS

Report SlaveID

The abbreviation can be used instead of the number, so F=RMC or F RMC is equal to F1

Parity / stop bits configuration designations

Setting

Parity

Stop bits

E1

even

1

O1

odd

1

N2

none

2

N1

none

1



Example

Write single coil

Modbus s1 f5 a0 v1

Write single coil, baud rate of 19200, even parity with 1 stop bit

Modbus s1 f5 a0 v1 b19200 fb=e1

Read multiple coils, store beginning at user variable #300

modbus s1 f=rmc a0 n8 u300 msg "c0="#300 " c1="#301 " c2="#302 " c3="#303 " c4="#304 " c5="#305 " c6="#306 " c7="#307

Read discrete inputs

modbus s1 f=rdi a0 n8 u400 msg "i0="#400 " i1="#401 " i2="#402 " i3="#403 " i4="#404 " i5="#405 " i6="#406 " i7="#407

Write single register

modbus s1 f6 a0 v255

Write multiple coils

#500=0 #501=1 #502=0 #503=1 #504=0 #505=1 #506=0 #507=1 modbus s1 f15 a0 n8 u500

Write multiple holding registers

#600 = 1 #601 = 2 modbus s1 f16 a0 n2 u600

Report slave id

modbus s1 f17