Master control multi-serial port concurrent cooperative communication method, electronic equipment and storage medium

By building a cache loop queue and prioritizing high-priority data according to the serial port communication speed and data processing speed, the data loss problem of traditional serial port communication during multi-serial port concurrent communication is solved, and the reliability of data transmission and the timeliness of high-priority data are improved.

CN119807110AActive Publication Date: 2025-04-11SHENZHEN JINGCUN TECH CO LTD

Patent Information

Application Number
CN202411943129.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-04-11
Estimated Expiration
2044-12-27

AI Technical Summary

Technical Problem

Traditional serial communication is prone to buffer congestion and data loss due to data rate differences in data, affecting production safety and system stability.

Method used

By obtaining the communication speed and data processing speed of each serial port, a cache loop queue is built, and high-priority data is processed based on the preset priority sequence and interrupt mechanism to avoid data loss.

Benefits of technology

It effectively avoids buffer overflow and data loss caused by the instant influx of large amounts of data by some serial ports, improves the reliability of data transmission, and ensures the timeliness of high-priority data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807110A_ABST
    Figure CN119807110A_ABST
Patent Text Reader

Abstract

The invention discloses a master control multi-serial port concurrent cooperative communication method, electronic equipment and a storage medium. The communication method comprises the following steps: acquiring a serial port communication speed and a data processing speed; constructing a cache circular queue according to the serial port communication speed and the data processing speed; acquiring at least one piece of data information transmitted from the serial port group; wherein the data information comprises a corresponding serial port identifier; generating an interrupt instruction according to the data information, and sequentially storing the data information at corresponding positions in a cache circular queue according to a serial port identifier of each piece of data information, a preset priority sequence and a write pointer of the cache circular queue; wherein the priority sequence is used for representing the processing priority of each serial port in the serial port group; and extracting the data information from a corresponding position in the cache circular queue according to a read pointer of the cache circular queue, and performing data processing on the data information. According to the invention, data loss of the serial port during communication can be avoided, and the data transmission reliability is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data communication technology, and in particular to a master control multi-serial port concurrent collaborative communication method, electronic equipment and storage medium. Background Art

[0002] In modern society, the fields of industrial automation and intelligent Internet of Things are booming, and it is very common for equipment to integrate multiple serial ports to connect different peripherals and work together. On industrial production lines, the main control equipment needs to communicate with a large number of sensors and actuators via serial ports to monitor and control production; in smart buildings, the central control needs to connect to a variety of environmental monitoring equipment to maintain a good condition in the building.

[0003] However, traditional serial communication solutions have serious defects when multiple serial ports communicate concurrently. Different serial ports are connected to devices with different functions, and the data generation rates vary greatly. Sometimes massive amounts of data pour in instantly, but the conventional sequential processing mode cannot keep up with the pace. The serial port buffer quickly becomes congested. Once it overflows, the data is at risk of being lost, resulting in the loss of key information, which seriously affects production safety and system stability. Summary of the invention

[0004] The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application proposes a master control multi-serial port concurrent cooperative communication method, which can avoid data loss during serial port communication and improve data transmission reliability.

[0005] In a first aspect, the present application provides a master control multi-serial port concurrent collaborative communication method, comprising:

[0006] Get serial port communication speed and data processing speed;

[0007] Constructing a cache circular queue according to the serial port communication speed and the data processing speed;

[0008] Acquire at least one data message transmitted from the serial port group; wherein the data message includes a corresponding serial port identifier;

[0009] Generate an interrupt instruction according to the data information, and store the data information in the corresponding position in the cache circular queue in sequence according to the serial port identifier of each of the data information, the preset priority sequence and the write pointer of the cache circular queue; wherein the priority sequence is used to characterize the processing priority of each serial port in the serial port group, and the interrupt instruction is used to interrupt the task currently being executed;

[0010] According to the read pointer of the cache circular queue, the data information is taken out from the corresponding position in the cache circular queue, and data processing is performed on the data information.

[0011] According to the master control multi-serial port concurrent cooperative communication method of the first aspect embodiment of the present application, at least the following beneficial effects are achieved: first, by detecting and analyzing the hardware parameters of each serial port and the data transmission situation during actual operation, the average serial port communication speed of the serial port group is accurately obtained, and at the same time, the processor performance of the master control device, the load of other currently running tasks, etc. are evaluated, and the data processing speed is comprehensively calculated. According to the acquired serial port communication speed and data processing speed, the length, capacity and other parameters of the cache circular queue are determined according to certain rules and algorithms, and a suitable cache circular queue structure is created. Each serial port is always in a state of listening to the incoming data from the outside world. Once the data is received, it will record which serial port the data comes from, and completely capture the data information. When the serial port receives the data information, the hardware immediately triggers the interrupt mechanism to generate an interrupt instruction, which is passed to the master control processor to suspend the non-critical tasks being executed, give priority to responding to the reception and caching operations of the data information, and then find the preset priority sequence according to the serial port identifier carried by the data information, judge the priority of the serial port data, and give priority to ensuring that the high-priority data information is stored in the corresponding position of the cache circular queue according to the write pointer indication. Subsequently, the system will extract the data information in sequence according to the read pointer of the cache circular queue, and perform corresponding data processing on the data information. In this application, the constructed cache circular queue acts as a data "transfer station", which can flexibly temporarily store the received data according to the different communication speeds of each serial port and the data processing speed of the system, avoiding the direct buffer overflow and data loss caused by the instantaneous influx of a large amount of data into some serial ports, thereby improving the reliability of data transmission. At the same time, the preset priority sequence can distinguish the importance and urgency of different serial port data, and can ensure that high-priority data is first stored in the cache circular queue, and can also be taken out and processed first later, avoiding high-priority data from waiting for a long time due to conventional sequential processing, and being "flooded" by a large amount of low-priority data, ensuring the timeliness of important data.

