TCP CLENT of CH9121 Ethernet module and TCP server connection

Introduction to CH9121

CH9121 network module is a network module that realizes transparent transmission of TCP or UDP network data packets and serial port (TTL level) data packets. As a multifunctional embedded data conversion module, the module integrates hardware TCP/IP protocol stack and 10/100M Ethernet data link layer (MAC) and physical layer (PHY). The user can easily connect the terminal to the network through the serial port, which greatly reduces the development time and development cost. The module parameters can be modified in real time by sending instructions through the serial port or the network, and can also be inquired and set by the parameter setting software provided by Clayman Technology. The serial port baud rate supports 300~921600bps. There are four working modes of the module: TCP_Server, TCP_Client, UDP_Client, and UDP_Server (the TCP_Client client mode is tested here).
The module is a universal serial port to Ethernet transparent transmission device, which can be connected to 51, AVR, PIC, ARM and other MCUs or other serial port (TTL) devices.

wiring

Insert picture description here

USB-TTL module CH9121 network module
VCC 5V
GND GND
TX RX
RX TX

Computer IP address setting

When connecting the TCP_Client and the server, you need to pay attention to the settings of the IP address.
1. The module and the computer are directly connected with a network cable. You need to configure the computer IP address settings yourself, open the computer's network and Internet-change the adapter option-Ethernet-Properties-IPV4-Properties-use the following IP address. You can refer to the parameter configuration in the figure below.

Insert picture description here
2. Connect the router directly with the computer, and the module is also connected to the router. This kind of connection does not need to configure the computer IP address, and can directly read the actual IP address of the computer for use (the computer will not be disconnected).

Query IP address

After configuring the computer's IP address, we need to check to see if it is consistent with our configuration, use the Windows+R key to open the "Run" window, then enter CMD to enter the command prompt window, enter: ipconfig and press Enter to see To the IP configuration information.

Insert picture description here
Entering ipconfig finds that it is not an executable file. This is because there is no default path for ipconfig to run this variable in the computer, and it needs to be set. Click the "Environment Variables" of the "My Computer→Properties→Advanced" tab in turn, and double-click the Path parameter in the "System Variables" to set the variable value "c:\windows\system32" for it, and be careful not to add a semicolon when creating a new one. The
Insert picture description here
Path parameter is set. After confirming that entering "ipconfig" in the command line mode, the correct information will be displayed.
Insert picture description here

Parameter configuration

Open the "Parameter Configuration Software.exe" software; click "Search Device", the device list will display all online modules; double-click the module to modify the parameters in the device list, and modify the module parameters according to your needs. After the modification is successful, the module is reset, and the module parameters are saved after power-off.Insert picture description here
Insert picture description here

function test

The function test takes the "TCP-To-232 V1.11" software provided by Clayman Technology as an example. This software has integrated serial port (software left) and network communication functions (software right).
Insert picture description here
Set the serial port parameters in the "TCP-232 V1.11" software to be consistent with the module serial port parameters, and open the serial port; (factory default: baud rate 9600, data bit 8, stop bit 1, no parity)! Click to create , The destination IP on the right side of the software will show the device IP we set, and a destination port will be randomly created.
Insert picture description here
Click Create, the device IP will appear in the destination IP on the right side of the software, and a destination port will be randomly created. Then you can communicate with each other. (If the second software cannot be connected, please restore the factory settings under the first software and reset it again). The configuration must be a client and a server.

to sum up

In TCP_Client mode, after the module is powered on, it will actively connect to the designated port of the remote TCP_Server server according to the network parameters that have been set, and establish a long connection to perform transparent data transmission. In this mode, the server IP can be the fixed IP of the Internet or the intranet IP in the local area network. The remote server IP is visible to the module, that is, the IP where the module is located can be pinged to the remote server IP. Long-term release of similar articles, welcome to pay attention, please feel free to leave a message, you can also leave a message below if you need information!

Guess you like

Origin blog.csdn.net/qq_42250136/article/details/108740329