Industrial Ethernet message transmission optimization method, device, equipment and medium
By creating and binding socket resources in Industrial Ethernet, the packets are processed directly from the application layer to the ring cache area, the delay problem caused by interrupt processing is solved, efficient and synchronous message reception is achieved, and the software is solved Receive delay problems caused by low interrupt priority.
Patent Information
- Application Number
- CN202410940335.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2044-07-15
AI Technical Summary
In industrial Ethernet, the interrupt processing of network messages leads to large delays, low priority of soft interrupts leads to severe jitter in message reception, which cannot be processed in time, affecting system performance.
By creating and binding socket resources, it is directly transferred from the application layer to the ring cache area of the link layer, using socket resources to process packet transmission, cancel the interrupt processing method, and use synchronous processing method to read the newspaper from the ring cache area To avoid reception delay caused by low soft interrupt priority.
Improve message transmission efficiency, simplify the reception process, avoid message reception jitter caused by low soft interrupt priority, greatly reduce delay, and ensure that messages are processed in time before the expiration time.
Smart Images

Figure CN118488021B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to an industrial Ethernet message transmission optimization method, device, equipment and medium. Background Art
[0002] In industrial Ethernet, industrial Ethernet messages are transmitted in the form of original data packets. Original data packets mean that data packets bypass the intermediate transport layer and network layer and are directly transmitted between the application layer and the link layer. Sending is: the application layer data is passed to the link layer through the network socket, and the link layer adds a check value and then directly passes it to the physical layer. Receiving is: after the physical layer data is passed to the link layer, the check value is removed and passed from the link layer to the application layer. When the network message in Ethernet reaches the network card, the message will be cached in the pre-applied ring buffer area, and then it has the function of notifying the processor that the message has arrived and requesting processing. After receiving the request, the processor can suspend the current task and give priority to the request. This process is interrupt processing. The network message data volume is relatively large and the process is complicated. If it takes a long time to process the network message during interrupt processing. Interrupt processing will take precedence over other tasks, and the processing time is too long, which will delay other tasks. Therefore, the network uses hard interrupts and soft interrupts. Hard interrupts process fast tasks such as network card status and trigger soft interrupts. Then resume the interrupted task. Soft interrupts process non-urgent tasks. Network message processing is placed in soft interrupt processing.
[0003] In the Linux operating system, each task has an associated priority that determines the order in which it is executed on the CPU. A high-priority task can be executed before a low-priority task. There may even be a preemption, that is, a high-priority task interrupts the execution of a low-priority task and runs first. An interrupt request is a preemption behavior. Since a soft interrupt is a low-priority task, when the CPU system is busy, the soft interrupt may not be responded to for a long time, and network messages may not be processed in time. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide an industrial Ethernet message transmission optimization method, device, equipment and medium, which can solve the problem of large delay in the transmission of industrial Ethernet messages by network sockets and realize direct reading of industrial Ethernet message information from the ring buffer area. The specific scheme is as follows:
[0005] In a first aspect, the present application discloses an industrial Ethernet message transmission optimization method, which is applied to an industrial automation system, comprising:
[0006] Create and bind a corresponding socket resource, so as to directly transfer the to-be-sent industrial Ethernet message from the application layer to the ring buffer of the link layer by using the socket resource through the application program, so as to transmit the ring buffer data to the network card through the bound first network port, so as to send the corresponding industrial Ethernet message;
[0007] When there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the circular buffer area, and then the application reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and using the corresponding socket resources to realize the reception of the industrial Ethernet message.
[0008] Optionally, the industrial automation system includes: a master station device and a slave station device, wherein the master station device is a terminal device for actively sending or receiving industrial Ethernet messages, and the slave station device is a network device located in the Ethernet and used to transmit the industrial Ethernet messages, and one network interface of the master station device is set as a first network port, and two or more network interfaces of each of the slave station devices are set as second network ports, so that the master station device is connected to the slave station device through the first network port, and the slave station devices are connected to each other through the second network port.
[0009] Optionally, when there is a request to receive an industrial Ethernet message, storing the target message received by the network card in the ring buffer area includes:
[0010] When there is a request to receive an industrial Ethernet message, a target message is received which is transmitted sequentially from each slave device through the second network port and arrives at the first network port of the master device, and the target message is stored in the ring buffer area.
[0011] Optionally, the creating and binding corresponding socket resources includes:
[0012] A socket is created by calling a network socket creation function through an application, and the socket is used to enter the kernel space of the operating system to call a kernel interface to create a corresponding socket resource, and the socket resource is bound to the first network port of the master station device so as to actively send or receive the industrial Ethernet message through the first network port.
[0013] Optionally, binding the socket resource to the first network port of the master station device so as to actively send or receive the industrial Ethernet message through the first network port includes:
[0014] The socket resource is bound by calling a network socket binding function through an application program, and then the socket resource is bound to the first network port of the master station device by calling a kernel interface, so as to actively send or receive the industrial Ethernet message through the first network port.
[0015] Optionally, the application program reads the to-be-received industrial Ethernet message directly from the circular buffer area according to the communication cycle and using the corresponding socket resources to achieve reception of the industrial Ethernet message, including:
[0016] When the communication cycle set by the timer is triggered, the application uses the corresponding socket resources to directly read and receive the target industrial Ethernet message from the circular buffer area to achieve periodic reception of the industrial Ethernet message.
[0017] Optionally, the application uses the corresponding socket resources to directly read and receive the target industrial Ethernet message from the ring buffer area to implement periodic reception of the industrial Ethernet message, including:
[0018] The application uses the first network port specified by the receiving system function in the socket resource to directly read the corresponding cache result from the ring buffer area;
[0019] If the cache result is empty, it indicates that the current target industrial Ethernet message has not arrived at the ring buffer area, and the received error signal is fed back to the application;
[0020] If the cache result is that cache data exists, the cache data is received as the target Industrial Ethernet message.
[0021] In a second aspect, the present application discloses an industrial Ethernet message transmission optimization device, which is applied to an industrial automation system, comprising:
[0022] A message sending module, used for creating and binding corresponding socket resources, so as to directly transfer the industrial Ethernet message to be sent from the application layer to the ring buffer area of the link layer through the application program and by using the socket resources, so as to transmit the ring buffer area data to the network card through the bound first network port, so as to send the corresponding industrial Ethernet message;
[0023] The message receiving module is used to store the target message received by the network card into the circular buffer area when there is a request to receive an industrial Ethernet message. Then the application reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and using the corresponding socket resources to realize the reception of the industrial Ethernet message.
[0024] In a third aspect, the present application discloses an electronic device, comprising:
[0025] Memory, used to store computer programs;
[0026] The processor is used to execute the computer program to implement the steps of the aforementioned disclosed industrial Ethernet message transmission optimization method.
[0027] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the aforementioned disclosed industrial Ethernet message transmission optimization method are implemented.
[0028] It can be seen that the present application discloses an industrial Ethernet message transmission optimization method, which is applied to industrial automation systems, including: creating and binding corresponding socket resources, so that the industrial Ethernet message to be sent is directly transferred from the application layer to the ring buffer area of the link layer through the application program and using the socket resources, so that the ring buffer area data is transmitted to the network card through the bound first network port to send the corresponding industrial Ethernet message; when there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the ring buffer area, and then the application program reads the industrial Ethernet message to be received directly from the ring buffer area according to the communication cycle and using the corresponding socket resources to realize the reception of the industrial Ethernet message. It can be seen that by transferring the industrial Ethernet message to be sent directly from the application layer to the ring buffer area of the link layer to send the corresponding industrial Ethernet message, the use of socket resources to process the kernel sending process reduces the intermediate links of message transmission and improves the transmission efficiency. When there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the circular buffer area, and then the industrial Ethernet message to be received is directly read from the circular buffer area according to the communication cycle and the corresponding socket resources. Compared with the traditional interrupt processing method, the original interrupt processing method is cancelled, and the hardware automatically stores the target message received by the network card in the circular buffer area and no longer reports to the processor. Then the application program reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and the corresponding socket resources, avoiding the problem of large jitter of message reception caused by low priority of soft interrupt and complex processing process. In this way, the synchronous processing method is adopted, and the application layer directly reads the industrial Ethernet message from the circular buffer area, which changes the original interrupt processing method, making the process of receiving the industrial Ethernet message simple and direct, avoiding the network card has obviously received the industrial Ethernet message, but because of the low priority of the soft interrupt and the complex processing process, the transmission process is interrupted by other high-priority tasks, thereby being suspended for a long time, resulting in large jitter of the industrial Ethernet message received by the application layer, and even in serious cases, the problem of not being able to read the industrial Ethernet message before the deadline. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0030] Figure 1 A flow chart of an industrial Ethernet message transmission optimization method disclosed in this application;
[0031] Figure 2 A connection diagram between a master station device and a slave station device disclosed in this application;
[0032] Figure 3 A flow chart of an industrial Ethernet message sending method disclosed in this application;
[0033] Figure 4 A flow chart of an industrial Ethernet message receiving method disclosed in this application;
[0034] Figure 5 This is a schematic diagram of the structure of an industrial Ethernet message transmission optimization device disclosed in this application;
[0035] Figure 6 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0037] In industrial Ethernet, industrial Ethernet messages are transmitted in the form of original data packets. Original data packets mean that data packets bypass the intermediate transport layer and network layer and are directly transmitted between the application layer and the link layer. Sending is: the application layer data is passed to the link layer through the network socket, and the link layer adds a check value and then directly passes it to the physical layer. Receiving is: after the physical layer data is passed to the link layer, the check value is removed and passed from the link layer to the application layer. When the network message in Ethernet reaches the network card, the message will be cached in the pre-applied ring buffer area, and then it has the function of notifying the processor that the message has arrived and requesting processing. After receiving the request, the processor can suspend the current task and give priority to the request. This process is interrupt processing. Therefore, the network message data volume is relatively large and the process is complicated. If it takes a long time to process the network message during interrupt processing. Interrupt processing will take precedence over other tasks, and the processing time is too long, which will delay other tasks. Therefore, the network uses hard interrupts and soft interrupts. Hard interrupts process fast tasks such as network card status and trigger soft interrupts. Then resume the interrupted task. Soft interrupts process non-urgent tasks. Network message processing is placed in soft interrupt processing.
[0038] In the Linux operating system, each task has an associated priority that determines the order in which it is executed on the CPU. A high-priority task can be executed before a low-priority task. There may even be a preemption, that is, a high-priority task interrupts the execution of a low-priority task and runs first. An interrupt request is a preemption behavior. Since a soft interrupt is a low-priority task, when the CPU system is busy, the soft interrupt may not be responded to for a long time, and network messages may not be processed in time.
[0039] In the existing technology, the real-time performance of industrial Ethernet messages is optimized from the perspective of hardware. For example, dedicated chips are used to receive, revise and forward Ethernet frames. Real-time kernels are used to send and receive industrial Ethernet messages, such as xenomai (a real-time development framework for the Linux kernel). Although the dedicated chip method has good real-time effect, it is not flexible and requires special embedded chips to support dedicated chips. Devices that do not support this technology cannot use this technology. Adding a real-time kernel requires recompiling the application source code. The above two methods are not universal enough and will be restricted by the platform or application.
[0040] To this end, the present invention provides an industrial Ethernet message transmission optimization solution, which can solve the problem of large delay in network socket transmission of industrial Ethernet messages and realize direct reading of industrial Ethernet message information from a ring buffer area.
[0041] Reference Figure 1 As shown, an embodiment of the present invention discloses an industrial Ethernet message transmission optimization method, which is applied to an industrial automation system, comprising:
[0042] Step S11: Create and bind corresponding socket resources so that the industrial Ethernet message to be sent can be directly transferred from the application layer to the ring buffer area of the link layer through the application program and by using the socket resources, so that the ring buffer area data can be transmitted to the network card through the bound first network port to send the corresponding industrial Ethernet message.
[0043] In this embodiment, the industrial automation system includes: a master station device and a slave station device, wherein the master station device is a terminal device for actively sending or receiving industrial Ethernet messages, and the slave station device is a network device located in the Ethernet and used to transmit the industrial Ethernet messages, and one network interface of the master station device is set as a first network port, and two or more network interfaces of each of the slave station devices are set as a second network port, so that the master station device is connected to the slave station device through the first network port, and the slave station devices are connected to each other through the second network port. One network interface of the master station device is set as a first network port, and two or more network interfaces of each of the slave station devices are set as a second network port, so that the master station device is connected to the slave station device through the first network port, and the slave station devices are connected to each other through the second network port. It can be understood that, with reference to Figure 2 As shown, in order to optimize the transmission of Ethernet messages in industrial Ethernet, it is necessary to set up master station devices and slave station devices in the industrial automation system, where the master station device is a terminal device that actively sends and receives industrial Ethernet messages, and the slave station device is a network device in the Ethernet message transmission process. For example: in an industrial scenario, the master station device sends control instructions to the slave station device, and the control instructions are: collect field data information of a certain link in the automated industrial environment. Therefore, in the industrial automation production scenario where the data collected by sensors in the automated industrial production environment needs to be sent to the remote control center as soon as possible, the terminal devices are industrial computers, PLCs, etc., and the slave station devices are network devices such as sensors, actuators, Ethernet switches, etc. Then the master station device is connected to each slave station device through a given network port, and finally a network topology is formed to realize the exchange and transmission of field data information. Among them, as Figure 2As shown, the master station device pre-specifies one of the network ports as the first network port for connecting to the slave station device. Each device is called a node, and the master station node sends or receives Industrial Ethernet messages through the pre-specified network port (first network port). In addition to the master station node, other nodes (slave station devices) generally include more than two network ports, that is, the second network port, which is used to connect all nodes. The master station node is the only node in the network segment that can actively send Industrial Ethernet messages, and other nodes only participate in transmitting messages. Therefore, the working mode of Industrial Ethernet in the present invention is that the master station node periodically sends / receives Industrial Ethernet messages, and the Industrial Ethernet messages pass through all nodes and finally return to the master station node by the original path.
[0044] In this embodiment, a socket is created by calling a network socket creation function through an application program, and the socket is used to enter the kernel space of the operating system to call a kernel interface to create a corresponding socket resource, and the socket resource is bound to the first network port of the master station device, so as to actively send or receive the industrial Ethernet message through the first network port. Specifically, the socket resource is bound by calling a network socket binding function through an application program, and then the kernel interface is called to bind the socket resource to the first network port of the master station device, so as to actively send or receive the industrial Ethernet message through the first network port. It can be understood that before the industrial Ethernet message is transmitted, the process of processing the industrial Ethernet message in the kernel space is rewritten to simplify the process of sending and receiving the industrial Ethernet message. Specifically, first, the application program for realizing the control function running on the master station device, the control center and other devices performs sokcet (socket) creation, and the specific creation process is as follows:
[0045] The application calls the network socket creation function "socket" to create a socket, enters the kernel space through the "socket" function, calls the kernel interface "__sys_socket" function, and creates the corresponding socket resources in this function for sending and receiving ethercat (EtherNet Control Automation Technology (Control Automation Technology, control automation technology), Ethernet control automation technology) messages.
[0046] When the creation is completed, the created socket resource is bound to the first interface of the master station device, that is, the network socket binding function is called by the application to bind the socket resource, and then the kernel interface is called to bind the socket resource to the first network port of the master station device, so as to actively send or receive the industrial Ethernet message through the first network port. Specifically, the application calls the network socket binding function "bind" to bind the socket resource. Enter the kernel space through the "bind" function and call the kernel interface "__sys_bind" function. The invention binds the first network port and the created socket resource that have been determined in advance in this function, and directly specifies the function interface of the network card driver to process the sending and receiving of ethercat messages, so that the sending and receiving process can execute the streamlined message direct sending and direct receiving processing method through the specified function interface.
[0047] In this embodiment, after the kernel rewrite process is completed, the master station device actively starts the message sending process. Specifically, the industrial Ethernet message to be sent is directly transferred from the application layer to the ring buffer area of the link layer through the kernel space and using the created socket resources, so as to transmit the ring buffer area data to the network card through the first network port. It can be understood that the application program of the master station device calls the socket resource to transfer the industrial Ethernet message to be sent from the application layer to the link layer, and then transmits it to the ring buffer area through the specified sending function interface. After that, the hardware control will directly transmit the ring buffer area message to the network card. Specifically, Figure 3 As shown, in the message sending process, it is divided into a user space execution process and a kernel space execution process, wherein the user space execution process includes: the application calls the network socket sending function "send" to send the ethercat message. The "send" standard function sends the message into the kernel space. The kernel space execution process includes: running the first kernel space function "__sys_sendto". In this function, the ethercat message is directly passed to the ring buffer in the network card driver through the specified sending function interface. The message in the ring buffer will be sent to the network card by hardware control. The steps of sending industrial Ethernet messages are simplified. Reduce the possibility and number of interruptions of the sending process by other high-priority tasks, thereby ensuring the real-time sending of industrial Ethernet messages.
[0048] Step S12: When there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the circular buffer area, and then the application reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and using the corresponding socket resources to realize the reception of the industrial Ethernet message.
[0049] In this embodiment, when the first slave station device receives the circular buffer area data from the network card through the second network interface, the circular buffer area data is identified and processed to obtain the corresponding target industrial Ethernet message, and the target industrial Ethernet message is transmitted and processed between other slave station devices through the second network interface until the target industrial Ethernet message is transmitted back to the first slave station device; wherein the other slave station devices are slave station devices other than the first slave station device.
[0050] In this embodiment, when the first slave station device receives the circular buffer data from the network card through the second network interface, the circular buffer data is identified, and the first slave station device information is inserted into the industrial Ethernet message after successful identification to obtain the corresponding target industrial Ethernet message. It can be understood that the industrial Ethernet message in the circular buffer is transmitted in the same way as the ethercat message is transmitted in the Ethernet. It should be noted that the industrial Ethernet message is transmitted through the second network interface, that is, it is directly transmitted end-to-end, which reduces the transmission time. In addition, each time it is transmitted to a slave station device, each slave station device is controlled to perform corresponding identification processing on the message data, parse the frame data, add frame data, etc. according to the instruction requirements in the industrial Ethernet message. Among them, the industrial Ethernet message processed by the first slave station device is used as the target industrial Ethernet message, and then the target industrial Ethernet message processed by the first slave station device is transmitted to the next slave station device through the second network interface of the first slave station device, so that the next slave station device can identify and process it, and the target industrial Ethernet message processed by the last slave station device is transmitted back to the first slave station device. It can be understood that by combining Figure 2 It can be seen that after each slave device completes processing and transmission of the industrial Ethernet message, it is sent to the previous slave device in the original order until it returns to the first slave device, thus completing the transmission process of the Ethernet message using the slave device.
[0051] In this embodiment, when there is a request to receive an industrial Ethernet message, the target message that arrives at the first network port of the master device after being transmitted sequentially from each slave device through the second network port is received, and the target message is stored in the circular buffer area. It can be understood that the original hard interrupt and soft interrupt processing methods are cancelled. When there is a request to receive an industrial Ethernet message, the hardware automatically stores the target message received by the network card in the circular buffer area and no longer reports the event. Then the application program reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and uses the corresponding socket resources to realize the reception of the industrial Ethernet message. After the transmission process of the Ethernet message using the slave device is completed, the target industrial Ethernet message returned by the first slave device is passed to the application layer so that the network card receives the target message and stores it in the circular buffer area. It can be seen that through the designated first network interface and the second network interface, specific network ports of the industrial Ethernet message are designated to connect with the master station device and the slave station device, which reduces the complexity and uncertainty of the network path, makes the message data transmission more direct and efficient, avoids unnecessary routing and switching delays, and thus shortens the time for the message data to reach the network card.
[0052] In this embodiment, when the communication cycle set by the trigger timer is triggered, the application uses the corresponding socket resources to directly read and receive the target Industrial Ethernet message from the circular buffer area to achieve periodic reception of Industrial Ethernet messages. Specifically, the application uses the first network port specified by the receiving system function in the socket resources to directly read the corresponding cache result from the circular buffer area; if the cache result is empty, it indicates that the current target Industrial Ethernet message has not arrived at the circular buffer area, and the received error signal is fed back to the application; if the cache result is that there is cache data, the cache data is received as the target Industrial Ethernet message. It can be understood that the master station device reads the target Industrial Ethernet message from the circular buffer area according to the communication cycle to achieve periodic sending or receiving of Industrial Ethernet messages.
[0053] In the previous transmission scheme of industrial Ethernet messages, the steps of sending messages from the application layer to the circular buffer are: the application layer message is sent to the link layer through the original socket, and the specific steps are: preset a target queue (the target queue contains the message to be transmitted), send it to the link layer through the queue method, and after reaching the link layer, read the message to be transmitted from the target queue, and store the read message to be transmitted in the circular buffer. In the transmission scheme of industrial Ethernet messages of the present invention, the optimization of the receiving method is as follows: for sending messages, the hardware transmits the message from the application layer to the circular buffer of the link layer, omitting the process of sending the original socket to the circular buffer of the link layer (generating a queue, sending the queue, and reading the message from the queue). For receiving messages, when the cycle time arrives, the application directly reads the ethercat message from the circular buffer through the network socket. When the communication cycle is reached, the application uses the socket resources to read and receive the target industrial Ethernet message from the circular buffer, so that the user can periodically send or receive industrial Ethernet messages. Figure 4 As shown, a synchronous processing method is adopted. After the ethercat message is cached in the ring buffer area, no request interrupt is sent to the processor. The application calls the network socket to periodically receive data. Among them, the execution process of the user space is as follows:
[0054] 1. The application uses the receiving system function "recv" in the network socket to receive the ethercat message.
[0055] 2. The "recv" standard function sends the message into the ethercat kernel space.
[0056] The execution process of kernel space is as follows:
[0057] 1. Run the first kernel space function "__sys_recvfrom".
[0058] 2. This function reads the ethercat message directly from the ring buffer in the network card driver through the specified receiving function interface.
[0059] i. Read successfully (data arrives), and return message.
[0060] ii. Reading fails (data not received), and an error is returned.
[0061] It can be understood that the message receiving process is to store the industrial Ethernet message in the circular buffer area through hardware. Once the application cycle arrives, the data will be read directly from the circular buffer area through the socket resource, and there is no waiting for the cumbersome soft interrupt and other thread actions in the middle. Specifically, when the prior art receives the industrial Ethernet message, it is processed by the kernel thread ksoftirq soft interrupt. The thread has a low priority and its operation is easily affected by the high-priority thread. If the thread has not been responded to, the application layer cannot read the industrial Ethernet message received by the network port. However, after rewriting the kernel, the application reads data directly from the circular buffer area through the socket when the cycle time arrives. Therefore, when receiving the industrial Ethernet message at this moment, either the data has arrived and is waiting. Or it has not returned and will no longer be affected by the soft interrupt thread. The jitter time of the receiving process is reduced. It can be seen that the present invention changes the original asynchronous reception processing method and adopts synchronous processing. The application layer directly reads the ethercat message from the circular buffer area. The original interrupt processing method and the protocol layer processing process are changed, making the process of receiving the ethercat message simple and direct. This avoids the situation where the network card has clearly received the industrial Ethernet message, but the transmission process is interrupted by other high-priority tasks due to the low priority of the soft interrupt and the complex processing process, resulting in a long period of suspension, causing large jitter in the Ethercat message received by the application layer, or even in severe cases, the Ethercat message cannot be read before the deadline.
[0062] The industrial Ethernet message reception and transmission of the present invention is more efficient, and interruptions by other high-priority transactions are reduced. Sending: The industrial Ethernet message sent by the application is directly transmitted to the circular buffer area in the network card driver, and then directly transmitted to the network card by hardware operation. Receiving: A synchronous processing method is adopted. The application reads the industrial Ethernet message directly from the circular buffer area in the network card driver. In this way, by rewriting the process of processing industrial Ethernet messages in the kernel, the process and mechanism of message data processing can be optimized. Priority processing can be more accurately regulated to ensure that high-priority network messages can be quickly processed and transmitted, rather than waiting in the circular buffer area or being interrupted by other low-priority messages, which effectively reduces the residence time.
[0063] In addition, the above method is more universal and has no restrictions on device platforms and applications. The process of the kernel processing industrial Ethernet messages is rewritten to achieve that if the network port is designated as a network port for industrial Ethernet messages, it is executed in the invented way, otherwise it is executed in the original way. The two are compatible and do not affect each other.
[0064] It can be seen that the present application discloses the creation and binding of corresponding socket resources, so that the industrial Ethernet message to be sent is directly transferred from the application layer to the ring buffer area of the link layer through the application program and by using the socket resources, so that the ring buffer area data is transmitted to the network card through the bound first network port to send the corresponding industrial Ethernet message; when there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the ring buffer area, and then the application program reads the industrial Ethernet message to be received directly from the ring buffer area according to the communication cycle and by using the corresponding socket resources to realize the reception of the industrial Ethernet message. It can be seen that by transferring the industrial Ethernet message to be sent directly from the application layer to the ring buffer area of the link layer to send the corresponding industrial Ethernet message, the use of socket resources to process the kernel sending process reduces the intermediate links of message transmission and improves the transmission efficiency. When there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the circular buffer area, and then the industrial Ethernet message to be received is directly read from the circular buffer area according to the communication cycle and the corresponding socket resources. Compared with the traditional interrupt processing method, the original interrupt processing method is cancelled, and the hardware automatically stores the target message received by the network card in the circular buffer area and no longer reports to the processor. Then the application program reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and the corresponding socket resources, avoiding the problem of large jitter of message reception caused by low priority of soft interrupt and complex processing process. In this way, the synchronous processing method is adopted, and the application layer directly reads the industrial Ethernet message from the circular buffer area, which changes the original interrupt processing method, making the process of receiving the industrial Ethernet message simple and direct, avoiding the network card has obviously received the industrial Ethernet message, but because of the low priority of the soft interrupt and the complex processing process, the transmission process is interrupted by other high-priority tasks, thereby being suspended for a long time, resulting in large jitter of the industrial Ethernet message received by the application layer, and even in serious cases, the problem of not being able to read the industrial Ethernet message before the deadline.
[0065] Reference Figure 5 As shown, the present invention also discloses an industrial Ethernet message transmission optimization device, which is applied to an industrial automation system, including:
[0066] The message sending module 11 is used to create and bind the corresponding socket resources, so as to transfer the industrial Ethernet message to be sent directly from the application layer to the ring buffer area of the link layer through the application program and by using the socket resources, so as to transmit the ring buffer area data to the network card through the bound first network port to send the corresponding industrial Ethernet message;
[0067] The message receiving module 12 is used to store the target message received by the network card into the circular buffer area when there is a request to receive an industrial Ethernet message. Then the application reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and using the corresponding socket resources to realize the reception of the industrial Ethernet message.
[0068] It can be seen that the present application discloses the creation and binding of corresponding socket resources, so that the industrial Ethernet message to be sent is directly transferred from the application layer to the ring buffer area of the link layer through the application program and by using the socket resources, so that the ring buffer area data is transmitted to the network card through the bound first network port to send the corresponding industrial Ethernet message; when there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the ring buffer area, and then the application program reads the industrial Ethernet message to be received directly from the ring buffer area according to the communication cycle and by using the corresponding socket resources to realize the reception of the industrial Ethernet message. It can be seen that by transferring the industrial Ethernet message to be sent directly from the application layer to the ring buffer area of the link layer to send the corresponding industrial Ethernet message, the use of socket resources to process the kernel sending process reduces the intermediate links of message transmission and improves the transmission efficiency. When there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the circular buffer area, and then the industrial Ethernet message to be received is directly read from the circular buffer area according to the communication cycle and the corresponding socket resources. Compared with the traditional interrupt processing method, the original interrupt processing method is cancelled, and the hardware automatically stores the target message received by the network card in the circular buffer area and no longer reports to the processor. Then the application program reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and the corresponding socket resources, avoiding the problem of large jitter of message reception caused by low priority of soft interrupt and complex processing process. In this way, the synchronous processing method is adopted, and the application layer directly reads the industrial Ethernet message from the circular buffer area, which changes the original interrupt processing method, making the process of receiving the industrial Ethernet message simple and direct, avoiding the network card has obviously received the industrial Ethernet message, but because of the low priority of the soft interrupt and the complex processing process, the transmission process is interrupted by other high-priority tasks, thereby being suspended for a long time, resulting in large jitter of the industrial Ethernet message received by the application layer, and even in serious cases, the problem of not being able to read the industrial Ethernet message before the deadline.
[0069] Furthermore, the present application also discloses an electronic device. Figure 6 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.
[0070] Figure 6A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the industrial Ethernet message transmission optimization method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0071] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0072] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0073] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0074] Among them, the operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, so as to realize the operation and processing of the massive data 223 in the memory 22 by the processor 21, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the industrial Ethernet message transmission optimization method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks. In addition to data transmitted from an external device received by the electronic device, the data 223 can also include data collected by its own input and output interface 25, etc.
[0075] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed industrial Ethernet message transmission optimization method is implemented. The specific steps of the method can refer to the corresponding contents disclosed in the aforementioned embodiments, and will not be repeated here.
[0076] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0077] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application. The steps of the method or algorithm described in conjunction with the embodiments disclosed herein can be implemented directly with hardware, a software module executed by a processor, or a combination of the two. The software module can be placed in a random access memory RAM (Random Access Memory), memory, read-only memory ROM (Read Only Memory), electrically programmable EPROM (Electrically Programmable Read Only Memory), electrically erasable programmable EEPROM (ElectricErasable Programmable Read Only Memory), register, hard disk, removable disk, CD-ROM (CompactDisc-Read Only Memory), or any other form of storage medium known in the technical field.
[0078] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0079] The scheme provided by the present invention is introduced in detail above. Specific examples are used in this article to illustrate the principle and implementation mode of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation mode and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. An industrial Ethernet message transmission optimization method, characterized in that: Applied to an industrial automation system, the industrial automation system includes a master station device and a slave station device, the master station device is a terminal device for actively sending or receiving industrial Ethernet messages, the slave station device is a network device located in the Ethernet and used to transmit the industrial Ethernet message, one network interface of the master station device is set as a first network port, and two or more network interfaces of each of the slave station devices are set as a second network port, so that the master station device is connected to the slave station device through the first network port, and the slave station devices are connected to each other through the second network port, and the method includes: Create and bind a corresponding socket resource, so as to directly transfer the to-be-sent industrial Ethernet message from the application layer to the ring buffer of the link layer by using the socket resource through the application program, so as to transmit the ring buffer data to the network card through the bound first network port, so as to send the corresponding industrial Ethernet message; When there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the circular buffer area, and then the application program reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and using the corresponding socket resources to realize the reception of the industrial Ethernet message; Wherein, the creating and binding corresponding socket resources includes: A socket is created by calling a network socket creation function through an application, and the socket is used to enter the kernel space of the operating system to call a kernel interface to create a corresponding socket resource, and the socket resource is bound to the first network port of the master station device so as to actively send or receive the industrial Ethernet message through the first network port.
2. The method for optimizing industrial Ethernet message transmission according to claim 1, characterized in that: When there is a request to receive an industrial Ethernet message, the target message received by the network card is stored in the ring buffer area, including: When there is a request to receive an industrial Ethernet message, a target message is received which is transmitted sequentially from each slave device through the second network port and arrives at the first network port of the master device, and the target message is stored in the ring buffer area.
3. The method for optimizing industrial Ethernet message transmission according to any one of claims 1 or 2, characterized in that: The application program reads the to-be-received industrial Ethernet message directly from the circular buffer area according to the communication cycle and using the corresponding socket resources to realize the reception of the industrial Ethernet message, including: When the communication cycle set by the timer is triggered, the application uses the corresponding socket resources to directly read and receive the target industrial Ethernet message from the circular buffer area to achieve periodic reception of the industrial Ethernet message.
4. The method for optimizing industrial Ethernet message transmission according to claim 3, characterized in that: The application uses the corresponding socket resources to directly read and receive the target industrial Ethernet message from the circular buffer area to achieve periodic reception of the industrial Ethernet message, including: The application uses the first network port specified by the receiving system function in the socket resource to directly read the corresponding cache result from the ring buffer area; If the cache result is empty, it indicates that the current target industrial Ethernet message has not arrived at the ring buffer area, and the received error signal is fed back to the application; If the cache result is that cache data exists, the cache data is received as the target Industrial Ethernet message.
5. An industrial Ethernet message transmission optimization device, characterized in that: Applied to an industrial automation system, the industrial automation system includes a master station device and a slave station device, the master station device is a terminal device for actively sending or receiving industrial Ethernet messages, the slave station device is a network device located in the Ethernet and used to transmit the industrial Ethernet message, one network interface of the master station device is set as a first network port, and two or more network interfaces of each of the slave station devices are set as a second network port, so that the master station device is connected to the slave station device through the first network port, and the slave station devices are connected to each other through the second network port, the device includes: A message sending module, used for creating and binding corresponding socket resources, so as to directly transfer the industrial Ethernet message to be sent from the application layer to the ring buffer area of the link layer through the application program and by using the socket resources, so as to transmit the ring buffer area data to the network card through the bound first network port, so as to send the corresponding industrial Ethernet message; A message receiving module, which is used to store the target message received by the network card into the circular buffer area when there is a request to receive an industrial Ethernet message, and then the application program reads the industrial Ethernet message to be received directly from the circular buffer area according to the communication cycle and using the corresponding socket resources to realize the reception of the industrial Ethernet message; The message sending module is specifically used to create a socket by calling a network socket creation function through an application, and use the socket to enter the kernel space of the operating system to call the kernel interface to create a corresponding socket resource, and bind the socket resource to the first network port of the master station device, so as to actively send or receive the industrial Ethernet message through the first network port.
6. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor is used to execute the computer program to implement the steps of the industrial Ethernet message transmission optimization method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: Used to store computer programs; wherein, when the computer program is executed by a processor, the steps of the industrial Ethernet message transmission optimization method as described in any one of claims 1 to 4 are implemented.