[0012] According to some embodiments of the first aspect of the present application, constructing a cache circular queue according to the serial port communication speed and the data processing speed includes:

[0013] Constructing an initial circular queue according to the serial port communication speed and the data processing speed;

[0014] Get the preset redundancy ratio;

[0015] The initial circular queue is adjusted according to the redundancy ratio to obtain a cache circular queue.

[0016] According to some embodiments of the first aspect of the present application, after the step of adjusting the initial circular queue according to the redundancy ratio to obtain a cache circular queue, the step further includes:

[0017] At intervals of a preset first time length, obtaining a first total amount of data of the data information received from each serial port, and taking out a second total amount of data of the data information from the buffer circular queue;

[0018] Obtaining a third total amount of data according to a total amount of first data corresponding to each serial port;

[0019] updating the serial port communication speed according to the first time length and the third data amount;

[0020] updating the data processing speed according to the first time length and the second total amount of data;

[0021] The cache circular queue is adjusted according to the redundancy ratio, the updated serial port communication speed and the data processing speed.

[0022] According to some embodiments of the first aspect of the present application, adjusting the cache circular queue according to the redundancy ratio, the updated serial port communication speed and the data processing speed includes:

[0023] According to the cache circular queue, an initial queue length is obtained;

[0024] Calculating a target queue length according to the redundancy ratio, the updated serial port communication speed, and the data processing speed;

[0025] When the absolute difference between the initial queue length and the target queue length is less than or equal to a preset adjustment threshold, maintaining the original cache circular queue;

[0026] When the absolute difference between the initial queue length and the target queue length is greater than the adjustment threshold, the cache circular queue is updated according to the target queue length.

[0027] According to some embodiments of the first aspect of the present application, storing the data information in sequence at corresponding positions in the cache circular queue according to the serial port identifier of each data information, a preset priority sequence and a write pointer of the cache circular queue includes:

[0028] When the data information is being stored in the cache circular queue, when new data information is received from the serial port group, the corresponding first serial port identifier and second serial port identifier are obtained according to the current data information and the new data information respectively;

[0029] According to the first serial port identifier, the second serial port identifier and the priority sequence, obtaining a first priority for the first serial port identifier and a second priority for the second serial port identifier;

[0030] When the first priority is greater than or equal to the second priority, continuing to store the current data information into the cache circular queue according to the write pointer of the cache circular queue;

[0031] When the first priority is less than the second priority, the new data information is stored in the cache circular queue according to the write pointer of the cache circular queue, and the previous data information is stored in the cache circular queue after the new data information is stored.

[0032] According to some embodiments of the first aspect of the present application, after the step of generating an interrupt instruction according to the data information, and storing the data information in sequence at corresponding positions in the cache circular queue according to the serial port identifier of each of the data information, a preset priority sequence and a write pointer of the cache circular queue, the method further includes:

[0033] At a preset second time interval, counting a fourth total amount of data received from each serial port;

[0034] Calculate the sum of the fourth data amounts corresponding to all serial ports to obtain the fifth data amount;

[0035] When the ratio of the fourth total amount of data to the fifth total amount of data of one of the serial ports is less than a preset first threshold, the priority of the serial port is downgraded and the priority sequence is adjusted;

[0036] When the ratio of the fourth total amount of data to the fifth total amount of data of one of the serial ports is greater than a preset second threshold, the priority of the serial port is upgraded and the priority sequence is adjusted.

[0037] According to some embodiments of the first aspect of the present application, storing the data information in sequence at corresponding positions in the cache circular queue according to the serial port identifier of each of the data information, the preset priority sequence and the write pointer of the cache circular queue includes:

[0038] Get the preset verification algorithm;

[0039] According to the verification algorithm, generating a first verification value related to the verification algorithm;

[0040] According to the serial port identifier of each data information, the preset priority sequence and the write pointer of the cache circular queue, the data information and the corresponding first check value are sequentially stored in the corresponding positions of the cache circular queue;

[0041] Correspondingly, taking out the data information from a corresponding position in the cache circular queue according to the read pointer of the cache circular queue and performing data processing on the data information includes:

[0042] According to the read pointer of the cache circular queue, taking out the data information and the corresponding second check value from the corresponding position in the cache circular queue;

[0043] When the first verification value is consistent with the second verification value, data processing is performed on the data information.

[0044] According to some embodiments of the first aspect of the present application, after the step of taking out the data information and the corresponding second check value from the corresponding position in the cache circular queue according to the read pointer of the cache circular queue, the step further includes:

[0045] When the first check value is inconsistent with the second check value, sending a resend instruction to the corresponding serial port according to the serial port identifier of the data information, and recording the accumulated number of failures of the corresponding serial port;

[0046] When the accumulated failure times corresponding to the first serial port in the serial port group exceeds a preset times threshold, the standby serial port in the serial port group is started to replace the first serial port, or the reception of data information sent by the first serial port is stopped.

[0047] In a second aspect, the present application further provides an electronic device, including:

[0048] at least one memory;

[0049] at least one processor;

[0050] at least one program;

[0051] The program is stored in the memory, and the processor executes at least one of the programs to implement the master control multi-serial port concurrent collaborative communication method as described in any one of the embodiments of the first aspect.

