A Protocol Conversion Method Based on Double Buffers

By introducing a weighted cyclic algorithm priority queue and a circular buffer into the PROFINET protocol conversion gateway, the problem of high-priority message loss was solved, and the stability and reliability of the system were improved.

CN116366574BActive Publication Date: 2026-05-26NANJING UNIV OF SCI & TECH +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NANJING UNIV OF SCI & TECH
Filing Date
2023-03-17
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

In PROFINET protocol conversion gateways, high-priority messages are easily lost due to untimely processing or full buffers, leading to equipment damage and affecting system stability.

Method used

By combining a priority queue based on a weighted cyclic algorithm and a circular buffer, a new technical solution is designed. This solution utilizes a dual-buffer protocol and configures the priority queue and circular buffer via serial port to achieve priority scheduling and buffer management of packets, ensuring timely processing of high-priority packets.

Benefits of technology

This effectively reduces the loss of high-priority messages and improves the reliability and stability of the gateway system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116366574B_ABST
    Figure CN116366574B_ABST
Patent Text Reader

Abstract

This invention discloses a protocol conversion method based on a dual buffer. Addressing the issue of high-priority packet loss when using a circular buffer in a serial port, it proposes a method combining a weighted cyclic priority queue and a circular buffer. This method includes: configuring a weighted cyclic priority queue in the serial port; configuring a circular buffer in the serial port; and sending or receiving packets through the dual buffer. A welding robot and a gateway are connected via a network cable, while the gateway and the welding machine are connected via a serial cable. The welding robot and gateway use a Process Field Network (PROFINET), and the gateway and welding machine use the MODBUS protocol. The gateway performs protocol conversion, thereby enabling the welding robot to control the welding machine. This invention employs a method combining a weighted cyclic priority queue and a circular buffer, reducing the loss of high-priority packets and improving the stability of the gateway system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of protocol conversion technology, and in particular to a protocol conversion method based on a double buffer. Background Technology

[0002] In recent years, the development of new energy vehicles has spurred the rapid growth of the lithium battery industry. The welding technology, a crucial aspect of lithium battery manufacturing, is becoming increasingly automated. With the intelligent development of industrial automation, the advantages of Ethernet technology in industrial automation are becoming apparent, and PROFINET, based on Ethernet, is gradually becoming the mainstream protocol conversion technology between various industrial devices. With the rise of PROFINET technology, welding robots based on the PROFINET protocol have been launched. However, since traditional welding equipment still commonly uses the MODBUS protocol, the two cannot be directly connected.

[0003] During actual operation, the gateway is subject to various interferences in the industrial environment, and the drive circuit between the two protocol conversion boards of the gateway may be damaged due to interference, which may even lead to the paralysis of the entire gateway system.

[0004] When the serial port of the PROFINET protocol conversion gateway receives a large number of messages, messages may be lost due to untimely processing. In particular, when using a circular buffer, the principle of first-in, first-out (FIFO) is followed. Therefore, when a high-priority message enters the buffer late, it must wait for the preceding messages to be processed before it can be processed. If the preceding message has a large amount of data, it will seriously affect the processing of the message. When the buffer is full, it will be cleared to ensure the entry of subsequent messages. This will cause high-priority messages to be unprocessed and lost in time, which may cause serious damage to the equipment. Summary of the Invention

[0005] The purpose of this invention is to provide a protocol conversion method based on a double buffer to solve the problem of high-priority serial port packet loss, thereby improving the reliability and stability of the gateway system.

[0006] The technical solution to achieve the objective of this invention is as follows: Firstly, this invention provides a protocol conversion method based on a double buffer, comprising the following steps:

[0007] Step 1: Configure a priority queue based on a weighted round-robin algorithm in the serial port. The weighted round-robin algorithm allocates bandwidth according to the weights W0 and W1 configured for each queue, and calculates the value of the counter count for each queue to determine whether to continue the loop.

[0008] Step 2: Configure a circular buffer in the serial port. Use head and tail pointers to read and write data in the buffer by moving these two pointers. Calculate the remaining length of the buffer, Lenth. When Lenth = 0, it indicates that the buffer is full. At this time, clear the buffer to zero and then store new data.

[0009] Step 3: Messages are sent or received through a double buffer. Using the priority queue set in the serial port in Step 1, messages are arranged and scheduled according to weights W0 and W1, and then stored in the circular buffer in sequence. At the same time, the values ​​of count and length are calculated to ensure that scheduling and storage are carried out smoothly. Finally, the two pointers of the circular buffer are moved to perform message sending and receiving operations.

