1 Main functional requirements analysis and model building
For network direct connection, the hardware is shown in Figure 1. The PC is connected to the display with a network direct connection, and then manually set their IP addresses on the same network segment to communicate.
However, in this way, if the IP address of the display is not known in advance, communication will be difficult. In order to achieve the purpose of direct communication between the PC and the display without knowing the IP address of the display, it can be solved by the DHCP service principle: setting the LED display to a fixed IP address DHCP server, setting the PC network card to automatic The way to obtain an IP address is to automatically configure the IP address of the PC's network card through the DHCP service function, so that the network connection channel is established. Some developers use this method to achieve network direct connection, but this method has some problems: First, because UDP communication is not connected communication, its communication reliability is worse, it is easy to fail; second, only through The system that comes with the operating system is completed, without intervention, the user cannot set the timeout, sometimes the waiting time is too long, and the longest is 60 seconds. Third, DHCP is a fixed IP mode, which is obviously not very good in practical applications; In the system, the original NIC configuration information of the PC cannot be restored.
Based on this, after research, this paper proposes a new network direct connection method, which can realize the functions of direct network connection, automatic acquisition of IP address, and storage and recovery of PC network card configuration information, overcoming the shortcomings of current implementation methods and improving reliability. The stability, timeliness and other aspects of the performance of the system model is shown in Figure 2, the main functions and workflow are as follows:
(1) When starting the system, retrieve and access all the network cards of the PC, and save the configuration information of the network card for recovery when exiting the system; (2) start the network direct connection process; (3) broadcast the IP address request data packet; (4) ) return IP address data packet; (5) unpack, obtain the IP address of the PC and LED display, set the IP address of the PC; (6) return the IP address of the LED display, close the network direct connection, complete the communication channel (7) After establishing the communication channel between the PC and the LED display, the display can be read/written parameters, send programs, switch screens and other communication control operations; (8) when exiting the system, according to (1) The saved NIC configuration information restores the original state of the PC NIC.
In the above process, (2)~(6) is the core process. It simulates the DHCP service, realizes the PC broadcast request IP address, obtains the PC IP address and settings, uploads the LED display IP address, and completes the network direct connection channel. Establishing is a necessary step when performing network direct connection operation; (1) and (8) are operations for saving PC network card configuration information and restoring network card configuration information when starting and exiting the system; (7) completing the network The general operation of the display control after the direct connection of the channel. This article focuses on the first two.
2 Design and implementation of key functions
2.1 Saving PC NIC Configuration Information
The PC used to debug the display is generally multi-purpose. When debugging the display, it is also used for office and Internet access. The IP address of the network card may be fixed or automatically obtained. When doing network direct connection, it may change its IP address. In order not to affect the user's work, you need to automatically restore its IP address when you log out. To do this, when starting the LED control software, read the current network card configuration information, such as IP address, network card name, MAC address, network card type, whether it is an automatic configuration IP address, etc., put this information into a It is saved in the linked list, and an identifier is set at the same time to record whether the user has used the network direct connection operation during the debugging of the display screen, and is used when exiting the system.
In the Windows operating system, the IP Helper interface can be used to read the NIC information. It is a set of APIs for managing local network settings. The IP_ADAPTER_INFO structure can be used to easily extract the NIC configuration information and save it to the linked list.
2.2 Drawing on the principle of DHCP service, construct a network direct connection channel
To achieve direct network communication between the PC and the LED display, two key issues must be addressed: first, let the PC and the LED display be on the same network segment; second, know the IP address of the LED display.
In addition, it is also necessary to solve the interference of multiple network cards and wireless network cards on the direct connection of the network. Learning from the principle of DHCP, the main solutions are as follows:
(1) Design a network direct connection control process on the PC side; (2) Start the process when the network is directly connected, and determine the non-wireless network card connected to the LED display through the Windows related network API function and registry information. Put its MAC address into the UDP packet of the build request IP address, and then broadcast it, and start the internal UDP packet capture subprocess; (3) After the LED display receives the UDP packet requesting the IP address, according to its own IP address, Construct a PC's IP address and broadcast it. In order not to cause confusion, a pseudo DHCP packet is built here. When a normal Windows client receives the UDP packet, it does not automatically change its IP address. (4) The UDP packet capture process of the network direct connection control process receives the UDP packet of the assigned IP address, unpacks the IP address of the PC and the IP address of the LED display; (5) sets the IP address of the PC network card, uploads the LED The IP address of the display is given to the control software. After successful, the network direct connection control process is closed, and the establishment of the network direct connection channel is completed.
The process of direct connection to the network involves three systems: (1) the network direct connection control process, which constructs the UDP packet requesting the IP address and broadcasts it, monitors the 68 port of the target network card, captures the returned UDP packet, and parses out the PC. The IP address of the machine and the IP address of the LED display, then set the IP address of the PC, submit the IP address of the LED display to the main process, complete the task of direct network connection; (2) LED display DHCP service sub-process, It receives the IP address request of the PC, constructs and sets its own IP address, and returns the pseudo DHCP packet of the IP address of the PC; (3) LED control software, when the user selects the network direct connection mode, the network direct connection controller is started. The process implements the establishment of a direct channel of the network. After completion, the process is closed.
2.3 Restoring the Configuration Information of the PC NIC
When you log out of the system, judge whether you have used the network directly connected identifier. If you have not used the network direct connection mode, you do not need to perform the network IP recovery function; otherwise, the recovery function will be executed, and the 2.1 saved NIC configuration will be restored. The NIC IP address can be used with the netsh interface ip set command. At the same time, in order to speed up the processing and increase the success rate, you can follow the steps of disabling the network card, setting the network card IP address, and then enabling the network card:
(1) Use the SetupAPI related interface API function of Windows to disable the target NIC; (2) Restore the target NIC IP settings, using different commands according to the static IP address and dynamic IP address:
a. Restore the static IP address command.
Netsh interface ip set address name=“local connectionâ€
Source=STatic addr=192.168.1.19 mask=255.
255.255.0 gateway=none.
b. Restore the dynamic IP address command.
Netsh interface ip set address "local connection" dhcp
(3) Use the SetupAPI related interface API function to enable the target NIC, thus completing the recovery of the NIC configuration information.
3 Conclusion
In this paper, a direct network connection method is proposed for the direct connection of the LED display during the debugging process. The system automatically saves the network card configuration information when starting up, uses the network direct connection process to construct the network direct connection channel, and automatically recovers when exiting the system. The network card configuration information enables the user to communicate with the PC and the LED display without knowing the IP address of the LED display or modifying the IP address of the PC. This method is used in the LED Navigator software, and its reliability, stability and timeliness have been recognized by users and achieved good results. Practice has proved that this method can provide a solution for similar applications.
Fpc Connector,0.3Mm Fpc Connector,0.5Mm Fpc Connector,1.0Mm Fpc Connector
Dongguan City Yuanyue Electronics Co.Ltd , https://www.yyeconn.com