[0052] In a third aspect, the present application further provides a computer-readable storage medium, which stores a computer-executable signal, and the computer-executable signal is used to execute the master control multi-serial port concurrent collaborative communication method as described in any embodiment of the first aspect.

[0053] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:

[0055] Figure 1 A flowchart of the master control multi-serial port concurrent collaborative communication method provided in this application;

[0056] Figure 2 For this application Figure 1 Flow chart about step S120;

[0057] Figure 3 For this application Figure 2 Regarding the flowchart after step S230;

[0058] Figure 4 For this application Figure 3 Flow chart about step S350;

[0059] Figure 5 For this application Figure 1 Flow chart about step S140;

[0060] Figure 6 For this application Figure 1 Regarding the flowchart after step S140;

[0061] Figure 7 For this application Figure 1 Flowchart about step S140 and step S150;

[0062] Figure 8 For this application Figure 7 Regarding the flowchart at step S730. DETAILED DESCRIPTION

[0063] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be understood as limiting the present application.

[0064] In the description of the present application, it should be understood that descriptions involving orientation, such as up, down, front, back, left, right, etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.

[0065] In the description of this application, if there is a description of first or second, it is only for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.

[0066] In the description of this application, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in this application based on the specific content of the technical solution.

[0067] In modern society, the fields of industrial automation and intelligent Internet of Things are booming, and it is very common for equipment to integrate multiple serial ports to connect different peripherals and work together. On industrial production lines, the main control equipment needs to communicate with a large number of sensors and actuators via serial ports to monitor and control production; in smart buildings, the central control needs to connect to a variety of environmental monitoring equipment to maintain a good condition in the building.

[0068] However, traditional serial communication solutions have serious defects when multiple serial ports communicate concurrently. Different serial ports are connected to devices with different functions, and the data generation rates vary greatly. Sometimes massive amounts of data pour in instantly, but the conventional sequential processing mode cannot keep up with the pace. The serial port buffer quickly becomes congested. Once it overflows, the data is at risk of being lost, resulting in the loss of key information, which seriously affects production safety and system stability.

[0069] Based on this, the present application provides a master control multi-serial port concurrent collaborative communication method, an electronic device and a storage medium to solve the above-mentioned technical problems. The technical solutions provided by the present application are described in detail one by one below.

[0070] First, refer to Figure 1 The present application provides a master control multi-serial port concurrent collaborative communication method, which may include but is not limited to the following steps:

[0071] Step S110: Obtain serial port communication speed and data processing speed;

[0072] Step S120: constructing a cache circular queue according to the serial port communication speed and the data processing speed;

[0073] Step S130: Acquire at least one data message transmitted from the serial port group; wherein the data message includes a corresponding serial port identifier;

[0074] Step S140: generating an interrupt instruction according to the data information, and storing the data information in a corresponding position in the cache circular queue in sequence according to the serial port identifier of each data information, the preset priority sequence and the write pointer of the cache circular queue; wherein the priority sequence is used to characterize the processing priority of each serial port in the serial port group, and the interrupt instruction is used to interrupt the task currently being executed;

[0075] Step S150: according to the read pointer of the cache circular queue, the data information is taken out from the corresponding position in the cache circular queue, and data processing is performed on the data information.

[0076] In step S110 to step S150, first, by detecting and analyzing the hardware parameters of each serial port and the data transmission situation during actual operation, the average serial port communication speed of the serial port group is accurately obtained. At the same time, the processor performance of the main control device, the load of other currently running tasks, etc. are evaluated, and the data processing speed is comprehensively calculated. According to the obtained serial port communication speed and data processing speed, the length, capacity and other parameters of the cache circular queue are determined according to certain rules and algorithms, and a suitable cache circular queue structure is created. Each serial port is always in a state of listening to the incoming data from the outside world. Once the data is received, it will record which serial port the data comes from, and completely capture the data information. When the serial port receives the data information, the hardware immediately triggers the interrupt mechanism to generate an interrupt instruction, which is transmitted to the main control processor to suspend the non-critical tasks being executed, give priority to responding to the reception and cache operation of the data information, and then find the preset priority sequence according to the serial port identifier carried by the data information, judge the priority of the serial port data, and give priority to ensuring that the high-priority data information is stored in the corresponding position of the cache circular queue according to the write pointer indication. Subsequently, the system will extract the data information in sequence according to the read pointer of the cache circular queue, and perform corresponding data processing on the data information. In this application, the constructed cache circular queue acts as a data "transfer station", which can flexibly temporarily store the received data according to the different communication speeds of each serial port and the data processing speed of the system, avoiding the direct buffer overflow and data loss caused by the instantaneous influx of a large amount of data into some serial ports, thereby improving the reliability of data transmission. At the same time, the preset priority sequence can distinguish the importance and urgency of different serial port data, and can ensure that high-priority data is first stored in the cache circular queue, and can also be taken out and processed first later, avoiding high-priority data from waiting for a long time due to conventional sequential processing, and being "flooded" by a large amount of low-priority data, ensuring the timeliness of important data.

[0077] It should be noted that in step S140, when the serial port receives data, the hardware immediately triggers the interrupt mechanism to generate an interrupt instruction, which is passed to the main control processor to suspend the non-critical tasks being executed and give priority to responding to the reception and cache operations of the data. Then, according to the serial port identifier carried by the data, the preset priority sequence is searched to determine the priority of the serial port data. If new data arrives at a high-priority serial port, even if the current write pointer is processing the data storage operation of a low-priority serial port, the low-priority operation will be suspended, and the high-priority data will be stored in the corresponding position of the cache circular queue according to the write pointer indication. Before storing the data, a check value can be added to the data to ensure data integrity. If the queue is almost full, some low-priority data will be cleared according to the priority strategy to make room to ensure that new data can be stored smoothly.

