modbus_tcp_client#
Overview#
This example demonstrates how to use Modbus TCP protocol to control board LED light.
FreeModbus supports bellow feature:
Read coil(0x01)
Read discrete inputs(0x02)
Read holding registers(0x03)
Read input registers(0x04)
Write single coil(0x05)
Write single holding register(0x06)
Write board LED status(0x0d)
Read board LED status(0x0e)
Write multiple coils(0x0f)
Write multiple holding registers(0x10)
Running the demo#
If the test passes, serial port output:
Please input Modbus Server ip address(for example 192.168.1.2):
Note: don't use backspace key or space key!
Modbus Server ip: 10.91.20.33
Initializing PHY...
[LINK STATE] netif=0, state=down
[LINK STATE] netif=0, state=up, speed=100M_full
************************************************
Modbus TCP example
************************************************
FOR TASK ETH Get IP address from DHCP...
IPv4 Address : 10.91.20.66
IPv4 Subnet mask : 255.255.255.0
IPv4 Gateway : 10.91.20.254
Enable LED1
0 1 0 0 0 6 1 13 0 0 0 1
Enable LED2
0 1 0 0 0 6 1 13 0 1 0 1
...
Use the MIMXRT1180-EVK board as modbus Server simulator, write board LED status(0x0d) to control LED light
Supported Boards#
MIMXRT1180-EVK
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
MIMXRT1180-EVK board
Personal Computer
Board settings
No special settings are required.
Prepare the Demo
Connect a USB cable between the host PC and the OpenSDA USB port on the target board.
Connect network to the target board(ENET4) via an Ethernet Cable.
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Write the program to the flash of the target board.
Press the reset button on your board to start the demo.
IMX943-EVK
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
IMX943-EVK board
Personal Computer
Board settings
No special settings are required.
Prepare the Demo
Connect a USB cable between the host PC and the OpenSDA USB port on the target board.
Connect network to the target board(J25) via an Ethernet Cable.
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target board.
Either re-power up your board or launch the debugger in your IDE to begin running the example.