Multi-serial port management method of interlocking equipment

Through the main thread, control thread and monitoring and analysis thread of the multi-serial port management module, communication interruptions and configuration conflicts caused by serial port exceptions of the interlocking device are solved, and efficient serial port management is achieved without restarting, improving work efficiency and read and write efficiency.

CN120429259APending Publication Date: 2025-08-05CASCO SIGNAL LTD

Patent Information

Application Number
CN202510500587.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-21
Publication Date
2025-08-05

AI Technical Summary

Technical Problem

Existing interlocking devices need to be restarted when the serial port is abnormal, resulting in communication interruption and low working efficiency. The serial port configurations of multiple external systems are prone to conflict, affecting operation and testing efficiency.

Method used

It adopts a multi-serial port management module, including the main thread, control thread and monitoring and analysis thread, manages the serial port through a non-blocking method, automatically closes the abnormal serial port and automatically opens after the exception is cleared, realizing centralized configuration management and real-time monitoring of the serial port.

Benefits of technology

The serial port exception can be handled without restarting the interlocking device, which improves work efficiency, reduces the probability of configuration conflicts, and ensures the read and write efficiency of external systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120429259A_ABST
    Figure CN120429259A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-serial-port management method for interlocking equipment. The method comprises the following steps: creating a main thread, a plurality of control threads and a monitoring analysis thread by utilizing a multi-serial-port management module; the main thread reads a configuration file and controls starting, closing and configuration updating of the multiple control threads and the monitoring analysis threads; each control thread controls a serial port on the interlocking equipment to perform data transmission with a corresponding external interface according to the configuration file, closes the serial port when the serial port is abnormal, and opens the serial port after the abnormality is cleared; and the monitoring analysis thread records the state of the serial port according to the configuration file and counts the total communication data amount and rate of each serial port. When the serial port is abnormal, the interlocking equipment does not need to be restarted like the prior art, so that the operation of the interlocking equipment is not influenced, and the working efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of rail transportation technology, and in particular to a multi-serial port management method for an interlocking device. Background Art

[0002] In national railway and urban rail transit stations, to ensure network isolation, the interlocking devices in the computer interlocking system usually use serial ports to communicate with external systems. For example, the interlocking operating machine uses serial ports to communicate with the Centralized Traffic Control (CTC) dispatching system, the Shunting Train Protecting (STP) system, and the vehicle base integrated automation system; the interlocking maintenance machine uses serial ports to communicate with the signal monitoring system.

[0003] Due to the wide application of serial ports, it is often the case that a certain interlocking device uses more than two serial ports at the same time to communicate with the same external system. Interlocking devices are usually provided with an external interface corresponding to the external system. The external interface and the serial port are based on the same external system, and the external interface and the serial port exchange data. The software of existing interlocking devices (such as interlocking operating machine software, interlocking maintenance machine software, etc., hereinafter referred to as interlocking software) are independent of each other in the management of each external interface; specifically, the interlocking software usually performs operations such as reading external interface configuration, opening serial ports, sending and receiving serial port data, and closing serial ports for each external interface. The implementation of this external interface function uses a method of directly operating a specific serial port, and its serial port operation is sequential and blocking. At present, the following defects and difficulties exist in the prior art:

[0004] 1. When a hardware failure occurs in the serial port channel corresponding to an external interface (i.e., the communication path between the serial port and the external system for data transmission) and a new serial port channel is required, the interlocking device must be restarted before the external interface can re-read the configuration information and open the new serial port. This restart method will cause communication interruption with other serial ports, external interfaces, and network interface interfaces on the interlocking device, affecting the operation of the interlocking device.

[0005] 2. During the testing or on-site debugging of the interlocking software, if the virtual serial port or serial port card is installed or replaced after the interlocking device is started, the corresponding external interface must also be restarted after the interlocking device to reopen the serial port, which seriously affects work efficiency.

[0006] 3. The serial port configurations corresponding to multiple external systems are separate, which can easily lead to configuration conflicts on the same serial port and increase the time to troubleshoot the problem.

[0007] 4. When the external system reads and writes data to the corresponding serial port, if no data can be read, the thread will be blocked for a certain period of time (e.g., 100 milliseconds), resulting in a delay in writing data. Currently, stations equipped with computer interlocking systems are becoming larger and larger, and this blocking method affects the reading and writing efficiency of the external system. Summary of the Invention

[0008] The purpose of the present invention is to provide a multi-serial port management method for an interlocking device, which does not require restarting the interlocking device as in the prior art when an abnormality occurs in the serial port, thereby not affecting the operation of the interlocking device and improving work efficiency.

[0009] In order to achieve the above object, the present invention is implemented through the following technical solutions:

[0010] A multi-serial port management method for an interlocking device is implemented by a multi-serial port management module, wherein the multi-serial port management module is provided on the interlocking device; the multi-serial port management method for an interlocking device comprises:

[0011] Utilize the multi-serial port management module to create a main thread, multiple control threads and a monitoring and analysis thread;

[0012] The main thread reads the configuration file and controls the startup, shutdown and configuration update of the multiple control threads and the monitoring and analysis threads;

[0013] Each of the control threads controls the serial port on the interlocking device to transmit data with the corresponding external interface according to the configuration file, and closes the serial port when an abnormality occurs in the serial port and opens the serial port after the abnormality is cleared;

[0014] The monitoring and analysis thread records the status of the serial ports according to the configuration file and counts the total amount and rate of communication data of each serial port.

[0015] Optionally, the configuration file includes: a control thread configuration block and a monitoring and analysis thread configuration block;

[0016] The control thread configuration block includes: the total number of control threads, a list of serial ports managed by each control thread, and setting information of each serial port; the setting information of each serial port includes the name of the external interface corresponding to the serial port, serial port address, baud rate, data bits, stop bits, parity check, flow control, and transmission direction;