[0078] Reference Figure 2 It is understandable that step S120 may include but is not limited to the following steps:

[0079] Step S210: constructing an initial circular queue according to the serial port communication speed and the data processing speed;

[0080] Step S220: obtaining a preset redundancy ratio;

[0081] Step S230: adjusting the initial circular queue according to the redundancy ratio to obtain a cache circular queue.

[0082] In step S210 to step S230, the rate of data generation and transmission is not always stable. At certain specific times or scenarios, a large amount of data may instantly flow into the serial port, far exceeding the average data flow. The system will pre-set a redundancy ratio, which is often obtained through a large number of preliminary tests, in-depth analysis of the equipment's past operating data, and combined with industry experience. For example, in industrial production scenarios where data flow fluctuates greatly and electromagnetic interference occurs frequently, the redundancy ratio may be set at 20% to 30% to prevent sudden situations from causing a large influx of data; while in a relatively stable office automation environment, the redundancy ratio may only need to be maintained at around 10%. After obtaining the redundancy ratio, the queue adjustment work is immediately carried out, and the queue capacity that needs to be additionally expanded is accurately calculated by multiplication operation, that is, "the capacity required to be expanded = the length of the initial circular queue × the redundancy ratio". According to the results obtained, the storage space of the initial circular queue is flexibly expanded at the memory level, the head and tail pointers are accurately moved to the position that adapts to the new capacity, and the key attributes of the queue such as the capacity identifier and index range are synchronously updated, thereby successfully creating a cache circular queue. Setting the redundancy ratio can reserve a certain amount of cache space to cope with sudden peaks in data traffic, ensuring that all data can be properly cached during peak data traffic periods to avoid data loss. At the same time, the extra space provided by the redundancy ratio can be used as a buffer mechanism. When encountering these problems, it can accommodate possible duplicate data, erroneous data, or additional data that needs to be retransmitted, ensuring stable system operation and reducing the risk of system crashes or errors due to data anomalies.

[0083] Reference Figure 3 It is understandable that after step S230, the following steps may also be included but not limited to:

[0084] Step S310: obtaining a first total amount of data received from each serial port and a second total amount of data taken from the buffer circular queue at intervals of a preset first time length;

[0085] Step S320: Obtaining a third total amount of data according to the first total amount of data corresponding to each serial port;

[0086] Step S330: updating the serial port communication speed according to the first duration and the third data amount;

[0087] Step S340: updating the data processing speed according to the first duration and the second data amount;

[0088] Step S350: adjusting the cache circular queue according to the redundancy ratio, the updated serial port communication speed and the data processing speed.

[0089] In step S310, at every first preset time length, the total amount of first data of the data information received from each serial port is counted. This counting process can be implemented by adding a counter in the data receiving program of each serial port, and whenever a new data block is received, the corresponding counter will increase the size of the data block. At the same time, at the data extraction end of the buffer circular queue, there is also a counter that records the total amount of second data of the data information extracted from the buffer circular queue within the same time length, and this counter will also be accumulated according to the size of the data block extracted each time.

[0090] In step S320 to step S330, the first data amount corresponding to each serial port is summed to obtain the third data amount. Then the third data amount is divided by the first time length to obtain the updated serial port communication speed, which is calculated based on the actual amount of data received in the recent period of time and can more accurately reflect the actual data transmission situation of the current serial port.

[0091] In step S340, similarly, the second total data amount is divided by the first time length to obtain an updated data processing speed. The above steps can reflect the current data processing capability of the system in real time. Considering that factors such as system load and efficiency of the processing algorithm may change over time, such an update can enable the system to have a more accurate grasp of its own data processing speed.

[0092] In step S350, according to the updated serial port communication speed and data processing speed, and the pre-set redundancy ratio, the size and related parameters of the cache circular queue are readjusted according to the method of constructing the cache circular queue mentioned above (i.e., first calculating the initial circular queue length, and then adjusting it considering the redundancy ratio). For example, if the serial port communication speed increases significantly, and the data processing speed does not keep up accordingly, it may be necessary to appropriately expand the capacity of the cache circular queue to avoid data accumulation and loss. In practical applications, the data generation rate of the device connected to the serial port may change due to various reasons (such as device upgrades, changes in working modes, changes in external environments, etc.). At the same time, the processing capacity of the system itself may also change due to other running tasks, hardware status and other factors. By regularly updating the serial port communication speed and data processing speed, and adjusting the cache circular queue accordingly, the system can always maintain a relatively ideal working state. When the data flow increases, appropriately expanding the cache can prevent data loss; and when the data flow decreases or the data processing capacity increases, reasonably reducing the cache can release system resources for other tasks. This dynamic update mechanism enables the system to automatically adapt to changes in data traffic and processing power, effectively avoiding problems caused by mismatches between data traffic and processing power, optimizing the allocation of system resources, and improving the overall performance and stability of the system.

[0093] Reference Figure 4 It is understandable that step S350 may include but is not limited to the following steps:

[0094] Step S410: obtaining an initial queue length according to the cache circular queue;

[0095] Step S420: Calculate the target queue length according to the redundancy ratio, the updated serial port communication speed and the data processing speed;

