Application Examples • 175
Example of a Modbus TCP Server
WAGO-I/O-SYSTEM 750
Linux Fieldbus Coupler
8.3 Example of a Modbus TCP Server
Program name: mb_tcp
Installation directory: /bin/mb_tcp
Source code files:
~/uclinux-dist/user/modbus/mb_tcp.h
~/uclinux-dist/user/modbus/mb_tcp.c
~/uclinux-dist/user/modbus/mbfunc.h
~/uclinux-dist/user/modbus/mbfunc.c
~/uclinux-dist/user/modbus/mbtypes.h
~/uclinux-dist/user/modbus/mbserver.h
~/uclinux-dist/user/modbus/mb_udp.c
Driver/Kernel modules: kbus.o (internal bus support)
Note
This example for a Modbus implementation does not completely comply with
the Modbus specification. It is only an example for the implementation of a
more complex program. Please find more information on MODBUS and
MODBUS definitions under: http://www.modbus.org/.
In this example, a remote Modbus master can establish only one Modbus
TCP connection. The user space server can only manage one connection at
the same time.
Function description
This example program allows to read the state of the input modules and to set
outputs via Ethernet. The data can be accessed byte by byte or bit by bit.
The following Modbus TCP function codes are available:
Function code
hex
Function name Function description
FC1: 0x01 Read Coils Reading one single bit
FC2: 0x02 Read Input Discrete reading of several input bits
FC3 0x03 Read Multiple Registers Reading several input registers
FC4: 0x04 Read InputRegisters Reading several input registers
FC5: 0x05 Write Coil Writing a single output bit
FC6: 0x06 Write SingleRegister Writing a single output register