[0017] The monitoring and analysis thread configuration block includes: the initialization state and monitoring period of the monitoring and analysis thread; and the initialization state of the monitoring and analysis thread includes initialization start and initialization not start.

[0018] Optionally, the initialization state of the monitoring and analysis thread is initialization startup, the main thread starts the monitoring and analysis thread and sends the monitoring and analysis thread configuration block to the started monitoring and analysis thread;

[0019] The main thread starts a corresponding number of the control threads according to the control thread configuration block and sends the control thread configuration block to the started control threads.

[0020] Optionally, the status of the serial port includes an initial state, an opening state, a readable and writable state, an abnormal state, a closing state, and a closed state.

[0021] Optionally, the step of each control thread controlling the serial port on the interlocking device to transmit data with the corresponding external interface according to the configuration file includes:

[0022] When the control thread starts, according to the serial port list it manages, it sets the state of the serial port to the initial state and creates a sending queue and a receiving queue of the external interface corresponding to the serial port;

[0023] The control thread periodically traverses the serial ports in the serial port list managed by it according to a first preset time interval to obtain the status of the serial ports;

[0024] If the state of the serial port is the initial state, the control thread performs an operation of opening the serial port in a non-blocking manner according to the setting information of the serial port, and changes the state of the serial port to an opening state;

[0025] If the serial port status is in the opening state, the control thread obtains the opening result of the serial port; if the serial port opening result is in the opening state, the serial port status is maintained in the opening state; if the serial port opening result is successfully opened, the serial port status is changed to a readable and writable state;

[0026] If the serial port is in a readable and writable state, the control thread determines whether the last data sending operation of the serial port to the external system has been completed; if the last data sending operation of the serial port has not been completed and no exception information is returned, the control thread does not perform any operation; if the last data sending operation of the serial port has been completed, the control thread determines whether there is data to be transmitted in the sending queue of the external interface corresponding to the serial port; if there is data to be transmitted, the control thread reads the data to be transmitted from the sending queue and initiates a new data sending operation to the serial port in a non-blocking manner;

[0027] If the status of the serial port is readable and writable, the control thread also determines whether the last data reception operation of the serial port to the external system has been completed; if the last data reception operation of the serial port has not been completed and no exception information is returned, the control thread does not perform the operation; if the last data reception operation of the serial port has been completed, the control thread writes the data received by the serial port from the external system into the receive queue of the external interface corresponding to the serial port, and the control thread initiates a new data reception operation to the serial port in a non-blocking manner.

[0028] Optionally, the step of each control thread controlling the serial port on the interlocking device to transmit data with the corresponding external interface according to the configuration file includes:

[0029] When the serial port is in a readable and writable state, if the last data sending operation of the serial port is not completed and returns an exception message, and / or the last data receiving operation of the serial port is not completed and returns an exception message, the control thread changes the serial port state to an abnormal state;

[0030] If the state of the serial port is an abnormal state, the control thread determines whether the abnormality of the serial port is a self-recoverable abnormality based on the returned abnormal information; if the abnormality of the serial port is a self-recoverable abnormality, the control thread clears the abnormality and changes the state of the serial port to a readable and writable state after the abnormality is cleared; if the abnormality of the serial port is an unrecoverable abnormality, the control thread executes the operation of closing the serial port in a non-blocking manner, clears the sending queue and receiving queue of the external interface corresponding to the serial port, and changes the state of the serial port to a closing state;

[0031] If the serial port status is in the closing state, the control thread obtains the closing result of the serial port; if the closing result of the serial port is in the closing state, the serial port status is maintained in the closing state; if the closing result of the serial port is successfully closed, the serial port status is changed to the closed state and the closing time of the serial port is recorded;

[0032] If the status of the serial port is closed, the control thread calculates the interval between the current time and the closing time of the serial port; if the interval between the current time and the closing time of the serial port reaches a preset duration, the control thread performs an operation of opening the serial port and changes the status of the serial port to an opening state in a non-blocking manner according to the setting information of the serial port; if the interval between the current time and the closing time of the serial port does not reach the preset duration, the status of the serial port is maintained in a closed state.

[0033] Optionally, the self-recoverable exception includes that the sending buffer and / or receiving buffer of the serial port is full, and the sending buffer and / or receiving buffer of the external system is full;

[0034] The non-self-recoverable abnormalities include hardware failure of the serial port channel, installation of a virtual serial port or serial port card, and replacement of a virtual serial port or serial port card.

[0035] Optionally, the multi-serial port management method of the interlocking device further includes:

[0036] Creating a communication record thread using the multi-serial port management module;

[0037] The communication recording thread records log data according to the configuration file.

[0038] Optionally, the configuration file further includes: a communication recording thread configuration block; the communication recording thread configuration block includes the initialization state of the communication recording thread, the file storage path, the file name format, the maximum storage time, and the maximum capacity of each file; and the initialization state of the communication recording thread includes initialization start and initialization not start;

[0039] The initialization state of the communication recording thread is initialization startup, and the main thread starts the communication recording thread and sends the communication recording thread configuration block to the started communication recording thread.

[0040] Optionally, the step of the communication recording thread recording the log data according to the configuration file includes:

[0041] When the communication recording thread is started, the folder for storing the log file is found according to the file storage path; if the folder does not exist, the folder is created; if the folder exists, the folder is opened;

[0042] The communication recording thread calculates the name of the current log file according to the file name format, and finds the current log file in the folder according to the name of the current log file; if the current log file is not found in the folder, creates a new log file and uses it as the current log file;

[0043] The communication recording thread periodically obtains the size of the current log file according to a second preset time interval;

[0044] If the sum of the size of the current log file and the size of the log data to be written is not greater than the maximum capacity of each file, the communication recording thread writes the log data to be written into the current log file;

[0045] If the size of the current log file is smaller than the maximum capacity of each file, and the sum of the size of the current log file and the size of the log data to be written is larger than the maximum capacity of each file, the communication recording thread backs up the current log file and creates and opens a new log file to write the log data to be written into the current log file and the new log file;