[0096] Step S430: When the absolute difference between the initial queue length and the target queue length is less than or equal to a preset adjustment threshold, the original cache circular queue is maintained;

[0097] Step S440: When the absolute difference between the initial queue length and the target queue length is greater than the adjustment threshold, the cache circular queue is updated according to the target queue length.

[0098] In step S410 to step S420, first, the initial queue length is determined from the configuration parameters of the cache circular queue or by calculating the size of its current storage area, and the initial queue length is the amount of data that the cache circular queue can accommodate in the current state. According to the updated serial port communication speed and data processing speed, combined with the preset redundancy ratio, the target queue length is calculated, and the target queue length represents the ideal length of the cache circular queue according to the latest system status and redundancy requirements.

[0099] In step S430 to step S440, the absolute difference between the initial queue length and the target queue length is calculated, and the difference is compared with a preset adjustment threshold value. The adjustment threshold value is a preset value used to determine whether the difference is large enough to adjust the cache circular queue. The setting of this value can be comprehensively determined based on factors such as the system's sensitivity to cache changes and the cost of adjusting the cache. If the absolute difference is less than or equal to the adjustment threshold value, it means that the length of the current cache circular queue is not much different from the ideal length, and the original cache circular queue state is maintained without any modification. If the absolute difference is greater than the adjustment threshold value, the cache circular queue needs to be updated according to the target queue length. This may involve the reallocation of memory space, expanding or shrinking the storage area of ​​the cache circular queue to the size corresponding to the target queue length. By setting the adjustment threshold value, frequent adjustment of the cache circular queue due to slight speed changes or calculation errors is avoided. This method can reduce the waste of system resources, because each adjustment of the cache circular queue may involve operations such as memory reallocation and data migration, which consume certain system resources and time. For example, when data traffic and processing speed are relatively stable, the system will not frequently change the size of the cache queue due to some small fluctuations, thereby maintaining efficient operation of the system. At the same time, this dynamic adjustment mechanism can enable the system to better adapt to long-term system changes and external environmental interference. By regularly updating and conditionally adjusting the cache cycle queue, the system can maintain relatively stable performance in these changes, effectively cope with various complex situations, and improve the overall adaptability and stability of the system.

[0100] Reference Figure 5 It is understandable that step S140 may include but is not limited to the following steps:

[0101] Step S510: when new data information is received from the serial port group during the process of storing the data information in the cache circular queue, the corresponding first serial port identifier and second serial port identifier are obtained according to the current data information and the new data information respectively;

[0102] Step S520: obtaining a first priority for the first serial port identifier and a second priority for the second serial port identifier according to the first serial port identifier, the second serial port identifier and the priority sequence;

[0103] Step S530: when the first priority is greater than or equal to the second priority, continue to store the current data information into the cache circular queue according to the write pointer of the cache circular queue;

[0104] Step S540: when the first priority is less than the second priority, the new data information is stored in the cache circular queue according to the write pointer of the cache circular queue, and after the new data information is stored, the previous data information is stored in the cache circular queue.

[0105] In step S510 to step S520, when the system is storing a piece of data information into the cache circular queue, if the serial port group receives new data information, the system will immediately extract the serial port identifier of the data being stored as the first serial port identifier, and the serial port identifier of the newly received data as the second serial port identifier. The system searches for the first priority corresponding to the first serial port identifier and the second priority corresponding to the second serial port identifier according to a preset priority sequence. This priority sequence is pre-set during the system initialization phase based on factors such as the importance of the devices connected to each serial port and the urgency of the data. For example, in an industrial control system, the serial port connected to a safety monitoring device (such as an emergency stop button, a fire alarm, etc.) may be given a higher priority, while the serial port connected to a common status monitoring device (such as a device temperature sensor, when in a non-critical threshold range) may have a lower priority.

[0106] In step S530 to step S540, if the first priority is greater than or equal to the second priority, it means that the data information being stored is at least as important as the newly received data information. At this time, the system will continue to store the data information being stored in the cache circular queue in its entirety according to the current position of the write pointer of the cache circular queue. When the first priority is less than the second priority, it means that the newly received data information is more important. At this time, the system will suspend the storage operation of the current data information, reposition the write pointer of the cache circular queue, and give priority to storing the new data information in the cache circular queue. The system will store the new data in the queue in sequence according to the position of the write pointer and the size of the new data, and the write pointer will also be updated accordingly until all the new data information is stored. After the storage of the new data is completed, the system will re-store the previously interrupted data information according to the position of the write pointer. At this time, the write pointer will point to the next position after the new data is stored, and continue to complete the previously unfinished data storage operation to ensure that all data information can be correctly stored in the cache circular queue according to the priority and order.

[0107] Devices connected to different serial ports have different roles and importance in the entire system. Through this priority judgment mechanism, it can be ensured that high-priority data information can be quickly stored in the cache cycle queue and then processed first. With the above embodiment, in an actual application scenario, such as in a security monitoring system of an intelligent building, if a fire alarm sends an alarm signal (high priority) through a serial port, and at the same time ordinary environmental monitoring data (low priority) is being stored in the cache cycle queue, the system will give priority to processing the fire alarm signal, so that fire fighting measures can be initiated in time to reduce losses.

[0108] Reference Figure 6 It is understandable that after step S140, the following steps may also be included but not limited to:

[0109] Step S610: Counting the fourth total amount of data received from each serial port at intervals of a preset second time length;

[0110] Step S620: Calculate the sum of the fourth data amounts corresponding to all serial ports to obtain the fifth data amount;

