The company's serial port to TCP / IP and serial to WIFI how to use a variety of TCP mode of operation, according to different applications how to choose a flexible TCP client, TCP server, UDP, UDP multicast, link router, external network, switch And then describes how to configure the serial port to TCP / IP and communication with the SocketDlgTest program.
1.TCP & UDP working mode:
TCP / IP is the basic protocol of Internet interconnection. TCP / IP actually involves two layers of network protocol: network layer and transport layer. IP belongs to the network layer, and TCP belongs to the transport layer, in fact TCP / IP protocol and some other agreement that UDP protocol, UDP protocol and TCP protocol together constitute the TCP / IP protocol transport layer. The TCP protocol has two client and server work mode. In the RS232 / RS485 networking module applications, mainly in the UDP, TCP client, TCP server between the three modes to choose. As shown in Figure 1.
Description: The client is usually the originator of the request, send the request, accept the results of the server; the server is to accept the client request, in the data processing, to send the relevant data to the client; that white, who will set what function Take the initiative to send data that is the server side, the data issued by the client who is to receive! Master-slave relationship: the server sends information, the client receives the information;
TCP (Transmission Control Protocol) is a reliable connection protocol. We can use the phone to analog TCP protocol. Using the TCP protocol for data transfer, you first need to establish a connection; just as you need to dial the phone before you dial the phone. TCP is a reliable transmission, that is, you transfer the data is wrong or lost, it will automatically re-transmission to ensure that the data is correct; this is just when the phone, if the signal is not good, the recipient will say: " Again.
UDP (User Datagram Protocol) is the message transmission protocol. We can use SMS to analogize UDP protocol. Use the UDP protocol, you do not need to obtain the consent of the other party (no need to establish a connection), you can always send. But the UDP protocol is unreliable transmission, you send out the data can not be guaranteed to be correctly received by the other party;
The so-called "correct reception", which includes three aspects of the content: 1. Loss of the problem: the data can be lost after the loss. 2. Error code: Data content error can be detected and resent. 3. Order problem: UDP can not guarantee the order of the data, for example, when sending long text messages, it is possible that the second half of the content of the first message received, and then receive the first half of the message content. This gives the receiver a big confusion, TCP protocol does not have this problem.
UDP protocol also has its own advantages. 1. Simplicity, convenience, UDP protocol is very similar to serial communication, because the serial port to send data itself is based on non-connected (message). At this time in the serial port to the Ethernet, the use of UDP protocol in line with the original thinking. 2.UDP protocol with broadcast, multicast function, you can achieve one-to-many communication.
1.2 TCP client and TCP server differences
In the choice of TCP communication, the two sides of the communication, one must be TCP client (TCP Client), one for the TCP server (TCP Server). To call to analogy, call the person is the TCP client, then the phone side of the TCP server. The IP address in the TCP / IP protocol is similar to the telephone number, and the port number in TCP / IP is similar to the telephone extension. The client (dialer) first needs to know the IP address and port (telephone number and extension number) of the other party, first connect to the TCP server (the answering machine's telephone off-hook) to carry on the data transmission (call). And the general phone is different, where the TCP server can simultaneously access multiple TCP client, as there are multiple lines of the phone, not because the phone is connected in the access and can not access other phones.
In the RS232 transfer network of the ZP-8XXX series networking module, the TCP connection has a long connection and a short connection. TCP long connection is not connected after the establishment of the connection, until the power. TCP short connection refers to the need to establish a connection when the communication, immediately after the closure of the connection.
1.3 UDP broadcast
UDP One of the advantages of UDP over TCP is that one-to-many communication can be achieved. The following describes UDP broadcast and UDP multicast.
UDP broadcast: UDP broadcast packets are different from ordinary UDP packets, UDP broadcasts are as follows:
UDP broadcast packets generally only exist within the LAN, that is to say it is not able to achieve cross-routing communications.
All computers in the same LAN are able to receive broadcast packets. This increases the burden on the network, while the security will be reduced.
The ZP-8XXX Series ZP-8XXX Series Series modules support the sending and receiving of UDP broadcast packets. In addition SocketDlgTest also supports sending and receiving UDP broadcast packets, can be used for UDP broadcast debugging.
1.4 UDP multicast
UDP multicast: UDP unicast (ie, ordinary UDP communication) can achieve the communication between points and points. UDP broadcast can be achieved to send data to multipoint. But UDP broadcast there are the following shortcomings: not only need to receive data from the network module can receive data, any LAN computer can receive data, so the packet confidentiality is not strong, but also do not want to receive the data of the computer Increased the burden.
UDP multicast can solve the above problems, UDP multicast can be sent to the multi-point data, and only join a multicast group of network modules can receive data, not on the multicast group outside the module or computer to increase reception Burden, reduce the network load.
To determine whether you purchased the ZP-8XXX series of products to support UDP multicast, please open the program settings dialog box, click on "more advanced options", if the device supports advanced features "UDP multicast" is ticked Indicating that the device supports UDP multicast.
2. The choice of working mode
2.1 TCP and UDP selection
In TCP and UDP selection, TCP protocol has many advantages, here only when to use UDP protocol.
1. Save the host computer's line resources. In the ZP-8XXX series module serial to Ethernet applications, if you select the TCP protocol, and TCP client, then the TCP connection is in the module after the power to start the connection, are "long connection." This makes the TCP protocol has occupied a communication line (a socket interface), if the number of network modules (such as tens of thousands), then use the TCP protocol to take up more resources. UDP does not have this problem.
2. Simplify the complexity of PC programming. UDP-based socket programming is simpler than TCP.
3. Applications that require broadcast or multicast.
2.2 Client and server selection
1. A monitoring center or a number of monitoring centers.
A monitoring center: in a single monitoring center of the centralized monitoring system, scattered in the collection point of the ZP-8XXX series module will collect data sent to the central computer, this time the best use of ZP-8XXX series module for the TCP client way, because At this point as long as each module to set a destination IP (the central computer's IP address) can be. Of course, you can also use the center for the client, the module for the server side, but this time the center must remember the IP address of each module is not conducive to the system scalability and configuration flexibility.
Multiple monitoring centers: There are multiple central computers that need to monitor the networking module. Since the TCP client module can only connect to one center (one destination IP), multiple centers can not monitor a TCP client mode module (unless the " Type AT command "function, so that modules can be connected to different centers as needed). At this point should be used as a server for the server.
2. Which side knows the IP address of the other party. If there is a party (eg A) that does not know the IP address of the other party (eg B), then A must be the TCP server. This is because A does not know the IP address of B, nor can it connect. In the network of ZP-8XXX series networking module, the IP address of the ZP-8XXX series networking module is dynamically acquired. Therefore, the center does not know the IP address of all the modules. Therefore, the module should be used as the client.
3. Master-slave relationship. In the master-slave relationship of the communication mode, the host always send data, the slave gives the answer. In TCP short connection applications, the host should use the client. This is because the short connection using a data transmission when the establishment of TCP connection, only the host to know when to send the data when the need to establish a connection, so the host for the client.
2.3 TCP short connection and TCP long connection selection:
TCP short connection due to the occupation of TCP line resources, the general efficiency is better than long connections. But with long connections in the following cases: There is no master-slave relationship between the two parties. Any party has the possibility of first sending data, so keep the TCP connection all the time. Select the long connection when you need to pay attention to the establishment of the connection to the current, the middle of the cable is broken, you need to always check the availability of the connection, short connection without the problem, the use of more convenient.
3. Parameter configuration and network connection:
Here, how to use ZP-8XXX series configuration serial port TCP / IP and SocketDlgTest procedures and communication. Zhuo Lan serial TCP / IP to comply with the standard TCP / IP protocol, so any agreement to the network terminal and network products can communicate, Zhuo Lan Technology provides a network debugging tool (SocketDlgTest program, the user can start the menu / Program / ZP-8XXX series / debugging tool, find the software) to simulate the network terminal and serial port to TCP / IP product communication.
To have two network terminals (here are network debugging tools and serial to TCP / IP products) to communicate, the parameter configuration must be paired.
3.1 UDP mode
In UDP mode, the parameter configuration shown in Figure 2, the left side of the serial port TCP / IP product software configuration, the right side of the network debugging tool SocketDlgTest settings. First, both must be UDP mode of operation. Also indicated by a red arrow, the destination IP and destination ports of the network tool must point to the local IP and local ports of the networked product. In the case of a blue arrow, the destination IP of the networked product must be the IP address of the computer where the network tool is located, and the destination port of the networked product must be the local port of the network debugging tool. These network parameters can be configured to ensure two-way UDP data communication.
3.2 TCP client
In TCP mode, there are two TCP server and TCP client. Regardless of which mode is used, the client must be the client and the client can access the server, either client or service Side can not achieve communication.
When the serial port to TCP / IP as a client, there must be three correspondence, as shown in Figure 3. Serial port TCP / IP working mode for the client corresponding SocketDlgTest server mode, serial port TCP / IP destination IP must be SocketDlgTest where the computer's IP address, serial port TCP / IP product destination port must be SocketDlgTest local port. This set up after the serial port to TCP / IP can automatically connect to the network tool, the connection can be sent to send and receive data.
3.3 TCP server
When the serial port to TCP / IP products as a server, there are three corresponding relationship, as shown in Figure 3, here is not one explanation. This set up and then click the network tool to open the button and serial port TCP / IP products to establish a TCP connection, the connection can be sent to send and receive data.
4. Two devices are configured for couplets
If the host computer is not Socket program (SocketDlgTest) is not ZP-8XXX series of products, but two devices connected through the network port, the configuration method is similar. First of all, users need to connect two devices, computers connected to the same LAN. This computer is running module management software, the purpose of connecting the computer is only for the configuration, the configuration can be completed after the computer does not have to connect.
Click the module management software to configure the device. Device pairing can be divided into TCP couplets and UDP pairs. If the TCP connection mode, the parameters of the two devices shown in Figure 5. The parameters shown in the arrows must correspond to the same way as "3.2 TCP client" and "3.3 TCP server". After the TCP connection is successful, you can return to the Device Management dialog box to see the connection status, as shown in Figure 6, if the two devices are "connected" means that the two devices have been established TCP link.
If it is UDP way couplet, the configuration parameters shown in Figure 7, the arrow corresponding to the parameters must be one to one correspondence. UDP Pair As long as the parameters are configured correctly do not have to check the connection status, the sent data will be automatically sent to the specified device
Finally need to remind, if it is equipment couplet, in addition to the network port parameters in accordance with the above settings, but also must set the correct serial parameters. The baud rate of the networking product is mainly the same as the baud rate of the user's equipment. After this setting, the user device can send data to each other through the serial port of two networking products.