[0046] If the size of the current log file is not less than the maximum capacity of each file, the communication recording thread backs up the current log file and creates and opens a new log file to write the log data to be written into the new log file;

[0047] The communication recording thread periodically scans all backup log files according to a third preset time interval to determine whether the storage time of the backup log files exceeds the maximum storage time; if the storage time of the backup log files exceeds the maximum storage time, they are deleted.

[0048] Optionally, when the monitoring and analysis thread is started, all the serial ports installed on the interlocking device are scanned periodically according to the monitoring period to generate a monitoring serial port list;

[0049] If a serial port in the monitored serial port list is managed by the control thread, the status of the serial port is updated; if the status of the serial port is readable and writable or abnormal, the monitoring and analysis thread calculates the total amount and rate of data sent by the serial port to the external system and the total amount and rate of data received from the external system.

[0050] Optionally, the main thread periodically re-reads the configuration file according to a fourth preset time interval, and compares the re-read configuration file with the original configuration file;

[0051] If the content of the control thread configuration block in the re-read configuration file is different from the content of the control thread configuration block in the original configuration file, the main thread starts the corresponding control thread according to the re-read control thread configuration block, and sends the re-read control thread configuration block to the corresponding control thread;

[0052] If the contents of the monitoring and analysis thread configuration block in the re-read configuration file are different from the contents of the monitoring and analysis thread configuration block in the original configuration file, the main thread starts or shuts down the monitoring and analysis thread according to the re-read monitoring and analysis thread configuration block, and sends the re-read monitoring and analysis thread configuration block to the started monitoring and analysis thread;

[0053] If the contents of the communication recording thread configuration block in the reread configuration file are different from those in the original configuration file, the main thread starts or shuts down the communication recording thread according to the reread communication recording thread configuration block, and sends the reread communication recording thread configuration block to the started communication recording thread.

[0054] Optionally, after receiving the re-read control thread configuration block, the control thread compares it with the original control thread configuration block and replaces it;

[0055] If a new serial port is added in the re-read control thread configuration block, the control thread sets the state of the newly added serial port to an initial state, and creates a sending queue and a receiving queue of an external interface corresponding to the newly added serial port;

[0056] If the serial port is deleted in the re-read control thread configuration block, the control thread executes the operation of closing the deleted serial port in a non-blocking manner, and clears the sending queue and receiving queue of the external interface corresponding to the deleted serial port;

[0057] If the setting information of the serial port in the re-read control thread configuration block changes, the control thread executes the operation of closing the corresponding serial port in a non-blocking manner and sets the state of the corresponding serial port to a closing state.

[0058] Compared with the prior art, the present invention has at least one of the following advantages:

[0059] The present invention provides a multi-serial port management method for an interlocking device. When a hardware failure occurs in a serial port channel corresponding to a certain external interface, resulting in an abnormality in the serial port, a control thread created by a multi-serial port management module automatically closes the abnormal serial port and automatically opens the serial port after the abnormality is cleared. There is no need to restart the interlocking device as in the prior art, and the operation of the interlocking device is not affected.

[0060] According to the present invention, during the testing or on-site debugging stage of the interlocking software, when a virtual serial port or a serial port card is installed or replaced after the interlocking device is started, causing a serial port abnormality, the control thread created by the multi-serial port management module will automatically close the abnormal serial port and automatically open the serial port after the abnormality is cleared, without the need to restart the interlocking device as in the prior art, thereby improving work efficiency.

[0061] In the present invention, the configuration of the serial port is centrally managed through the main thread, thereby reducing the probability of configuration conflicts; and according to the real-time monitoring results of the monitoring and analysis thread, the serial port conflict problem is conveniently checked.

[0062] The control thread in the present invention adopts a non-blocking strategy for all serial port operations (including opening, closing and data transmission), uses multiple control threads for concurrent processing, maximizes the read and write capabilities of the serial port, and thus ensures the read and write efficiency of the external system. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] Figure 1 This is a flow chart of a multi-serial port management method for an interlocking device provided by one embodiment of the present invention;

[0064] Figure 2 The diagram is a schematic diagram of a serial port of an interlocking device provided by an embodiment of the present invention transmitting data with an external interface through a multi-serial port management module. DETAILED DESCRIPTION

[0065] The following is a further detailed description of a multi-serial port management method for an interlocking device proposed by the present invention in conjunction with the accompanying drawings and specific embodiments. According to the following description, the advantages and features of the present invention will be clearer. It should be noted that the drawings are in a very simplified form and use non-precise proportions, which are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention. In order to make the purposes, features and advantages of the present invention more obvious and easy to understand, please refer to the accompanying drawings. It should be noted that the structures, proportions, sizes, etc. illustrated in the drawings of this specification are only used to match the contents disclosed in the specification, so that people familiar with this technology can understand and read them, and are not used to limit the conditions for the implementation of the present invention, so they have no technical significance. Any modification of the structure, change in the proportional relationship or adjustment of the size should still fall within the scope of the technical content disclosed by the present invention without affecting the efficacy and purpose that can be achieved by the present invention.