[0111] Step S630: when the ratio of the fourth total amount of data to the fifth total amount of data of one of the serial ports is less than a preset first threshold, the priority of the serial port is downgraded and the priority sequence is adjusted;

[0112] Step S640: when the ratio of the fourth total amount of data to the fifth total amount of data of one of the serial ports is greater than a preset second threshold, the priority of the serial port is upgraded and the priority sequence is adjusted.

[0113] In step S610 to step S620, the system pre-sets the second duration, which is usually determined based on a comprehensive consideration of factors such as the approximate cycle of system data flow changes and the frequency of business demand for dynamic data adjustment. After completing the statistics of the fourth total amount of data of each serial port, the fourth total amount of data corresponding to all serial ports is summed up to obtain the fifth total amount of data. Then, for each serial port, the ratio of its fourth total amount of data to the fifth total amount of data is calculated, and this ratio is compared with the preset first threshold and second threshold.

[0114] In step S630 to step S640, when the ratio of the fourth total amount of data to the fifth total amount of data of a certain serial port is less than the preset first threshold, it means that the amount of data received by this serial port in the recent period is too small relative to the amount of data received by the entire system, and the device currently connected to it may be less active or the importance of the data has decreased. At this time, the system will downgrade the priority of the serial port. For example, assuming that the priority is divided into 5 levels, level 1 is the highest and level 5 is the lowest, and the original priority of the serial port is level 3, it will be downgraded to level 4. And adjust the entire priority sequence accordingly, and rearrange the priority order of other serial ports to reflect the change in the position of the serial port after the priority is reduced. On the contrary, when the ratio of the fourth total amount of data to the fifth total amount of data of one of the serial ports is greater than the preset second threshold, it indicates that the amount of data received by this serial port accounts for a large proportion in the system, and the device connected to it may be in a critical operation stage or the urgency and importance of the data have increased. At this time, the system will upgrade the priority of the serial port, for example, from the original level 3 to level 2, and then adjust the priority sequence to ensure that the priority order of each serial port can accurately reflect the current actual situation, so as to facilitate subsequent operations such as storing data in the cache circular queue based on priority.

[0115] In actual multi-serial port application scenarios, the working status of the devices connected to each serial port and the importance of the data generated are not static. Through this mechanism of regular statistics and dynamic adjustment of priorities based on the proportion of data volume, the system can automatically adapt to the dynamic changes of the business, ensure that relevant data is processed in a timely manner, better meet the needs of different stages of the actual business process, avoid allocating cache resources and processing order according to a fixed priority sequence, resulting in resource waste or key data not being processed in a timely manner, and improve the performance of the entire system.

[0116] Reference Figure 7 It is understandable that step S140 may include but is not limited to the following steps:

[0117] Step S710: Obtain a preset verification algorithm;

[0118] Step S720: Generate a first verification value related to the verification algorithm according to the verification algorithm;

[0119] According to the serial port identifier of each data information, the preset priority sequence and the write pointer of the cache circular queue, the data information and the corresponding first check value are sequentially stored in corresponding positions in the cache circular queue.

[0120] Correspondingly, in step S150, the following steps may be included but not limited to:

[0121] Step S730: according to the read pointer of the cache circular queue, taking out the data information and the corresponding second check value from the corresponding position in the cache circular queue;

[0122] Step S740: When the first verification value is consistent with the second verification value, data processing is performed on the data information.

[0123] In step S710 to step S720, a preset check algorithm is first obtained, and this check algorithm can be a cyclic redundancy check, a parity check, etc., which is not limited in this application. According to the obtained check algorithm, the data information to be stored in the cache circular queue is calculated to generate a first check value. After the first check value is generated, the system stores the data information and the corresponding first check value in the corresponding position in the cache circular queue in sequence according to the serial port identifier of each data information, the preset priority sequence and the write pointer of the cache circular queue.

[0124] In step S730 to step S740, when data needs to be processed from the cache circular queue, the data information and the corresponding second check value are taken out from the corresponding position according to the read pointer of the cache circular queue. The read pointer reads the data and the check value one by one from the cache space in a pre-set order to ensure that the reading order of the data is consistent with the storage order. After the data is taken out, the first check value generated when it was previously stored is compared with the second check value taken out now. If the two are consistent, it means that no error occurred during the storage of the data in the cache circular queue, and the system will process the data information at this time.

[0125] By generating and comparing check values ​​when storing and retrieving data, it is possible to effectively detect whether errors occur in the data storage process of the cache circular queue. Whether the data change is caused by hardware failure or software abnormality, as long as the check value is inconsistent, it can be discovered in time. This ensures that only accurate data can enter the subsequent data processing link, avoiding system error decisions or wrong operations caused by erroneous data, and improving the quality of data processing.

[0126] Reference Figure 8 It is understandable that after step S730, the following steps may also be included but not limited to:

[0127] Step S810: When the first check value is inconsistent with the second check value, a resend instruction is sent to the corresponding serial port according to the serial port identifier of the data information, and the accumulated number of failures of the corresponding serial port is recorded;

[0128] Step S820: when the accumulated failure times corresponding to the first serial port in the serial port group exceeds a preset times threshold, the backup serial port in the serial port group is started to replace the first serial port, or the reception of data information sent by the first serial port is stopped.

