Virtual debugging communication method and device, equipment and storage medium
By verifying the client connection request and establishing independent threads and client instances in the virtual debugging system, using protocol converters and communication drivers for data conversion, the problems of high cost of virtual debugging communication methods and PLC incompatibility are solved, and efficient Communication mechanism and simplified debugging environment construction.
Patent Information
- Application Number
- CN202410606025.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-16
- Publication Date
- 2024-10-01
AI Technical Summary
Existing virtual debugging communication methods are costly and incompatible with PLC and simulation software, resulting in communication delays and low efficiency in scenarios with large signal volumes.
By verifying the client's connection request on the server side, establishing an independent thread and client instance, parsing the data interaction request, using the protocol converter and communication driver to convert the data format and type, an efficient communication mechanism is achieved, and a soft PLC is used to replace the hardware PLC. Perform debugging.
It reduces virtual debugging communication costs, improves PLC reuse rate and debugging efficiency, avoids communication delays, and simplifies the steps to build a debugging environment.
Smart Images

Figure CN118740899A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of virtual debugging, and in particular to a virtual debugging communication method, device, equipment and storage medium. Background Art
[0002] When communicating between simulation software and PLC (Programmable Logic Controller), the existing technology is forwarded through the OPC (OLE for Process Control) communication protocol, which will cause a large communication delay in scenarios with a large amount of signals. Taking KepServer, a more mature product on the market, as an example, the Kep Sever end obtains signals from the PLC end through a polling mechanism. When the signal volume is large, polling will consume a lot of computer computing resources and is inefficient. In addition, existing products on the market are all based on hard PLCs and have high costs. In the motion simulation application scenario, since many of the communication functions of the simulation software are only compatible with its own brand of PLC, incompatibility issues are prone to occur with other PLCs. Summary of the invention
[0003] The main purpose of the present invention is to solve the technical problems of high cost and incompatibility between simulation software and PLC in the existing virtual debugging communication mode.
[0004] A first aspect of the present invention provides a virtual debugging communication method, which is applied to a virtual debugging communication system. The virtual debugging communication system includes a client, a server and a device. The server is used to realize communication between the client and the device. The method includes: the server verifies based on a connection request sent by the client, and establishes a communication channel with the client after the verification is passed, and establishes an independent thread corresponding to the client based on the communication channel, wherein the independent thread is used to receive and process data interaction tasks sent by the corresponding client; the server establishes a client instance based on the client after the verification is passed, receives the data interaction request sent by the client, and parses the data interaction request through the client instance, determines the communication task of the client, and sends the communication task to the device.
[0005] Optionally, in a first implementation of the first aspect of the present invention, the device end is a PLC, and the client is at least one of a PLC, a host computer, simulation software, and a human-machine interface.
[0006] Optionally, in a second implementation method of the first aspect of the present invention, the server performs verification based on the connection request sent by the client, including: the server receives the connection request sent by the client, and performs a handshake verification with the client based on the connection request; after the handshake verification is passed, the server receives the verification data packet sent by the client, parses the verification data packet, and returns a feedback data packet to the client, confirming that the connection verification between the client and the server is passed.
[0007] Optionally, in a third implementation method of the first aspect of the present invention, when the client is a human-machine interface, the verification data packet sent by the receiving client is parsed, and a feedback data packet is returned to the client to confirm that the connection verification between the client and the server is successful, including: the server receives the function code sent by the human-machine interface, and generates a variable name with the same length as the variable name through an algorithm to register the variable name, and sends the registered variable name to the human-machine interface to confirm that the connection verification between the client and the server is successful, wherein the function code is an unencrypted session ID sent by the human-machine interface.
[0008] Optionally, in a fourth implementation method of the first aspect of the present invention, a communication channel with the client is established after the verification is passed, and an independent thread corresponding to the client is established based on the communication channel, including: the server obtains the client parameters of the client, and establishes a communication channel based on the communication protocol between the client and the server based on the client parameters, wherein the client parameters are used to uniquely identify the client, and the client parameters include the client ID and the client IP; the server creates an independent thread for the client that establishes the communication channel, and creates a thread pool to manage all independent threads.
[0009] Optionally, in a fifth implementation method of the first aspect of the present invention, the server establishes a client instance based on the client after verification, and receives a data interaction request sent by the client, including: the server obtains client parameters of the successfully connected client, creates a client instance based on the client parameters, and receives the data interaction request sent by the client based on the client instance, wherein the client instance corresponds one-to-one to the client.
[0010] Optionally, in a sixth implementation method of the first aspect of the present invention, the data interaction request is parsed by the client instance, the communication task of the client is determined, and the communication task is sent to the device end, including: parsing the data interaction request by the client instance, converting the format of the data interaction request by a protocol converter, and performing data type conversion on the format-converted data interaction request by a communication driver, to obtain the communication task of the client based on a preset format, and sending the communication task to the device end.
[0011] A second aspect of the present invention provides a virtual debugging communication device, which is applied to a virtual debugging communication system. The virtual debugging communication system includes a client, a server and a device. The server is used to implement communication between the client and the device. The device includes:
[0012] A verification module, used to verify based on the connection request sent by the client, and establish a communication channel with the client after the verification is passed, and establish an independent thread corresponding to the client based on the communication channel, wherein the independent thread is used to receive and process the data interaction task sent by the corresponding client;
[0013] The interaction module is used to establish a client instance based on the client after verification, receive the data interaction request sent by the client, and parse the data interaction request through the client instance, determine the communication task of the client, and send the communication task to the device end.
[0014] Optionally, in a first implementation of the second aspect of the present invention, the verification module includes:
[0015] The device end is a PLC, and the client end is at least one of a PLC, a host computer, simulation software, and a human-machine interface.
[0016] Optionally, in a second implementation of the second aspect of the present invention, the verification module further includes:
[0017] A connection unit is used for the server to receive a connection request sent by a client, and to perform a handshake verification with the client based on the connection request; after the handshake verification is passed, the server receives a verification data packet sent by the client, parses the verification data packet, and returns a feedback data packet to the client to confirm that the connection verification between the client and the server is passed.
[0018] Optionally, in a third implementation method of the second aspect of the present invention, the connection unit is specifically used for: when the client is a human-machine interface, the server receives a function code sent by the human-machine interface, and generates a variable name with the same length as the variable name through an algorithm to register the variable name, and sends the registered variable name to the human-machine interface to confirm that the connection verification between the client and the server is passed, wherein the function code is an unencrypted session ID sent by the human-machine interface.
[0019] Optionally, in a fourth implementation of the second aspect of the present invention, the verification module further includes:
[0020] A creation unit is used to obtain client parameters of the client, and establish a communication channel based on a communication protocol between the client and the server based on the client parameters, wherein the client parameters are used to uniquely identify the client, and the client parameters include a client ID and a client IP; the server creates an independent thread for the client that establishes the communication channel, and creates a thread pool to manage all independent threads.
[0021] Optionally, in a fifth implementation of the second aspect of the present invention, the interaction module includes:
[0022] The receiving unit is used to obtain the client parameters of the successfully connected client, create a client instance based on the client parameters, and receive a data interaction request sent by the client based on the client instance, wherein the client instance corresponds to the client one by one.
[0023] Optionally, in a sixth implementation of the second aspect of the present invention, the interaction module further includes:
[0024] A conversion unit is used to parse the data interaction request through the client instance, convert the format of the data interaction request using a protocol converter, and convert the data type of the data interaction request after the format conversion using a communication driver to obtain a communication task of the client based on a preset format, and send the communication task to the device end.
[0025] A third aspect of the present invention provides a virtual debugging communication device, which includes a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the virtual debugging communication device executes the virtual debugging communication method as described above.
[0026] A fourth aspect of the present invention provides a computer-readable storage medium, on which instructions are stored, and when the instructions are executed by a processor, the virtual debugging communication method as described above is implemented.
[0027] In the technical solution provided by the present invention, a communication channel with the client and an independent thread corresponding to the client are established after the connection request sent by the client is verified. The server establishes a client instance based on the client after verification, and determines the communication task after parsing the data interaction request sent by the client through the client instance, and sends the communication task to the device. This solution uses soft PLC to replace hardware PLC for debugging, improves the reuse rate of PLC, simplifies the steps of setting up the debugging environment, reduces the cost of hardware PLC, realizes an efficient communication mechanism, ensures that when debugging complex and large equipment, there will be no communication delay and affect the debugging results, reduces the communication cost of virtual debugging, and improves the efficiency and convenience of virtual debugging communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A schematic diagram of a first embodiment of a virtual debugging communication method provided by an embodiment of the present invention;
[0029] Figure 2 A schematic diagram of a communication mechanism of a virtual debugging communication system provided by an embodiment of the present invention;
[0030] Figure 3 A schematic diagram of a second embodiment of a virtual debugging communication method provided by an embodiment of the present invention;
[0031] Figure 4 A schematic diagram of a connection mechanism for multiple connection objects provided by an embodiment of the present invention;
[0032] Figure 5 A schematic diagram of the structure of a virtual debugging communication device provided by an embodiment of the present invention;
[0033] Figure 6 Another structural schematic diagram of a virtual debugging communication device provided by an embodiment of the present invention;
[0034] Figure 7 A schematic diagram of the structure of a virtual debugging communication device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0035] With respect to the existing virtual debugging communication method, this application establishes a communication channel with the client and an independent thread corresponding to the client after verifying the connection request sent by the client. The server establishes a client instance based on the verified client, and determines the communication task after parsing the data interaction request sent by the client through the client instance, and sends the communication task to the device. This solution uses soft PLC to replace hardware PLC for debugging, improves the reuse rate of PLC, simplifies the steps of setting up the debugging environment, reduces the cost of hardware PLC, realizes an efficient communication mechanism, ensures that there will be no communication delay when debugging complex and large equipment, and affects the debugging results, and improves the efficiency of virtual debugging communication.
[0036] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, device, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0037] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 A first embodiment schematic diagram of a virtual debugging communication method provided by an embodiment of the present invention, the method specifically comprises the following steps:
[0038] 101. The server performs verification based on the connection request sent by the client, establishes a communication channel with the client after the verification is passed, and establishes an independent thread corresponding to the client based on the communication channel.
[0039] Among them, the independent thread is used to receive and process the data interaction tasks sent by the corresponding client. First, determine the type of communication protocol between the server and the client. The server needs to create a socket and bind it to a specific IP address and port number, and then listen for connection requests from the client. The client also needs to create a socket and specify the IP address and port number of the server to be connected, and then initiate a connection request to the server. When the server receives the connection request from the client, if everything is normal (for example, there is no port conflict, the server is willing to accept the connection, etc.), it will receive the request and establish a network connection with the client. At this point, the client and the server can transmit and communicate data through the connection. After the connection is established, the client and the server can transmit data, including sending and receiving data packets, parsing data packets, processing data, etc. In virtual debugging, the data includes control instructions, status information, debugging data, etc.
[0040] In TCP (Transmission Control Protocol), thread establishment is usually implemented through thread libraries or thread classes in programming languages. Threads themselves do not retain resources, but apply to the process they are in when needed to meet the needs of operation, so that multiple threads can execute different tasks in parallel in the same process, and concurrent processing is achieved. Threads can access the memory space and resources of their process and share these resources with other threads in the same process. Each thread has an independent execution path and can execute code in its own logical order. In this solution, threads are used to implement concurrent access of multiple clients. When multiple clients simultaneously initiate connection requests to the server, the server can create a new thread for each client to process the client's request. In this way, the server can process multiple client requests at the same time, improving the server's concurrent processing capabilities and response speed. In another achievable way, a thread pool is used instead of creating a new thread for each client connection. The thread pool can limit the number of threads that are active at the same time, thereby saving system resources. When a client connection request arrives, an idle thread can be obtained from the thread pool to process the request. If there is no idle thread, the request can be put into a queue and wait.
[0041] 102. The server establishes a client instance based on the verified client, receives a data interaction request sent by the client, parses the data interaction request through the client instance, determines the communication task of the client, and sends the communication task to the device.
[0042] The server first listens to a specific port and waits for the client's connection request. When the client connects, the server performs identity authentication, such as checking the username, password or token. If the authentication is successful, the server creates an instance associated with the client. The instance is used to store the client's status information and connection details, and receive and process the communication request sent by the client. When the client sends a data interaction request, the server receives these requests through the client instance, parses the received data according to a pre-defined protocol (such as JSON, XML, etc.), and extracts key information from the parsed data, such as the target device, data type, data content, etc. of the communication task. Based on the extracted information, the server determines the client's communication task. Depending on the nature of the task, the server may need to perform some pre-processing or post-processing operations, such as data conversion, format adjustment, etc. Based on the target device information in the communication task, the server selects the device end to establish a connection with it, and sends the processed data or communication task to the target device end. If an error occurs during the sending process, the server records the error and sends an error notification to the client.
[0043] In this embodiment, a connection is established between the client and the device through the server. Specifically, a data transmission channel is first established between the server and the device through a transmission protocol, and the established transmission channel is verified. After the verification is passed, an independent thread and a client instance are established to process the transmission task of the client, so that any data transmitted by any client can be transmitted to the corresponding device through the server. Specifically, the server first needs to establish a connection with the device through a transmission protocol (such as TCP, UDP, WebSocket, etc.), that is, the server listens to a specific port and waits for a connection request from the device. When the device sends a connection request, the server accepts the request and creates a new connection or session. The established connection is verified, which may include identity authentication, permission check and other steps to ensure the legitimacy of the device. Similarly, the server also needs to establish a connection with the client. After the connection is established, the server verifies and authorizes the client, including checking whether the connection is stable, whether the bandwidth is sufficient, and whether the delay is acceptable. In order to avoid blocking and improve the response speed, the server should create an independent thread for each connected client. The thread is responsible for listening to the client's transmission request and processing these requests. When the client sends data, the server thread should receive the data and forward the data to the corresponding device according to the information of the device. When the server receives the transmission request from the client, it parses the information in the transmission request, including the data to be transmitted, the target device ID, etc. According to the information, the server thread establishes a connection with the target device and sends the data. Further, the server performs format conversion or encoding and decoding on the sent data to ensure that the device can parse it correctly. Throughout the process, the server should be able to handle possible errors and abnormal situations, such as disconnection, data transmission failure, etc. For each error and exception, the server should record detailed logs for subsequent analysis and troubleshooting. In another achievable way, for the communication delay problem in the virtual machine, the delay can be reduced by adjusting the VMware settings, for example, modifying the way the virtual machine memory is used to ensure that the virtual machine only uses physical memory and does not read the hard disk, thereby improving communication efficiency.
[0044] See also Figure 2, a schematic diagram of the communication mechanism of the virtual debugging communication system provided by an embodiment of the present invention, considering that the server is an instance management tool, therefore, for the client, this solution does not limit the number of connected clients, and only needs to create a corresponding number of threads on the server to realize the communication between each client and the soft and hard PLC. The server creates a listening socket and binds it to a specific IP address and port. The listening socket is used to listen to the connection request from the client. When a client initiates a connection request, the listening socket will accept the request and return a connected socket instance. The connected socket instance establishes a two-way communication channel with the client socket. For each connected socket, the server will create a new socket instance (or thread, process, etc.) to handle the communication with the client. The socket instance will be responsible for reading the data sent by the client, processing the data, sending responses, and other tasks. The server simultaneously handles the connection requests and communication tasks of multiple clients by using multi-threading, multi-process, asynchronous I / O, etc. The server needs to manage the life cycle of these socket instances, including creation, use, and destruction. When a client disconnects, the server needs to close the corresponding socket instance and release related resources. After accepting the client connection, the server can perform additional connection verification steps, including checking the client's authentication information, verifying the data packet, etc. The server and the client need to follow a communication protocol to exchange data. This protocol can be custom or an existing standard protocol.
[0045] This solution uses soft PLC instead of hardware PLC for debugging, improves the reuse rate of PLC, simplifies the steps of setting up the debugging environment, reduces the cost of hardware PLC, realizes an efficient communication mechanism, and ensures that there will be no communication delay when debugging complex and large equipment, which will affect the debugging results.
[0046] See also Figure 3 A second embodiment schematic diagram of a virtual debugging communication method provided by an embodiment of the present invention, the method specifically comprises the following steps:
[0047] 201. The server performs handshake verification with the client, and after the handshake verification is passed, performs connection verification based on the verification data packet, and after the connection verification, confirms that the connection verification between the client and the server is passed.
[0048] The communication between the client and the server is based on the TCP protocol. Since the remote connection will be connected to a pseudo server, it is difficult to ensure reliability if only the TCP connection mechanism is relied upon during the connection. Therefore, this solution adds a connection verification mechanism. After the TCP three-way handshake is completed, the client will once again send a data packet to the server, and the server will return a pre-agreed data packet to the client, and then normal communication will be carried out, that is, the registration session will be realized. Specifically, regarding the TCP three-way handshake, the client initiates a connection request (SYN) to the server, and after the server receives the request, it sends a response (SYN-ACK) to the client. After the client receives the response from the server, it sends a confirmation (ACK) to the server to complete the TCP three-way handshake. After the TCP three-way handshake is completed, the client will send an additional connection verification data packet to the server, and the verification data includes the client's identifier, timestamp, random number, encryption algorithm, etc. After the server receives the client's connection verification data packet, it will perform a verification operation, including checking whether the identifier in the data packet is legal, whether the timestamp is within a reasonable range, and whether the random number meets the requirements. If the verification is successful, the server will generate a pre-agreed response data packet and send it to the client. The response data packet includes the session ID, encryption key, etc. After receiving the response data packet from the server, the client will verify it. If the verification is successful, it confirms that the connection with the server has been established and normal communication can be carried out. Furthermore, after the connection verification is successful, the server and the client will register a session and use this session for subsequent communication.
[0049] When the client is a human-machine interface, the server receives the function code sent by the human-machine interface, and generates a variable name with the same length from the variable name through an algorithm to register the variable name, and sends the registered variable name to the human-machine interface to confirm that the connection verification between the client and the server is passed, wherein the function code is an unencrypted session ID sent by the human-machine interface. Specifically, the human-machine interface attempts to establish a connection with the server. As part of the connection request, the human-machine interface sends a function code (as an unencrypted session ID). The server receives the function code sent by the HMI for verification to ensure that the session ID is valid. After the session ID verification is passed, the server will process the variable name registration related to the human-machine interface, that is, the server uses an algorithm to convert the original variable name into a new variable name with the same length, and then the converted variable name is registered on the server. The server sends the registered variable name back to the human-machine interface, and the human-machine interface receives and confirms these variable names. When the human-machine interface successfully confirms the variable name, the connection verification between the client and the server is considered to be passed. Once the connection is verified, the HMI and server can begin normal communication, including the HMI sending read or write requests to the server, the server forwarding these requests to the PLC or other device, and returning the response to the HMI.
[0050] 202. The server establishes a communication channel based on a communication protocol between the client and the server based on the client parameters of the client.
[0051] Among them, the client parameters are used to uniquely identify the client, and the client parameters include the client ID and the client IP. The client initiates a connection request with the server by providing necessary parameters (such as the server IP address, port number, authentication information, etc.). The server listens for connection requests from the client on the specified IP address and port. When receiving the client's connection request, the server will verify the parameters provided by the client (such as whether the IP address and port number are in the whitelist, whether the authentication information is correct, etc.). If the verification is successful, the server will accept the connection request and establish a communication channel with the client. When establishing the communication channel, the server and the client need to determine the communication protocol to be used. The communication protocol can be a transport layer protocol or an application layer protocol. Depending on the protocol, the server and the client need to send and receive data in the format specified by the protocol.
[0052] 203. The server creates an independent thread for the client that establishes the communication channel, and creates a thread pool to manage all independent threads.
[0053] When the client needs data, it initiates a request. After receiving the request, the server will automatically generate a request event and be triggered. When there are multiple requests, multiple events will be generated and triggered at the same time. Each event is triggered by an independent thread. After a request is completed, the current thread will be released immediately. This will greatly improve the utilization efficiency of computer computing resources. This mechanism is also called event-driven mechanism in this solution. In addition, the server also has the function of load balancing (horizontal expansion). When the number of client requests reaches a certain limit, the load balancing can be turned on. By combining the event-driven mechanism with the load balancing mechanism, this solution can efficiently process a large number of client requests and ensure the stability and scalability of the system. In actual applications, when the client needs data, it initiates a request to the server. After receiving the request, the server will automatically generate an event related to the request. The event is encapsulated into a task and waits to be processed. All generated events are placed in one or more event queues. The event queue follows the first-in-first-out (FIFO) principle and can also be sorted according to priority. The server has multiple event handlers, which are specifically responsible for taking events out of the event queue and processing them. Each event is processed by an independent thread. When the event handler completes processing the request, it generates a response and sends it back to the client through the network. The server manages the life cycle of these threads. When a thread completes processing a request, it is released back to the thread pool to wait for the next event. Furthermore, the server monitors the current system load, including CPU usage, memory usage, request queue length, etc. When the load reaches a preset threshold, the server starts the load balancing mechanism. The load balancing strategy can be configured according to the actual situation, such as polling, random, minimum number of connections, weight, etc.
[0054] 204. The server creates a client instance based on the parameters of the successfully connected client, and receives a data interaction request sent by the client based on the client instance.
[0055] The client instances correspond to the clients one by one.
[0056] The server also includes a basic manager based on the transmission protocol. The basic manager does not participate in the actual communication data interaction. Its main function is to create, configure, and destroy socket instances. When a client connects to the server, the basic manager will create a socket instance. The client corresponds to the socket instance one by one, and the socket instance will handle all communication tasks with the client. This mechanism is implemented based on the IOCP model, which means that a thread can monitor the sending and receiving tasks of multiple clients at the same time. Among them, the basic manager is responsible for the creation, configuration, and destruction of the socket instance. When a client connects to the server, the basic manager will create a socket instance for it to ensure that each client corresponds to a specific socket instance; the socket instance is responsible for handling all communication tasks of the client corresponding to it, including receiving data from the client, sending data to the client, managing the connection status, etc.
[0057] 205. Parse the data interaction request through the client instance.
[0058] The client instance listens to the preset port or channel, waiting to receive data interaction requests from the client. The client instance first verifies whether the received request conforms to the expected format. If the request format is incorrect or invalid, the client instance may reject the request and return an error message. If the request format is valid, the client instance will start parsing the content of the request, which includes converting the request data from binary format to readable text format. The client instance encapsulates the processing results into an appropriate response format, including converting the data into a structured data format such as binary format, and the client instance sends the prepared response data back to the requesting client.
[0059] 206. Convert the format of the data interaction request using a protocol converter, and convert the data type of the format-converted data interaction request using a communication driver to obtain a communication task of the client based on a preset format.
[0060] The protocol converter first identifies the data interaction request from the client and parses the original protocol format followed by the request. According to the protocol supported by the target system or device, the protocol converter converts the original format of the data interaction request into a new protocol format and encapsulates the converted data interaction request into a new protocol data packet. The communication driver receives the data interaction request in the converted format from the protocol converter, analyzes the data in the data packet, determines the field or data segment that needs to be converted into a data type, and according to the preset data type conversion rules or mapping table, the communication driver converts the original data type into the target data type, including the conversion of data size, sign bit, precision, range, etc. After the format conversion and data type conversion of the data interaction request are completed by the protocol converter and the communication driver, the communication task of the client is generated according to the preset format. The communication task includes information such as the target address, port number, communication protocol, data content, etc. The client performs the communication operation according to the generated communication task, sends the data to the target system or device, and receives the response data from the target system or device. After the response data received by the client is parsed and processed, it can be further operated.
[0061] In one achievable manner, the server includes a protocol converter and a communication driver, and the protocol converter is connected to the client through a communication protocol. For example, the virtual PLC transmits data with the protocol converter through the TCP protocol, the human-machine interface transmits data with the protocol converter through the EIP protocol, and the host computer transmits data with the protocol converter through the CIP protocol. The protocol converter converts the format of data transmitted based on various protocols, and then transmits the format-converted data to the communication driver for data type conversion, and sends the data converted into the target data type to the corresponding PLC through the interface, wherein the data type conversion refers to converting data of any data format into data in a data format acceptable to the target PLC, for example, transmitting the converted data to the Omron soft PLC through API1, and transmitting the converted data to the Inovance hard PLC through API2.
[0062] In actual applications, for the communication between the virtual PLC and the protocol converter, the virtual PLC first initializes the network connection with the protocol converter, including configuring network parameters and creating and binding sockets. The virtual PLC uses the TCP protocol to encapsulate the data into a TCP data packet, which contains the instructions, data or other information to be transmitted. The encapsulated TCP data packet is sent to the protocol converter through the network. The functions of the protocol converter mainly include data reception, data analysis and conversion, and data forwarding, that is, the protocol converter receives the TCP data packet from the virtual PLC, analyzes the TCP data packet, and converts the data format according to the requirements of the target device and protocol, and forwards the converted data to the target device through the protocol converter. Regarding the communication between the human-machine interface and the protocol converter, the human-machine interface initializes the network connection with the protocol converter and configures the corresponding EIP parameters. The human-machine interface receives the EIP data packet from the protocol converter and analyzes the data therein. The human-machine interface performs corresponding processing based on the analyzed data and displays relevant information on the interface. Regarding the communication between the host computer and the protocol converter, the host computer initializes the network connection with the protocol converter and configures the corresponding CIP parameters. The host computer receives the CIP data packet from the protocol converter and parses the data therein. The host computer performs further processing or application based on the parsed data, such as data storage, analysis, and control command issuance.
[0063] 207. Send the communication task to the device end.
[0064] Regarding the communication between the server and the device, first determine the communication protocol supported by the device, set the specific port, IP address or other connection parameters according to the requirements of the protocol, and construct a message containing the required information, including commands, parameters, data or other metadata, in the form of text or binary, and establish a connection between the server and the device, and send the message to the device. Figure 4 , a schematic diagram of the connection mechanism of multiple connection objects provided by an embodiment of the present invention, there are multiple socket instances in the server, each socket instance is used to handle the communication task of a corresponding client, and the server is actually a tool for managing instances and does not have an actual communication function. For the management of socket instances, a new thread can be created for each connected client, and the thread is used to handle the communication with the client, including receiving and sending data. The threads are executed concurrently, so the server can handle multiple clients at the same time; or, each client connection is handled by an independent process; or, the server uses an event loop to listen to events on multiple sockets; or, the server sets the socket to non-blocking mode and uses a polling mechanism to check which sockets are readable or writable.
[0065] On the software configuration page of the server, configure the connections of the client, PLC simulator, human-machine interface, and signal coupler. Specifically, the client configuration includes the client ID, client IP, and service type; the PLC simulator configuration includes the PLC address and PLC port; the human-machine interface configuration includes the IP address and service port; the signal coupler configuration includes the IP address and service port. Furthermore, other parameters can be set, including the PLC type and simulator communication delay light, and label information, recipes, and recipes can be imported and exported, and the service status of the server can be displayed.
[0066] This solution realizes debugging by replacing hardware PLC with soft PLC, improving the reuse rate of PLC, simplifying the steps of setting up the debugging environment, reducing the cost of hardware PLC, realizing an efficient communication mechanism, and ensuring that there will be no communication delays and affecting the debugging results when debugging complex and large equipment.
[0067] The above describes the virtual debugging communication method in the embodiment of the present invention. The following describes the virtual debugging communication device in the embodiment of the present invention in detail from the perspective of modular functional entities. Figure 5 , a structural diagram of a virtual debugging communication device provided by an embodiment of the present invention, the virtual debugging communication device is applied to a virtual debugging communication system, the virtual debugging communication system includes a client, a server and a device, the server is used to realize communication between the client and the device, and the device includes:
[0068] Verification module 510, used to perform verification based on the connection request sent by the client, and establish a communication channel with the client after the verification is passed, and establish an independent thread corresponding to the client based on the communication channel, wherein the independent thread is used to receive and process the data interaction task sent by the corresponding client;
[0069] The interaction module 520 is used to establish a client instance based on the client after verification, receive a data interaction request sent by the client, parse the data interaction request through the client instance, determine the communication task of the client, and send the communication task to the device end.
[0070] This solution uses soft PLC instead of hardware PLC for debugging, improves the reuse rate of PLC, simplifies the steps of setting up the debugging environment, reduces the cost of hardware PLC, realizes an efficient communication mechanism, and ensures that there will be no communication delay when debugging complex and large equipment, which will affect the debugging results.
[0071] See also Figure 6 , another structural diagram of a virtual debugging communication device provided by an embodiment of the present invention, the virtual debugging communication device is applied to a virtual debugging communication system, the virtual debugging communication system includes a client, a server and a device, the server is used to realize communication between the client and the device, the device includes:
[0072] Verification module 610, used to perform verification based on the connection request sent by the client, and establish a communication channel with the client after the verification is passed, and establish an independent thread corresponding to the client based on the communication channel, wherein the independent thread is used to receive and process the data interaction task sent by the corresponding client;
[0073] The interaction module 620 is used to establish a client instance based on the client after verification, receive a data interaction request sent by the client, parse the data interaction request through the client instance, determine the communication task of the client, and send the communication task to the device end.
[0074] In this embodiment, the verification module 610 includes:
[0075] The device end is a PLC, and the client end is at least one of a PLC, a host computer, simulation software, and a human-machine interface.
[0076] In this embodiment, the verification module 610 further includes:
[0077] The connection unit 611 is used for the server to receive the connection request sent by the client, and to perform handshake verification with the client based on the connection request; after the handshake verification is passed, the server receives the verification data packet sent by the client, parses the verification data packet, and returns the feedback data packet to the client to confirm that the connection verification between the client and the server is passed.
[0078] In this embodiment, the connection unit 611 is specifically used for: when the client is a human-machine interface, the server receives the function code sent by the human-machine interface, and generates a variable name with the same length as the variable name through an algorithm to register the variable name, and sends the registered variable name to the human-machine interface to confirm that the connection verification between the client and the server is passed, wherein the function code is an unencrypted session ID sent by the human-machine interface.
[0079] In this embodiment, the verification module 610 further includes:
[0080] The creation unit 612 is used to obtain the client parameters of the client, and establish a communication channel based on the communication protocol between the client and the server based on the client parameters, wherein the client parameters are used to uniquely identify the client, and the client parameters include the client ID and the client IP; the server creates an independent thread for the client that establishes the communication channel, and creates a thread pool to manage all independent threads.
[0081] In this embodiment, the interaction module 620 includes:
[0082] The receiving unit 621 is used to obtain client parameters of the successfully connected client, create a client instance based on the client parameters, and receive a data interaction request sent by the client based on the client instance, wherein the client instance corresponds to the client one by one.
[0083] In this embodiment, the interaction module 620 further includes:
[0084] The conversion unit 622 is used to parse the data interaction request through the client instance, convert the format of the data interaction request using a protocol converter, and convert the data type of the data interaction request after the format conversion using a communication driver, so as to obtain the communication task of the client based on a preset format, and send the communication task to the device end.
[0085] This solution uses soft PLC instead of hardware PLC for debugging, improves the reuse rate of PLC, simplifies the steps of setting up the debugging environment, reduces the cost of hardware PLC, realizes an efficient communication mechanism, and ensures that there will be no communication delay when debugging complex and large equipment, which will affect the debugging results.
[0086] above Figure 5-6 The virtual debugging communication device in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The virtual debugging communication device in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0087] See also Figure 7 As shown, the virtual debugging communication device includes a processor 700 and a memory 701 . The memory 701 stores machine executable instructions that can be executed by the processor 700 . The processor 700 executes the machine executable instructions to implement the above-mentioned virtual debugging communication method.
[0088] Further, Figure 7 The virtual debugging communication device shown further includes a bus 702 and a communication interface 703 , and the processor 700 , the communication interface 703 and the memory 701 are connected via the bus 702 .
[0089] The memory 701 may include a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), for example, at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 703 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 702 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0090] The processor 700 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 700. The above processor 700 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 701 , and the processor 700 reads the information in the memory 701 and completes the method steps of the above-mentioned embodiment in combination with its hardware.
[0091] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the various steps of the virtual debugging communication method provided in the above embodiments.
[0092] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described equipment, devices, and units can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.
[0093] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0094] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A virtual debugging communication method, applied to a virtual debugging communication system, characterized in that: The virtual debugging communication system includes a client, a server and a device. The server is used to realize communication between the client and the device. The virtual debugging communication method includes: The server performs verification based on the connection request sent by the client, and establishes a communication channel with the client after the verification is passed, and establishes an independent thread corresponding to the client based on the communication channel, wherein the independent thread is used to receive and process the data interaction task sent by the corresponding client; The server establishes a client instance based on the verified client, receives a data interaction request sent by the client, parses the data interaction request through the client instance, determines the communication task of the client, and sends the communication task to the device.
2. The virtual debugging communication method according to claim 1, characterized in that: The device end is a PLC, and the client end is at least one of a PLC, a host computer, simulation software, and a human-machine interface.
3. The virtual debugging communication method according to claim 1, characterized in that: The server performs verification based on the connection request sent by the client, including: The server receives the connection request sent by the client, and performs handshake verification with the client based on the connection request; After the handshake verification is passed, the server receives the verification data packet sent by the client, parses the verification data packet, and returns a feedback data packet to the client to confirm that the connection verification between the client and the server is passed.
4. The virtual debugging communication method according to claim 3, characterized in that: When the client is a human-machine interface, the receiving of a verification data packet sent by the client, parsing the verification data packet, and returning a feedback data packet to the client to confirm that the connection verification between the client and the server is passed includes: The server receives the function code sent by the human-machine interface, and registers the variable name by generating a variable name with the same length through an algorithm, and sends the registered variable name to the human-machine interface to confirm that the connection verification between the client and the server is passed, wherein the function code is an unencrypted session ID sent by the human-machine interface.
5. The virtual debugging communication method according to claim 1, characterized in that: The step of establishing a communication channel with the client after the verification is passed, and establishing an independent thread corresponding to the client based on the communication channel, includes: The server obtains the client parameters of the client, and establishes a communication channel based on the communication protocol between the client and the server based on the client parameters, wherein the client parameters are used to uniquely identify the client, and the client parameters include the client ID and the client IP; The server creates an independent thread for the client that establishes the communication channel, and creates a thread pool to manage all independent threads.
6. The virtual debugging communication method according to claim 1, characterized in that: The server establishes a client instance based on the client after verification, and receives a data interaction request sent by the client, including: The server obtains the client parameters of the successfully connected client, creates a client instance based on the client parameters, and receives a data interaction request sent by the client based on the client instance, wherein the client instance corresponds to the client one by one.
7. The virtual debugging communication method according to claim 1, characterized in that: The step of parsing the data interaction request through the client instance, determining the communication task of the client, and sending the communication task to the device end includes: The data interaction request is parsed through the client instance, the format of the data interaction request is converted using a protocol converter, and the data type of the data interaction request after the format conversion is converted using a communication driver to obtain a communication task of the client based on a preset format, and the communication task is sent to the device end.
8. A virtual debugging communication device, applied to a virtual debugging communication system, characterized in that: The virtual debugging communication system includes a client, a server and a device. The server is used to realize communication between the client and the device. The virtual debugging communication device includes: A verification module, used to verify based on the connection request sent by the client, and establish a communication channel with the client after the verification is passed, and establish an independent thread corresponding to the client based on the communication channel, wherein the independent thread is used to receive and process the data interaction task sent by the corresponding client; The interaction module is used to establish a client instance based on the client after verification, receive the data interaction request sent by the client, and parse the data interaction request through the client instance, determine the communication task of the client, and send the communication task to the device end.
9. A virtual debugging communication device, characterized in that: The virtual debugging communication device includes a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the virtual debugging communication device executes the virtual debugging communication method according to any one of claims 1 to 7.
10. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by the processor, the virtual debugging communication method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Remote safety debugging method and system for IPTV equipment and IPTV equipment
CN119299750A
IPTV device remote security debugging method, system and IPTV device
CN119299750B
Wireless data transmission method, programmable wireless transmission device and storage medium
CN120499649A
Method, device and system for transmitting multi-modal data
CN120812125A
Method, apparatus and system for transmitting multi-modal data
CN120812125B