[0066] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0067] Combined with attachment Figures 1-2 As shown, this embodiment provides a multi-serial port management method for an interlocking device, which is composed of a multi-serial port management module (such as Figure 2The multi-serial port management module is provided on the interlocking device. Specifically, the interlocking device is a device in a computer interlocking system, such as an interlocking operation machine and an interlocking maintenance machine. The interlocking device is provided with a communication interface with an external system (such as Figure 2 Serial port for communication between external system 1 and external system 3 (e.g. Figure 2 Serial port 1 to serial port 5 in the system), and also has external interfaces corresponding to external systems (such as Figure 2 External interface 1-external interface 3) in the interlocking device, that is, the external interface and the serial port correspond to the same external system; wherein the external interface is a logical interface, and the external interface and the serial port exchange data. For example, the upper-layer application sends the data to be sent to a certain external system to the serial port through the corresponding external interface, and then sends it to the external system through the serial port; for another example, the serial port sends the data received from a certain external system to the external interface corresponding to the external system, and then sends it to the upper-layer application through the external interface. More specifically, the interlocking device is also provided with an external interface module for managing the external interface on the interlocking device. Optionally, the external interface module is embedded in the software of the interlocking device (hereinafter referred to as the interlocking software); the interlocking software is provided on the interlocking device and is used to manage the serial port and external interface of the interlocking device, such as the interlocking operation machine software and the interlocking maintenance machine software.

[0068] In this embodiment, the multi-serial port management module is located between the external interface module and the serial port, and the serial port exchanges data with the external interface through the multi-serial port management module. The multi-serial port management module has the following functions: centralized management of serial port configuration; control of serial port opening, closing, data reception, and data transmission; serial port discovery; recording of serial port communications; and monitoring and analysis of serial port activity. Optionally, the multi-serial port management module is embedded in the interlocking software, but the present invention is not limited thereto.

[0069] like Figure 1 As shown, the multi-serial port management method of the interlocking device includes: step S1, using the multi-serial port management module to create a main thread, multiple control threads and a monitoring and analysis thread; wherein, the main thread is the only thread. Step S2, the main thread reads the configuration file, and controls the startup, shutdown and configuration update of the multiple control threads and the monitoring and analysis threads; it can be understood that the configuration file is pre-stored in the interlocking device. Step S3, each of the control threads controls the serial port on the interlocking device to transmit data with the corresponding external interface according to the configuration file, and closes the serial port when an abnormality occurs in the serial port and opens the serial port after the abnormality is cleared. Step S4, the monitoring and analysis thread records the status of the serial port according to the configuration file and counts the total amount and rate of communication data of each serial port.

[0070] In this embodiment, when an abnormality occurs in the serial port, such as a hardware failure of the serial port channel corresponding to a certain external interface, or a serial port abnormality caused by installing or replacing a virtual serial port or serial port card after the interlocking device is started during the testing or on-site debugging of the interlocking software, the control thread will automatically close the abnormal serial port and automatically open the serial port after the abnormality is cleared, without the need to restart the interlocking device as in the prior art. This ensures that the operation of the interlocking device is not affected and improves work efficiency. In addition, in this embodiment, the main thread reads the configuration file to achieve centralized management of the serial port configuration, thereby reducing the probability of configuration conflicts; and based on the real-time monitoring results of the monitoring and analysis thread, it is convenient to troubleshoot serial port conflicts.

[0071] Specifically, the configuration file includes: a control thread configuration block and a monitoring and analysis thread configuration block. The monitoring and analysis thread configuration block includes: the initialization state and monitoring cycle of the monitoring and analysis thread; and the initialization state of the monitoring and analysis thread includes initialization start and initialization not start.

[0072] The control thread configuration block includes: the total number of control threads, a list of serial ports managed by each control thread, and the setting information of each serial port. Optionally, the number of serial ports managed by each control thread can be one or more. The setting information of each serial port includes the name of the external interface corresponding to the serial port, serial port address, baud rate, data bits, stop bits, parity, flow control, and transmission direction; and the control thread controls the serial port on the interlocking device to transmit data with the corresponding external interface according to the setting information of the serial port. Figure 2 As shown, the total number of control threads is 2; the serial port list managed by control thread 1 includes serial port 1, serial port 2, and serial port 3, and the serial port list managed by control thread 2 includes serial port 4 and serial port 5. Specifically, serial port 1 and serial port 2 communicate with external system 1, external interface 1 corresponds to external system 1, and serial port 1 and serial port 2 exchange data with the corresponding external interface 1; serial port 3 and serial port 4 communicate with external system 2, external interface 2 corresponds to external system 2, and serial port 3 and serial port 4 exchange data with the corresponding external interface 2; serial port 5 communicates with external system 3, external interface 3 corresponds to external system 3, and serial port 5 exchanges data with the corresponding external interface 3, but the present invention is not limited to this.

[0073] In some embodiments, in step S1, the multi-serial port management module is further used to create a communication logging thread. In step S2, the main thread further controls the startup, shutdown, and configuration update of the communication logging thread. The multi-serial port management method for an interlocking device further includes: the communication logging thread recording log data according to the configuration file.

[0074] Specifically, the configuration file also includes: a communication recording thread configuration block; the communication recording thread configuration block includes the initialization status of the communication recording thread, file storage path, file name format, maximum storage time, and maximum capacity of each file; and the initialization status of the communication recording thread includes initialization start and initialization not start.

[0075] Specifically, when the interlocking software is started, the main module of the interlocking software will synchronously start the external interface module and the multi-serial port management module. After startup, the multi-serial port management module creates the main thread, the control thread, the communication recording thread, and the monitoring and analysis thread. In step S2, the main thread created by the multi-serial port management module reads the configuration file. If the initialization state of the communication recording thread in the configuration file is "initialization startup," the main thread starts the communication recording thread and sends the communication recording thread configuration block to the started communication recording thread; otherwise, the communication recording thread is not started. If the initialization state of the monitoring and analysis thread in the configuration file is "initialization startup," the main thread starts the monitoring and analysis thread and sends the monitoring and analysis thread configuration block to the started monitoring and analysis thread; otherwise, the monitoring and analysis thread is not started. Furthermore, after the main thread sequentially starts or stops the communication recording thread and the monitoring and analysis thread, it also starts a corresponding number of control threads based on the control thread configuration block and sends the control thread configuration block to the started control thread. Optionally, the main thread may start one or more control threads.

[0076] In one embodiment, the main thread periodically re-reads the configuration file according to a fourth preset time interval, and compares the re-read configuration file with the original configuration file; optionally, the fourth preset time interval is 1 second.

[0077] It can be understood that if the contents of the control thread configuration block in the re-read configuration file are different from the contents of the control thread configuration block in the original configuration file, the main thread starts the corresponding control thread according to the re-read control thread configuration block, and sends the re-read control thread configuration block to the corresponding control thread, thereby realizing the configuration update of the control thread.

[0078] If the contents of the monitoring and analysis thread configuration block in the reread configuration file are different from the monitoring and analysis thread configuration block in the original configuration file, the main thread starts or shuts down the monitoring and analysis thread according to the reread monitoring and analysis thread configuration block, and sends the reread monitoring and analysis thread configuration block to the started monitoring and analysis thread, thereby realizing the configuration update of the monitoring and analysis thread.

[0079] If the contents of the communication recording thread configuration block in the reread configuration file are different from those in the original configuration file, the main thread starts or shuts down the communication recording thread according to the reread communication recording thread configuration block, and sends the reread communication recording thread configuration block to the started communication recording thread, thereby updating the configuration of the communication recording thread.

[0080] In addition, in another embodiment, the main thread can periodically monitor the status (including startup or shutdown) of the communication recording thread, the monitoring and analysis thread, and the control thread according to the fifth preset time interval to ensure that the communication recording thread, the monitoring and analysis thread, and the control thread all operate normally according to the latest configuration file. Optionally, the fifth preset time interval is 150ms to 250ms; preferably, the fifth preset time interval is 200ms, but the present invention is not limited thereto. In another embodiment, the configuration file can also be modified according to user needs so that the main thread can start or shut down the communication recording thread and start or shut down the monitoring and analysis thread at any time according to user needs. For example, when the performance of the interlocking device is insufficient, the communication recording thread and the monitoring and analysis thread can be temporarily shut down by modifying the configuration file.

[0081] It is understood that during its operation, the main thread also collects information such as the status (including startup and shutdown) and configuration changes of the control thread, the communication logging thread, and the monitoring and analysis thread, and sends this collected information as log data to the communication logging thread and the monitoring and analysis thread. Furthermore, when the interlocking software exits, the main thread first shuts down all control threads, then shuts down the monitoring and analysis thread, then shuts down the communication logging thread, and finally shuts down the main thread.

[0082] Specifically, the control thread sets dynamic status information for the serial port it manages; and the status of the serial port includes initial state, opening state, readable and writable state, abnormal state, closing state and closed state. More specifically, step S3 includes:

[0083] Step S31 : When the control thread starts, according to the serial port list it manages, the state of the serial port is set to the initial state and a sending queue and a receiving queue of the external interface corresponding to the serial port are created.

[0084] Step S32: The control thread periodically traverses the serial ports in the serial port list it manages according to a first preset time interval to obtain the status of the serial ports; optionally, the first preset time interval is 15ms to 25ms; preferably, the first preset time interval is 20ms.

[0085] Step S33: When the control thread periodically traverses the serial port in the serial port list it manages, if the state of the serial port is the initial state, the control thread performs an operation of opening the serial port in a non-blocking manner according to the setting information of the serial port, and changes the state of the serial port to an opening state.

[0086] Step S34: When the control thread periodically traverses the serial port in the serial port list it manages, if the status of the serial port is in the opening state, the control thread obtains the opening result of the serial port; if the opening result of the serial port is opening, the status of the serial port is maintained in the opening state; if the opening result of the serial port is successfully opened, the status of the serial port is changed to a readable and writable state.

[0087] Step S35, when the control thread periodically traverses the serial port in the serial port list it manages, if the status of the serial port is a readable and writable state, the control thread determines whether the last data sending operation of the serial port to the external system has been completed; if the last data sending operation of the serial port has been completed, the control thread determines whether there is data to be transmitted in the sending queue of the external interface corresponding to the serial port; if there is data to be transmitted, the control thread reads the data to be transmitted from the sending queue and initiates a new data sending operation to the serial port in a non-blocking manner, so that the serial port initiates a new data sending operation to the external system; if the last data sending operation of the serial port is not completed and no exception information is returned, indicating that the serial port is sending data to the external system, the control thread does not perform any operation; if the last data sending operation of the serial port is not completed and an exception information is returned, the control thread changes the status of the serial port to an abnormal state.

[0088] If the status of the serial port is a readable and writable state, the control thread further determines whether the last data receiving operation of the serial port to the external system has been completed; if the last data receiving operation of the serial port has been completed, the control thread writes the data received by the serial port from the external system into the receiving queue of the external interface corresponding to the serial port, and the control thread initiates a new data receiving operation to the serial port in a non-blocking manner, so that the serial port initiates a new data receiving operation to the external system; if the last data receiving operation of the serial port is not completed and no exception information is returned, indicating that the serial port is receiving data from the external system, the control thread does not perform the operation; if the last data receiving operation of the serial port is not completed and an exception information is returned, the control thread changes the status of the serial port to an abnormal state.

[0089] Step S36, when the control thread periodically traverses the serial port in the serial port list it manages, if the status of the serial port is an abnormal state, the control thread determines whether the abnormality of the serial port is a self-recoverable abnormality based on the returned abnormal information; if the abnormality of the serial port is a self-recoverable abnormality, the control thread clears the abnormality and changes the status of the serial port to a readable and writable state after the abnormality is cleared; if the abnormality of the serial port is a non-self-recoverable abnormality, the control thread uses a non-blocking method to execute the operation of closing the serial port, clears the sending queue and the receiving queue of the external interface corresponding to the serial port, and changes the status of the serial port to a closing state.

[0090] Step S37: When the control thread periodically traverses the serial port in the serial port list it manages, if the status of the serial port is in the closing state, the control thread obtains the closing result of the serial port; if the closing result of the serial port is closing, the status of the serial port is maintained in the closing state; if the closing result of the serial port is successfully closed, the status of the serial port is changed to the closed state and the closing time of the serial port is recorded.

[0091] Step S38: When the control thread periodically traverses the serial port in the serial port list it manages, if the status of the serial port is closed, the control thread calculates the interval between the current time and the closing time of the serial port; if the interval between the current time and the closing time of the serial port reaches a preset duration, the control thread performs the operation of opening the serial port and changes the status of the serial port to opening in a non-blocking manner according to the setting information of the serial port; if the interval between the current time and the closing time of the serial port does not reach the preset duration, the status of the serial port is maintained in the closed state. Optionally, the preset duration is 3s to 8s; preferably, the preset duration is 5s, but the present invention is not limited thereto.

[0092] In this embodiment, in step S36, the self-recoverable exception includes the send buffer and / or receive buffer of the serial port being full, or the send buffer and / or receive buffer of the external system being full; in this case, the serial port or the external system cannot continue to send or receive data, and the control thread clears the exception by quickly writing data to the receive queue of the external interface corresponding to the serial port (in the case where the receive buffer of the serial port or the send buffer of the external system is full) and / or waiting for the external system to read data (in the case where the send buffer of the serial port or the receive buffer of the external system is full). The non-self-recoverable exception includes a hardware failure of the serial port channel (i.e., the communication path for data transmission between the serial port and the external system), the installation of a virtual serial port or serial port card after the interlocking device is started during the testing or on-site debugging of the interlocking software, or the replacement of a virtual serial port or serial port card; in this case, the control thread clears the exception by closing the serial port where the non-self-recoverable exception occurs and clearing the send queue and receive queue of the external interface corresponding to the serial port; and the control thread opens the serial port after the serial port is closed for a preset period of time. It can be seen that in this embodiment, after an abnormality occurs in the serial port, there is no need to restart the interlocking device as in the prior art, so that the operation of the interlocking device is not affected and the work efficiency can be improved.

[0093] In addition, after the control thread periodically receives the re-read control thread configuration block (i.e., the control thread configuration block in the re-read configuration file), it compares and replaces it with the original control thread configuration block (the control thread configuration block in the original configuration file). If a new serial port is added to the re-read control thread configuration block, the control thread sets the state of the newly added serial port to the initial state, and creates a sending queue and a receiving queue of the external interface corresponding to the newly added serial port; if a serial port is deleted from the re-read control thread configuration block, the control thread uses a non-blocking method to execute the operation of closing the deleted serial port, and clears the sending queue and the receiving queue of the external interface corresponding to the deleted serial port; if the setting information of the serial port in the re-read control thread configuration block changes, the control thread uses a non-blocking method to execute the operation of closing the corresponding serial port, and sets the state of the corresponding serial port to the closing state.

[0094] In one embodiment, during the execution of each step (i.e., steps S31 to S38), the control thread also collects information such as the status of the serial port, the status of the send queue and receive queue of the external interface corresponding to the serial port (including queue empty, queue full, occupancy rate, etc.), data sent and received by the serial port, and sends the collected information as log data to the communication recording thread and the monitoring and analysis thread. Optionally, the format of the log data is generally "time + generation thread + type + level + content", but the present invention is not limited to this.

[0095] Specifically, the step of the communication recording thread recording log data according to the configuration file includes: step S51, when the communication recording thread starts, finds the folder for storing log files according to the file storage path; if the folder does not exist, creates the folder; if the folder exists, opens the folder. Step S52, the communication recording thread calculates the name of the current log file according to the file name format, so as to find the current log file in the folder according to the name of the current log file; if the current log file is not found in the folder, creates a new log file and uses it as the current log file. Step S53, the communication recording thread periodically obtains the size of the current log file according to a second preset time interval; optionally, the second preset time interval is 15ms to 25ms; preferably, the second preset time interval is 15ms. Step S54: If the sum of the size of the current log file and the size of the log data to be written is not greater than the maximum capacity of each file, the communication recording thread writes the log data to be written to the current log file; if the size of the current log file is less than the maximum capacity of each file, and the sum of the size of the current log file and the size of the log data to be written is greater than the maximum capacity of each file, the communication recording thread backs up the current log file and creates and opens a new log file to write the log data to be written to the current log file and the new log file; if the size of the current log file is not less than the maximum capacity of each file, the communication recording thread backs up the current log file and creates and opens a new log file to write the log data to be written to the new log file. Step S55: The communication recording thread periodically scans all backed-up log files according to a third preset time interval to determine whether the storage time of the backed-up log files exceeds the maximum storage time; if the storage time of the backed-up log files exceeds the maximum storage time, the backed-up log files are deleted; if the storage time of the backed-up log files does not exceed the maximum storage time, the backed-up log files are retained. Optionally, the third preset time interval is 50s to 70s; preferably, the third preset time interval is 60s, but the present invention is not limited thereto.

[0096] Specifically, step S4 includes: step S41: when the monitoring and analysis thread is started, it periodically scans all serial ports installed on the interlocking device according to the monitoring cycle to generate a list of monitored serial ports; step S42: if a serial port in the list of monitored serial ports is managed by the control thread, the status of the serial port is updated; if the status of the serial port is readable and writable or abnormal, the monitoring and analysis thread calculates the total amount and rate of data sent by the serial port to the external system, as well as the total amount and rate of data received from the external system. Optionally, the monitoring and analysis thread can drive the calculation results to be displayed on a human-computer interface or saved in a log file, but the present invention is not limited to this.

[0097] For example, the content of the configuration file is presented in XML format as follows:

[0098]

[0099]

[0100]

[0101] In the example configuration file in XML format, <serialportmanagementconfig>Is the root element, containing all configuration information. <controlthreads>The element contains the configuration information of the control thread. Each <threadconfig>The sub-element represents a control thread, and its number is the total number of control threads; each <serialport>The sub-element represents a serial port.

[0102] The configuration information for each serial port is contained in a <serialport>The element lists in detail the name, serial port address, baud rate, data bits, stop bits, parity, flow control and transmission direction of the external interface that communicates with the serial port. Among them, the external interface refers to the logical interface on the interlocking device corresponding to the external system, for example, the external system is the centralized dispatching system (CTC) and the wireless shunting locomotive signal and monitoring system (Shunting Train Protecting, STP system).

[0103] <logthread>The element contains configuration information for the communication logging thread, including parameters such as whether to initialize, the file storage path, the file name format, the maximum storage time, and the maximum size of each file. The file name format is a formatted string, where %Y%m%d represents the year, month, and day. Based on this configuration, the communication logging thread will create a log file with the current date, such as serialport_20250108.log.

[0104] <monitoringanalysisthread>The element contains the configuration information of the monitoring and analysis thread, including parameters such as whether to start the initialization and the monitoring period.

[0105] Although the present invention has been described in detail through the above preferred embodiments, it should be understood that the above description is not intended to limit the present invention. After reading the above description, various modifications and substitutions of the present invention will become apparent to those skilled in the art. Therefore, the scope of protection of the present invention should be defined by the appended claims.< / monitoringanalysisthread> < / logthread> < / serialport> < / serialport> < / threadconfig> < / controlthreads> < / serialportmanagementconfig>

Claims

1. A multi-serial port management method for an interlocking device, implemented by a multi-serial port management module, wherein the multi-serial port management module is provided on the interlocking device; characterized in that: The multi-serial port management method of the interlocking device includes: Utilize the multi-serial port management module to create a main thread, multiple control threads and a monitoring and analysis thread; The main thread reads the configuration file and controls the startup, shutdown and configuration update of the multiple control threads and the monitoring and analysis threads; Each of the control threads controls the serial port on the interlocking device to transmit data with the corresponding external interface according to the configuration file, and closes the serial port when an abnormality occurs in the serial port and opens the serial port after the abnormality is cleared; The monitoring and analysis thread records the status of the serial ports according to the configuration file and counts the total amount and rate of communication data of each serial port.

2. The multi-serial port management method for an interlocking device according to claim 1, wherein: The configuration file includes: a control thread configuration block and a monitoring and analysis thread configuration block; The control thread configuration block includes: the total number of control threads, a list of serial ports managed by each control thread, and setting information of each serial port; the setting information of each serial port includes the name of the external interface corresponding to the serial port, serial port address, baud rate, data bits, stop bits, parity check, flow control, and transmission direction; The monitoring and analysis thread configuration block includes: the initialization state and monitoring period of the monitoring and analysis thread; and the initialization state of the monitoring and analysis thread includes initialization start and initialization not start.

3. The multi-serial port management method of an interlocking device according to claim 2, characterized in that: The initialization state of the monitoring and analysis thread is initialization startup, the main thread starts the monitoring and analysis thread and sends the monitoring and analysis thread configuration block to the started monitoring and analysis thread; The main thread starts a corresponding number of the control threads according to the control thread configuration block and sends the control thread configuration block to the started control threads.

4. The multi-serial port management method for an interlocking device according to claim 3, wherein: The states of the serial port include an initial state, an opening state, a readable and writable state, an abnormal state, a closing state, and a closed state.

5. The multi-serial port management method for an interlocking device according to claim 4, characterized in that: The steps of each control thread controlling the serial port on the interlocking device to transmit data with the corresponding external interface according to the configuration file include: When the control thread starts, according to the serial port list it manages, it sets the state of the serial port to the initial state and creates a sending queue and a receiving queue of the external interface corresponding to the serial port; The control thread periodically traverses the serial ports in the serial port list managed by it according to a first preset time interval to obtain the status of the serial ports; If the state of the serial port is the initial state, the control thread performs an operation of opening the serial port in a non-blocking manner according to the setting information of the serial port, and changes the state of the serial port to an opening state; If the serial port status is in the opening state, the control thread obtains the opening result of the serial port; if the serial port opening result is in the opening state, the serial port status is maintained in the opening state; if the serial port opening result is successfully opened, the serial port status is changed to a readable and writable state; If the serial port is in a readable and writable state, the control thread determines whether the last data sending operation of the serial port to the external system has been completed; if the last data sending operation of the serial port has not been completed and no exception information is returned, the control thread does not perform any operation; if the last data sending operation of the serial port has been completed, the control thread determines whether there is data to be transmitted in the sending queue of the external interface corresponding to the serial port; if there is data to be transmitted, the control thread reads the data to be transmitted from the sending queue and initiates a new data sending operation to the serial port in a non-blocking manner; If the status of the serial port is readable and writable, the control thread also determines whether the last data reception operation of the serial port to the external system has been completed; if the last data reception operation of the serial port has not been completed and no exception information is returned, the control thread does not perform the operation; if the last data reception operation of the serial port has been completed, the control thread writes the data received by the serial port from the external system into the receive queue of the external interface corresponding to the serial port, and the control thread initiates a new data reception operation to the serial port in a non-blocking manner.

6. The multi-serial port management method of an interlocking device according to claim 5, characterized in that: The steps of each control thread controlling the serial port on the interlocking device to transmit data with the corresponding external interface according to the configuration file include: When the serial port is in a readable and writable state, if the last data sending operation of the serial port is not completed and returns an exception message, and / or the last data receiving operation of the serial port is not completed and returns an exception message, the control thread changes the serial port state to an abnormal state; If the state of the serial port is an abnormal state, the control thread determines whether the abnormality of the serial port is a self-recoverable abnormality based on the returned abnormal information; if the abnormality of the serial port is a self-recoverable abnormality, the control thread clears the abnormality and changes the state of the serial port to a readable and writable state after the abnormality is cleared; if the abnormality of the serial port is an unrecoverable abnormality, the control thread executes the operation of closing the serial port in a non-blocking manner, clears the sending queue and receiving queue of the external interface corresponding to the serial port, and changes the state of the serial port to a closing state; If the serial port status is in the closing state, the control thread obtains the closing result of the serial port; if the closing result of the serial port is in the closing state, the serial port status is maintained in the closing state; if the closing result of the serial port is successfully closed, the serial port status is changed to the closed state and the closing time of the serial port is recorded; If the status of the serial port is closed, the control thread calculates the interval between the current time and the closing time of the serial port; if the interval between the current time and the closing time of the serial port reaches a preset duration, the control thread performs an operation of opening the serial port and changes the status of the serial port to an opening state in a non-blocking manner according to the setting information of the serial port; if the interval between the current time and the closing time of the serial port does not reach the preset duration, the status of the serial port is maintained in a closed state.

7. The multi-serial port management method of an interlocking device according to claim 6, characterized in that: The self-recoverable exception includes that the sending buffer and / or receiving buffer of the serial port is full, and the sending buffer and / or receiving buffer of the external system is full; The non-self-recoverable abnormalities include hardware failure of the serial port channel, installation of a virtual serial port or serial port card, and replacement of a virtual serial port or serial port card.

8. The multi-serial port management method for an interlocking device according to claim 2, wherein: Also includes: Creating a communication record thread using the multi-serial port management module; The communication recording thread records log data according to the configuration file.

9. The multi-serial port management method for an interlocking device according to claim 8, wherein: The configuration file further includes: a communication record thread configuration block; the communication record thread configuration block includes the initialization state of the communication record thread, file storage path, file name format, maximum storage time, and maximum capacity of each file; and the initialization state of the communication record thread includes initialization start and initialization not start; The initialization state of the communication recording thread is initialization startup, and the main thread starts the communication recording thread and sends the communication recording thread configuration block to the started communication recording thread.

10. The multi-serial port management method of an interlocking device according to claim 9, characterized in that: The step of recording the log data according to the configuration file by the communication recording thread includes: When the communication recording thread is started, the folder for storing the log file is found according to the file storage path; if the folder does not exist, the folder is created; if the folder exists, the folder is opened; The communication recording thread calculates the name of the current log file according to the file name format, and finds the current log file in the folder according to the name of the current log file; if the current log file is not found in the folder, creates a new log file and uses it as the current log file; The communication recording thread periodically obtains the size of the current log file according to a second preset time interval; If the sum of the size of the current log file and the size of the log data to be written is not greater than the maximum capacity of each file, the communication recording thread writes the log data to be written into the current log file; If the size of the current log file is smaller than the maximum capacity of each file, and the sum of the size of the current log file and the size of the log data to be written is larger than the maximum capacity of each file, the communication recording thread backs up the current log file and creates and opens a new log file to write the log data to be written into the current log file and the new log file; If the size of the current log file is not less than the maximum capacity of each file, the communication recording thread backs up the current log file and creates and opens a new log file to write the log data to be written into the new log file; The communication recording thread periodically scans all backup log files according to a third preset time interval to determine whether the storage time of the backup log files exceeds the maximum storage time; if the storage time of the backup log files exceeds the maximum storage time, they are deleted.

11. The multi-serial port management method of an interlocking device according to claim 3, characterized in that: When the monitoring and analysis thread is started, all the serial ports installed on the interlocking device are regularly scanned according to the monitoring cycle to generate a monitoring serial port list; If a serial port in the monitored serial port list is managed by the control thread, update the status of the serial port; If the serial port is in a readable and writable state or an abnormal state, the monitoring and analysis thread calculates the total amount and rate of data sent by the serial port to the external system and the total amount and rate of data received from the external system.

12. The multi-serial port management method of an interlocking device according to claim 9, characterized in that: The main thread periodically re-reads the configuration file according to a fourth preset time interval, and compares the re-read configuration file with the original configuration file; If the content of the control thread configuration block in the re-read configuration file is different from the content of the control thread configuration block in the original configuration file, the main thread starts the corresponding control thread according to the re-read control thread configuration block, and sends the re-read control thread configuration block to the corresponding control thread; If the contents of the monitoring and analysis thread configuration block in the re-read configuration file are different from the contents of the monitoring and analysis thread configuration block in the original configuration file, the main thread starts or shuts down the monitoring and analysis thread according to the re-read monitoring and analysis thread configuration block, and sends the re-read monitoring and analysis thread configuration block to the started monitoring and analysis thread; If the contents of the communication recording thread configuration block in the reread configuration file are different from those in the original configuration file, the main thread starts or shuts down the communication recording thread according to the reread communication recording thread configuration block, and sends the reread communication recording thread configuration block to the started communication recording thread.

13. The multi-serial port management method of an interlocking device according to claim 12, characterized in that: After receiving the re-read control thread configuration block, the control thread compares it with the original control thread configuration block and replaces it; If a new serial port is added in the re-read control thread configuration block, the control thread sets the state of the newly added serial port to an initial state, and creates a sending queue and a receiving queue of an external interface corresponding to the newly added serial port; If the serial port is deleted in the re-read control thread configuration block, the control thread executes the operation of closing the deleted serial port in a non-blocking manner, and clears the sending queue and receiving queue of the external interface corresponding to the deleted serial port; If the setting information of the serial port in the re-read control thread configuration block changes, the control thread executes the operation of closing the corresponding serial port in a non-blocking manner and sets the state of the corresponding serial port to a closing state.

Citation Information

Patent Citations

  • Multiple serial port communication system and method based on thread pool

    CN102929823A

  • Method and device for reading and writing serial data, computer device, and storage medium

    CN108470008A

  • Identity card information remote centralized acquisition system and method

    CN109639763A

  • High-speed data acquisition and storage device of laser gyroscope

    CN111207771A

  • Station train control system and interface method of automatic train monitoring system and interlocking lower computer of station train control system

    CN115257877A

Cited By

  • RS-485 multi-serial port transceiving control method based on domestic single-core CPU

    CN121560807A