[0129] In step S810 to step S820, when it is found that the first check value is inconsistent with the second check value, the system will first extract the serial port identifier corresponding to the data information. According to the serial port identifier, the system sends a resend instruction to the corresponding serial port through a pre-set communication protocol and a serial port communication interface. The format and content of this resend instruction are formulated according to the rules agreed upon between the system and the serial port device. For example, in some simple serial port communication protocols, the resend instruction may be a specific byte sequence used to notify the serial port device to resend the previous data. At the same time, the system will record the failure of this verification for the corresponding serial port and add 1 to its cumulative number of failures. This record of the cumulative number of failures is usually stored in a special counter or a field in the system log file to track the data transmission quality of each serial port.

[0130] The system will continuously monitor the cumulative number of failures of each serial port. When the cumulative number of failures corresponding to a serial port (called the first serial port) exceeds the preset number threshold, the system will check whether there is a backup serial port. If there is a backup serial port, the system will start a series of switching processes. If there is no backup serial port, when the cumulative number of failures exceeds the number threshold, the system will stop receiving data information sent by the first serial port. This is a protective measure to prevent the system from continuing to receive data that may be erroneous, thereby affecting the operation of the entire system. The system may record the reason for stopping reception and issue an alarm to the relevant user or management module, prompting the need to repair or inspect the serial port. By sending a resend command to the erroneous serial port, the system has the opportunity to obtain the correct data, thereby correcting the errors and omissions in the data during the transmission process, so as to ensure the accuracy of the data that finally enters the data processing link and avoid system erroneous decisions or operations caused by erroneous data.

[0131] In a second aspect, the present application also provides an electronic device, comprising: at least one memory, at least one processor and at least one program, the program is stored in the memory, and the processor executes one or more programs to implement the above-mentioned master control multi-serial port concurrent collaborative communication method.

[0132] In the electronic device, it is used to execute the concurrent cooperative communication method of the main control multi-serial port. First, by detecting and analyzing the hardware parameters of each serial port and the data transmission situation during actual operation, the average serial port communication speed of the serial port group is accurately obtained. At the same time, the processor performance of the main control device, the load of other currently running tasks, etc. are evaluated, and the data processing speed is comprehensively calculated. According to the obtained serial port communication speed and data processing speed, the length, capacity and other parameters of the cache circular queue are determined according to certain rules and algorithms to create a suitable cache circular queue structure. Each serial port is always in a state of listening to the incoming data from the outside world. Once the data is received, it will record which serial port the data comes from and completely capture the data information. When the serial port receives the data information, the hardware immediately triggers the interrupt mechanism to generate an interrupt instruction, which is transmitted to the main control processor to suspend the non-critical tasks being executed, give priority to responding to the reception and cache operations of the data information, and then find the preset priority sequence according to the serial port identifier carried by the data information, judge the priority of the serial port data, and give priority to ensuring that the high-priority data information is stored in the corresponding position of the cache circular queue according to the write pointer indication. Subsequently, the system will extract the data information in sequence according to the read pointer of the cache circular queue, and perform corresponding data processing on the data information. In this application, the constructed cache circular queue acts as a data "transfer station", which can flexibly temporarily store the received data according to the different communication speeds of each serial port and the data processing speed of the system, avoiding the direct buffer overflow and data loss caused by the instantaneous influx of a large amount of data into some serial ports, thereby improving the reliability of data transmission. At the same time, the preset priority sequence can distinguish the importance and urgency of different serial port data, and can ensure that high-priority data is first stored in the cache circular queue, and can also be taken out and processed first later, avoiding high-priority data from waiting for a long time due to conventional sequential processing, and being "flooded" by a large amount of low-priority data, ensuring the timeliness of important data.

[0133] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required by at least one function; the data storage area may store relevant data of the above-mentioned master control multi-serial port concurrent collaborative communication method, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device or other non-volatile solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processing module via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0134] One or more signals are stored in a memory, and when executed by one or more processors, the master control multi-serial port concurrent cooperative communication method in any of the above method embodiments is executed.

[0135] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. The computer program is executed by one or more processors, enabling the one or more processors to execute the master control multi-serial port concurrent collaborative communication method in the above method embodiment.

[0136] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., may be located in one place, or may be distributed over multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0137] Through the description of the above embodiments, it will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed methods above can be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components can be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, and the computer-readable medium can include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as a computer-readable signal, a data structure, a program module or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassette, magnetic tape, disk storage or other magnetic storage device, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media generally embodies computer readable signals, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

[0138] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0139] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0140] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0141] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0142] 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 application 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, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0143] The embodiments of the present application are described in detail above in conjunction with the accompanying drawings, but the present application is not limited to the above embodiments, and various changes can be made within the knowledge scope of ordinary technicians in the relevant technical field without departing from the purpose of the present application.

Claims

1. A master control multi-serial port concurrent collaborative communication method, characterized in that: include: Get serial port communication speed and data processing speed; Constructing a cache circular queue according to the serial port communication speed and the data processing speed; Acquire at least one data message transmitted from the serial port group; wherein the data message includes a corresponding serial port identifier; Generate an interrupt instruction according to the data information, and store the data information in the corresponding position in the cache circular queue in sequence according to the serial port identifier of each of the data information, the preset priority sequence and the write pointer of the cache circular queue; wherein the priority sequence is used to characterize the processing priority of each serial port in the serial port group, and the interrupt instruction is used to interrupt the task currently being executed; According to the read pointer of the cache circular queue, the data information is taken out from the corresponding position in the cache circular queue, and data processing is performed on the data information.

