Module modbus

Modbus in Toggle

Toggle has a built-in Modbus TCP server. It can be used to read and write I/Os. Modbus server is implemented in the iod service. It uses the libmodbus library to implement the Modbus protocol.

Configuration

For the Modbus server to be accessible, it must be enabled in configuration. See the configuration section for more details.

Port

Modbus server listens on TCP port 502. Enabling the Modbus server also enables a firewall rule that allows access to port 502 from the WAN interface.

Modbus addressing

Toggle exposes 3 I/O chains through Modbus addressing: 0 - GPIO, 1 - EtherCAT, 2 - EtherCAT P. Each chain (except GPIO) can have up to 16 modules connected in series. Each module can have up to 16 I/O channels. GPIO chain has 1 default module with 2 input and 2 output I/O channels.

Note: The numbering of modules and channels starts with 1. But Modbus's addressing starts with 0.

The high byte of the address specifies the chain, the upper nibble of the low byte specifies the module, and a lower nibble of the low byte specifies the channel.

Addressing scheme:

XXXXXXXX XXXXXXXX - available addressing space
^^^^^^^^ - chain (0 - 2)
^^^^ - module (0 - 15)
^^^^ - channel (0 - 15)
00000010 11111111 - highest address (0x02FF)

Examples

  • 0x0000 - GPIO, input 1

  • 0x0001 - GPIO, input 2

  • 0x0002 - GPIO, output 1

  • 0x0003 - GPIO, output 2

  • 0x0100 - EtherCAT, module 1, I/O 1

  • 0x0111 - EtherCAT, module 2, I/O 2

  • 0x0200 - EtherCAT P, module 1, I/O 1

  • 0x0211 - EtherCAT P, module 2, I/O 2

Note: Trying to read or write I/O that is not connected or the module is not enabled in configuration will result in an error.

Functions

Only two functions are implemented:

  • 0x01 - Read coils
  • 0x05 - Write single coil

Testing

For testing, I used the modbus-cli utility written in Python. It can be used like this:

# Address 256 corresponds to EtherCAT module 1, I/O 1
./modbus 192.168.180.1 c@256=1 # Set value to 1
./modbus 192.168.180.1 c@256=0 # Set value to 0
./modbus 192.168.180.1 c@256 # Read value

Index

Type Aliases

Generated using TypeDoc