[0010] In a second aspect, the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method described in the first aspect.

[0011] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in the first aspect.

[0012] Fourthly, the present invention provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the method described in the first aspect.

[0013] Compared with the prior art, the significant advantages of this invention are: by designing a priority queue based on a weighted circular algorithm and a circular buffer, this invention not only improves the packet loss rate but also further reduces the loss of high-priority packets, thereby improving the stability of the gateway system.

[0014] The present invention will be further described below with reference to specific embodiments and accompanying drawings. Attached Figure Description

[0015] Figure 1 This is a hardware circuit schematic diagram of a highly stable protocol conversion gateway in an embodiment of the present invention.

[0016] Figure 2 This is a general structure diagram of the software design of a highly stable protocol conversion gateway in this embodiment of the invention.

[0017] Figure 3 This is a diagram illustrating the scheduling principle of the weighted loop algorithm.

[0018] Figure 4 This is a schematic diagram of a circular buffer.

[0019] Figure 5 This is a diagram illustrating the message structure when using the improved buffer. Detailed Implementation

[0020] The protocol conversion gateway for highly stable welding robots and welding machines is designed based on a combination of a priority queue and a circular buffer using a weighted circular algorithm. Its hardware circuit schematic is shown below. Figure 1 As shown, its overall software design structure diagram is as follows: Figure 2 As shown.

[0021] This invention provides a protocol conversion method based on a double buffer, comprising the following steps:

[0022] Step 1: Configure a priority queue based on a weighted round-robin algorithm on the serial port. The weighted round-robin algorithm allocates bandwidth equally according to the weights W0 and W1 configured for each queue, and calculates the value of the counter count for each queue to determine whether to continue the loop.

[0023] Step 2: Configure a circular buffer in the serial port. Use head and tail pointers to read and write data in the buffer by moving these two pointers. Calculate the remaining length of the buffer, Lenth. When Lenth = 0, it indicates that the buffer is full. At this time, clear the buffer to zero, and then new data can be stored. This reduces the time spent frequently releasing channels in ordinary queues.

[0024] Step 3: Messages are sent or received through a double buffer. Using the priority queue set in the serial port in Step 1, messages are arranged and scheduled according to weights W0 and W1, and then stored in the circular buffer in sequence. At the same time, the values ​​of count and length are calculated to ensure that scheduling and storage are carried out smoothly. Finally, the two pointers of the circular buffer are moved to perform message sending and receiving operations.

[0025] Furthermore, the specific process of configuring the priority queue based on the weighted round-robin algorithm in step 1 is as follows:

[0026] The priority queue based on the weighted round-robin algorithm allows queues to be scheduled in turn, ensuring that each queue can be served. Compared with the strict priority algorithm, the weighted round-robin algorithm makes the scheduling of queues relatively fairer, especially for lower-priority messages with similar priorities, the weighted round-robin algorithm ensures that they will not be lost due to the buffer being full.

[0027] The principle of the weighted round-robin algorithm is to set a message counter for each queue of the port and count according to the set weight. When the round-robin reaches the queue, the queue outputs a message and the message counter of the queue is decremented by 1 until it is reduced to 0, at which point the scheduling of the queue stops. When the message counters of all queues are reduced to 0, the calculation is recalculated according to the weight and the round-robin scheduling starts again.

[0028] The weighted loop algorithm uses two FIFO channels, each assigned a weight of W0 and W1. The first channel contains N packets, and the second channel contains M packets. During the first polling, W0 packets are retrieved from the first channel and W1 packets from the second channel. At this point, the counters (count) of both channels are decremented by 1. The second polling then begins. If the count in one channel is 0, packets are retrieved only from the other channel. The polling ends when the counts in both channels are both 0.

[0029] Furthermore, the specific process of configuring the circular buffer in step 2 on the serial port is as follows:

[0030] The circular buffer design utilizes two pointers: Head (pointing to the head of the queue) and Tail (pointing to the tail of the queue). The principle is as follows: before data arrives, the circular buffer is initialized, with both the head and tail pointing to "0". When data arrives, Head points to "0", Tail points to the next storage space "1", and the data is stored at address "0". When more data arrives, Head points to "1", Tail points to the next storage space "2", and the data is stored at address "1", and so on. During data processing, data at address "0" is processed first, followed by the next data in sequence, thus enabling reading and writing to the circular buffer. When the head and tail of the queue overlap again, it indicates that the circular buffer is full, and no more data can enter. At this point, the circular buffer is cleared, removing any data that has not been parsed for a long time and retaining the latest data.