2. The master control multi-serial port concurrent collaborative communication method according to claim 1, characterized in that: The step of constructing a cache circular queue according to the serial port communication speed and the data processing speed includes: Constructing an initial circular queue according to the serial port communication speed and the data processing speed; Get the preset redundancy ratio; The initial circular queue is adjusted according to the redundancy ratio to obtain a cache circular queue.

3. The master control multi-serial port concurrent collaborative communication method according to claim 2, characterized in that: After the step of adjusting the initial circular queue according to the redundancy ratio to obtain a cache circular queue, the method further includes: At intervals of a preset first time length, obtaining a first total amount of data of the data information received from each serial port, and taking out a second total amount of data of the data information from the buffer circular queue; Obtaining a third total amount of data according to a total amount of first data corresponding to each serial port; updating the serial port communication speed according to the first time length and the third data amount; updating the data processing speed according to the first time length and the second total amount of data; The cache circular queue is adjusted according to the redundancy ratio, the updated serial port communication speed and the data processing speed.

4. The master control multi-serial port concurrent collaborative communication method according to claim 3, characterized in that: The step of adjusting the cache circular queue according to the redundancy ratio, the updated serial port communication speed, and the data processing speed includes: According to the cache circular queue, an initial queue length is obtained; Calculating a target queue length according to the redundancy ratio, the updated serial port communication speed, and the data processing speed; When the absolute difference between the initial queue length and the target queue length is less than or equal to a preset adjustment threshold, maintaining the original cache circular queue; When the absolute difference between the initial queue length and the target queue length is greater than the adjustment threshold, the cache circular queue is updated according to the target queue length.

5. The master control multi-serial port concurrent collaborative communication method according to claim 1, characterized in that: According to the serial port identifier of each piece of data information, the preset priority sequence and the write pointer of the cache circular queue, the data information is sequentially stored in the corresponding position of the cache circular queue, including: When the data information is being stored in the cache circular queue, when new data information is received from the serial port group, the corresponding first serial port identifier and second serial port identifier are obtained according to the current data information and the new data information respectively; According to the first serial port identifier, the second serial port identifier and the priority sequence, obtaining a first priority for the first serial port identifier and a second priority for the second serial port identifier; When the first priority is greater than or equal to the second priority, continuing to store the current data information into the cache circular queue according to the write pointer of the cache circular queue; When the first priority is less than the second priority, the new data information is stored in the cache circular queue according to the write pointer of the cache circular queue, and the previous data information is stored in the cache circular queue after the new data information is stored.

6. The master control multi-serial port concurrent collaborative communication method according to claim 1, characterized in that: After the step of generating an interrupt instruction according to the data information, and storing the data information in the corresponding position in the cache circular queue in sequence according to the serial port identifier of each data information, the preset priority sequence and the write pointer of the cache circular queue, the method further includes: At a preset second time interval, counting a fourth total amount of data received from each serial port; Calculate the sum of the fourth data amounts corresponding to all serial ports to obtain the fifth data amount; When the ratio of the fourth total amount of data to the fifth total amount of data of one of the serial ports is less than a preset first threshold, the priority of the serial port is downgraded and the priority sequence is adjusted; When the ratio of the fourth total amount of data to the fifth total amount of data of one of the serial ports is greater than a preset second threshold, the priority of the serial port is upgraded and the priority sequence is adjusted.

7. The master control multi-serial port concurrent collaborative communication method according to claim 1, characterized in that: According to the serial port identifier of each piece of data information, the preset priority sequence and the write pointer of the cache circular queue, the data information is sequentially stored in the corresponding position of the cache circular queue, including: Get the preset verification algorithm; According to the verification algorithm, generating a first verification value related to the verification algorithm; According to the serial port identifier of each data information, the preset priority sequence and the write pointer of the cache circular queue, the data information and the corresponding first check value are sequentially stored in the corresponding positions of the cache circular queue; Correspondingly, taking out the data information from a corresponding position in the cache circular queue according to the read pointer of the cache circular queue and performing data processing on the data information includes: According to the read pointer of the cache circular queue, taking out the data information and the corresponding second check value from the corresponding position in the cache circular queue; When the first verification value is consistent with the second verification value, data processing is performed on the data information.

8. The master control multi-serial port concurrent collaborative communication method according to claim 7, characterized in that: After the step of taking out the data information and the corresponding second check value from the corresponding position in the cache circular queue according to the read pointer of the cache circular queue, the method further includes: When the first check value is inconsistent with the second check value, sending a resend instruction to the corresponding serial port according to the serial port identifier of the data information, and recording the accumulated number of failures of the corresponding serial port; When the accumulated failure times corresponding to the first serial port in the serial port group exceeds a preset times threshold, the standby serial port in the serial port group is started to replace the first serial port, or the reception of data information sent by the first serial port is stopped.

9. An electronic device, characterized in that: include: at least one memory; at least one processor; at least one program; The program is stored in the memory, and the processor executes at least one of the programs to implement the master control multi-serial port concurrent collaborative communication method as described in any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer-executable signal, and the computer-executable signal is used to execute the master control multi-serial port concurrent collaborative communication method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Merging transmission method, system and device for multiple serial interfaces and medium

    CN113114331A

  • Management method for high-concurrency multi-serial-port communication

    CN117453606A

  • Method for dynamic regulating serial transmission buffer area size

    CN1773476A

  • Optimization system for doubled i / O buffer length

    JP1997062483A

Cited By

  • Method for realizing IO (Input / Output) equipment data distribution by Internet of Things gateway and Internet of Things gateway

    CN121509148A

  • Embedded device communication scheduling method and system based on multi-serial port collaboration

    CN122195621A