[0031] The circular buffer has a remaining length of Lenth and a buffer length of S. Lenth is incremented by 1 when reading data and decremented by 1 when storing data. When Lenth = 0, the buffer is full; when Lenth = S, the buffer is empty. When Lenth = 0, the buffer is cleared; when Lenth ≠ 0, writing to the buffer is allowed.

[0032] Furthermore, the specific process of sending or receiving messages through a double buffer in step 3 is as follows:

[0033] In the dual-buffer transmission or reception, during the first polling, W0 messages are taken from the first channel and W1 messages are taken from the second channel, and then sent to the circular buffer. At this time, the remaining length of the circular buffer is Lenth = S - W0 - W1. Then, during the second polling, W0 + W1 messages are taken and sent to the circular buffer. At this time, the remaining length of the circular buffer is Lenth = S - 2*(W0 + W1). Then, during the next polling, when the count of both FIFO channels is 0, the polling ends. If Lenth = 0, the circular buffer is cleared to allow subsequent messages to enter.

[0034] After steps 1 and 2 are completed, the message, after passing through the priority queue, will be sent to the circular buffer according to the scheduling result. Then, the message will be sent or received according to the following steps. First, define the serial port structure, including setting the serial port baud rate to 115.2Kbps, using 8 bits for data transmission, using 1 stop bit, enabling parity and hardware, setting the receive and send modes, initializing the serial port register according to the parameters, and enabling serial port interrupts and serial port peripherals. Then, define the serial port receive and send functions, obtain the send or receive status bit by calling functions, and determine whether to send or receive data based on the return value. Finally, define the serial port interrupt for sending and receiving data. After defining a variable to store the received data, read the interrupt flag, clear the interrupt flag, store the received characters in an array, and finally send or receive the data through the serial port.

[0035] Example

[0036] The protocol conversion gateway for welding robots and welding machines is designed as follows: the Serial Peripheral Interface (SPI) conversion rate is set to 18Mbps, and the RS-232 protocol conversion rate is set to 115.2Kbps. An encoding switch is used to select which drive circuit to use. Four pins (32, 33, 35, and 52) correspond to OM0 to OM3 respectively. Only one of these three modes can be selected during use, and the selection must be made before the board is reset. Their voltage levels are sampled on the rising edge of the RESET pin on the protocol conversion board to determine the protocol conversion method between the protocol conversion board and the application board. The priority channels are divided into two: priority queue2 is the high-priority queue, and priority queue1 is the low-priority queue. The weight of queue2 is set to 4, and the weight of queue1 is set to 2. According to the algorithm scheduling principle, one message should be retrieved from the queue in the following order: 2-1-2-2-1-2.

[0037] To verify that a dual-buffered mode using a priority queue and a circular buffer based on a weighted circular algorithm in the protocol conversion gateway reduces the loss of high-priority packets more effectively than using only a circular buffer, the priority queue design was first verified using programming software. Then, PROFINET IO packet information was monitored using Wireshark software. By comparing and analyzing the IO tables under the two methods, packet loss was observed and compared.

[0038] Figure 3 This is a diagram illustrating the scheduling principle of the weighted round-robin algorithm. Figure 4 This is a schematic diagram of a circular buffer. Figure 5 This refers to the message situation when using the improved buffer.

[0039] The test results of the priority queue based on the weighted cyclic algorithm show that the queue is scheduled according to a weight ratio of 4:2, and the output result is 1-0-1-1-0-1. The queue is cyclically scheduled according to the set weight ratio until all messages in the queue are output, which verifies the successful design of the priority algorithm.

[0040] Figure 5 The graph shows the message situation when using the improved buffer. As can be seen from the graph, even after the system has been running for a long time, no PROFINET message error messages were found when using the improved buffer. This indicates that the use of the improved buffer reduces message loss and improves the stability of the gateway system.

[0041] In summary, the protocol conversion gateway based on dual buffers proposed in this invention solves the problem of high-priority serial port packets being lost, greatly improving the reliability and stability of the gateway system.

Claims

1. A protocol conversion method based on a double buffer, characterized in that, Includes the following steps: Step 1: Configure a priority queue based on a weighted round-robin algorithm in the serial port. The weighted round-robin algorithm allocates bandwidth according to the weights W0 and W1 configured for each queue, and calculates the value of the counter count for each queue to determine whether to continue the loop. The principle of the weighted round-robin algorithm is to set a message counter for each queue of the port and count according to the set weight. When the round-robin reaches the queue, the queue outputs a message and the message counter of the queue is decremented by 1 until it is decremented to 0, at which point the scheduling of the queue stops. When the message counters of all queues are decremented to 0, the calculation is recalculated according to the weight and the round-robin scheduling starts again. The weighted loop algorithm uses two FIFO channels, with weights W0 and W1 assigned to each channel. The first channel contains N packets, and the second channel contains M packets. During the first polling, W0 packets are taken from the first channel and W1 packets are taken from the second channel. At this time, the counters count of both channels are decremented by 1, and then the second polling begins. When the count in one channel is 0, packets are taken only from the other channel. When the count in both channels is 0, the polling ends. Step 2: Configure a circular buffer in the serial port. Use head and tail pointers to read and write data in the buffer by moving these two pointers. Calculate the remaining length of the buffer, Lenth. When Lenth=0, it indicates that the buffer is full. At this time, clear the buffer to zero and then store new data. Step 3: The message is sent or received through a double buffer. Using the priority queue set in the serial port in Step 1, the messages are arranged and scheduled according to weights W0 and W1, and then stored in the circular buffer in sequence. At the same time, the values ​​of count and Lenth are calculated to ensure that the scheduling and storage are carried out smoothly. Finally, the two pointers of the circular buffer are moved to perform message sending and receiving operations. The specific process of sending or receiving messages through a double buffer is as follows: During the first polling, W0 packets are retrieved from the first channel and W1 packets are retrieved from the second channel, and then sent to the circular buffer. At this time, the remaining length of the circular buffer is Lenth = S - W0 - W1. Then, the second polling is performed, retrieving W0 + W1 packets and sending them to the circular buffer. At this time, the remaining length of the circular buffer is Lenth = S - 2 * (W0 + W1). Then, the next polling is performed. When the count of both FIFO channels is 0, the polling ends. If Lenth = 0, the circular buffer is cleared to allow subsequent packets to enter. After steps 1 and 2 are completed, the message, after passing through the priority queue, will be sent to the circular buffer according to the scheduling result. Then, the message will be sent or received according to the following steps: First, define the serial port structure, set the serial port baud rate to 115.2Kbps, use 8 bits for data transmission, use 1 stop bit, enable parity and hardware, set the receive and send modes, initialize the serial port register according to the parameters, and enable serial port interrupts and serial port peripherals; then define serial port receive and send, obtain the send status bit or receive status bit by calling functions, and determine whether to send or receive data based on the return value; finally, define serial port interrupt for sending and receiving data, define a variable to store the received data, read the interrupt flag bit, clear the interrupt flag bit, store the received characters in an array, and finally send or receive the data through the serial port.

2. The protocol conversion method based on a double buffer according to claim 1, characterized in that, In step 2, the specific process of configuring the circular buffer in the serial port is as follows: The circular buffer is designed using two pointers: Head, which points to the head of the queue, and Tail, which points to the tail of the queue. The principle is as follows: before data arrives, the circular buffer is initialized, with both the head and tail of the queue pointing to "0". When data arrives, the head points to "0", the tail points to the next storage space "1", and the data is stored at address "0". When more data arrives, the head points to "1", the tail points to the next storage space "2", and the data is stored at address "1". When processing data, the data at address "0" is processed first, and then the next data is processed sequentially, thus realizing the reading and writing of the circular buffer. When the head and tail of the queue overlap again, the circular buffer is full, and subsequent data cannot enter. At this time, the circular buffer is cleared, and the latest data is retained. The circular buffer is defined as follows: the remaining length of the buffer is Lenth, and the buffer length is S. Lenth is incremented by 1 when reading data and decremented by 1 when storing data. When Lenth = 0, the buffer is full. When Lenth = S, the buffer is empty. When Lenth = 0, the buffer is cleared. When Lenth ≠ 0, writing to the buffer is allowed.

3. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method as described in any one of claims 1-2.

4. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the method as described in any one of claims 1-2.

5. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the steps of the method described in any of claims 1-2.