A service gateway machine serial communication state monitoring method and system
By monitoring serial port data transmission and reception records at the operating system driver layer, efficient and seamless monitoring of the serial port communication status of the service gateway machine is achieved, solving the problems of high resource consumption and functional coupling in existing technologies, and improving the system's flexibility and stability.
Patent Information
- Application Number
- CN202411326644.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2044-09-23
AI Technical Summary
Existing service gateways cannot directly and efficiently obtain status information when monitoring serial communication status. Furthermore, the monitoring mechanism is tightly coupled with the communication function, resulting in high system resource consumption and limiting flexibility and scalability.
By monitoring the serial port data transmission and reception length records at the operating system driver layer and periodically reading the serial port status information using a timer, the status monitoring and communication functions are decoupled without directly manipulating the serial port resources.
It improves the efficiency and accuracy of serial communication status monitoring, reduces system resource consumption, ensures the application's exclusive access to serial port resources, and enhances the overall stability and reliability of the system.
Smart Images

Figure CN119363625B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of power automation, and in particular to a service gateway machine serial port communication state monitoring method and system. BACKGROUND
[0002] In the wide application of service gateway machines in complex environments such as substations, serial port communication as an important means of interaction with various serial port devices, its stability and effectiveness are crucial to ensure the timeliness and accuracy of data transmission. However, the existing service gateway machines face many challenges in monitoring the serial port communication state. The system commands provided by most service gateway machine operating systems mainly focus on serial port configuration information and attribute queries, making it difficult to directly determine the actual communication status between the serial port and the connected device, such as data flow, connection state, etc. This limitation results in a lack of direct and accurate basis for the service gateway machine to report the serial port communication state to the upper master station.
[0003] To monitor the serial port communication state, the existing technology mainly records the sending and receiving status of the data communication program when sending and receiving data, and reports it to the main program. This approach not only increases the complexity of the data communication program, but also occupies additional system resources, especially when multiple programs reuse the same serial port, which can easily lead to resource competition and conflicts. In addition, the existing technology requires all communication programs to have state recording and reporting functions, otherwise they cannot be used compatibly, which greatly limits the flexibility and scalability of the service gateway machine when integrating third-party communication programs.
[0004] In summary, the existing service gateway machine has obvious shortcomings in serial port communication state monitoring, mainly reflected in the inability to directly and efficiently obtain serial port communication state information, and the close coupling of the monitoring mechanism and the communication function, leading to high system resource occupation. Therefore, exploring a method that can decouple serial port communication state monitoring and communication function is of great significance to improve the working efficiency and reliability of the service gateway machine. SUMMARY
[0005] The purpose of the present application is to provide a service gateway machine serial port communication state monitoring method and system that can determine the serial port communication state without directly operating the serial port resources, and decouple the serial port communication function and the serial port communication state monitoring.
[0006] To solve the above technical problems, the present application provides a service gateway machine serial port communication state monitoring method and system.
[0007] In a first aspect, the present application provides a service gateway machine serial port communication state monitoring method, which comprises the following steps:
[0008] After starting the program, the program is initialized according to a service gateway system configuration file, and serial port device identification information of the service gateway is retrieved according to a received system command;
[0009] The serial port device identification information is parsed, and a unique identification code of each serial port is extracted and stored in a serial port identification code structure array;
[0010] In response to a timer trigger instruction, current transceiving data byte length information of each serial port is obtained by periodically opening and reading data in an operating system driver layer serial port state record file according to the unique identification code of each serial port;
[0011] The current transceiving data byte length information of each serial port is associated and saved into the serial port identification code structure array according to the unique identification code;
[0012] Based on the serial port identification code structure array, current transceiving data byte length information is periodically compared with last recorded transceiving data byte length information to obtain a serial port transceiving state change result;
[0013] A service gateway serial port communication state is judged according to the serial port transceiving state change result, and program state information is updated according to the service gateway serial port communication state.
[0014] In a further embodiment, the step of judging the service gateway serial port communication state according to the serial port transceiving state change result comprises: if the serial port transceiving state change result is that the transceiving data byte length of all serial ports has changed or is within a normal threshold range, it is judged that the service gateway serial port communication state is normal, otherwise it is judged that the service gateway serial port communication state is abnormal.
[0015] In a further embodiment, a monitoring period of the timer is determined according to an actual communication frequency of a serial port communication application program;
[0016] The monitoring period of the timer should be lower than or equal to the actual communication frequency of the serial port communication application program.
[0017] In a further embodiment, the unique identification code of each serial port comprises an address, an interrupt number and a serial port type.
[0018] In a further embodiment, the method further comprises: continuously monitoring an external instruction interface when the timer is not triggered, if a program exit instruction is received, performing resource release and program termination processing, releasing all allocated resources, and safely terminating program running;
[0019] If no program exit instruction is received, the next trigger of the timer is continued to be waited for, and the next round of serial port communication state monitoring is performed.
[0020] In further embodiments, the service gateway system configuration file includes a timer period parameter.
[0021] In a second aspect, the present application provides a service gateway serial port communication state monitoring system, the system comprising:
[0022] an initialization module for initializing the program according to the service gateway system configuration file after starting the program, and retrieving serial port device identification information of the service gateway according to the received system command;
[0023] an identification analysis module for analyzing the serial port device identification information, extracting the unique identification code of each serial port, and storing the unique identification code of each serial port in a serial port identification code structure array;
[0024] a period monitoring module for opening and reading data in the operating system driver layer serial port state record file according to the unique identification code of each serial port in response to a timer trigger instruction, to obtain current transceiving data byte length information of each serial port;
[0025] an identification association module for associating and saving the current transceiving data byte length information of each serial port to the serial port identification code structure array according to the unique identification code;
[0026] a state monitoring module for periodically comparing the current transceiving data byte length information with the last recorded transceiving data byte length information based on the serial port identification code structure array, to obtain serial port transceiving state change results;
[0027] a state judgment module for judging the service gateway serial port communication state according to the serial port transceiving state change results, and updating the program state information according to the service gateway serial port communication state.
[0028] In further embodiments, the judging the service gateway serial port communication state according to the serial port transceiving state change results specifically includes: if the serial port transceiving state change results are that the transceiving data byte length of all serial ports has changed or is within a normal threshold range, then judging that the service gateway serial port communication state is normal, otherwise judging that the service gateway serial port communication state is abnormal.
[0029] In further embodiments, the monitoring period of the timer is determined according to the actual communication frequency of the serial port communication application program;
[0030] The monitoring period of the timer should be lower than or equal to the actual communication frequency of the serial port communication application program.
[0031] In a further embodiment, the system further comprises a program monitoring module for continuously monitoring the external instruction interface when the timer is not triggered, if a program exit instruction is received, performing resource release and program termination processing, releasing all allocated resources, and safely terminating the program running;
[0032] If no program exit instruction is received, the next trigger of the timer is continued to wait, and the next round of serial port communication state monitoring is performed.
[0033] The application provides a serial port communication state monitoring method and system for a service gateway machine, which comprises the following steps: performing program initialization according to a service gateway machine system configuration file, analyzing serial port device identification information of the service gateway machine, extracting a unique identification code of each serial port, and storing the unique identification code of each serial port in a serial port identification code structure array; responding to a timer trigger instruction, regularly opening and reading data in an operating system driver layer serial port state record file according to the unique identification code of each serial port, and obtaining current transceiving data byte length information of each serial port; associating and saving the current transceiving data byte length information of each serial port to the serial port identification code structure array according to the unique identification code; periodically comparing the current transceiving data byte length information with previously recorded transceiving data byte length information based on the serial port identification code structure array, and obtaining serial port transceiving state change results; judging a serial port communication state of the service gateway machine according to the serial port transceiving state change results, and updating program state information according to the serial port communication state of the service gateway machine. Compared with the prior art, the method can realize efficient and real-time monitoring of the serial port communication state of the service gateway machine by directly reading and analyzing data of the operating system driver layer without relying on application program interaction, thereby improving the monitoring efficiency and accuracy, reducing system resource consumption, ensuring the exclusivity of the serial port resources for the application program, decoupling the state monitoring and communication functions, and providing strong support for the operation and maintenance management of the service gateway machine. BRIEF DESCRIPTION OF DRAWINGS
[0034] Figure 1 is a serial port communication state monitoring method flowchart provided by an embodiment of the application;
[0035] Figure 2 is a flowchart of one embodiment of the serial port communication state monitoring method provided by an embodiment of the application;
[0036] Figure 3 is a block diagram of the serial port communication state monitoring system provided by an embodiment of the application. DETAILED DESCRIPTION
[0037] The embodiments of the present application are described below in detail with reference to the accompanying drawings. The embodiments are given only for the purpose of illustration and should not be understood as limiting the present application. The accompanying drawings are used for reference and illustration only and do not constitute a limitation to the scope of patent protection of the present application, because many changes can be made to the present application without departing from the spirit and scope thereof.
[0038] Reference Figure 1 The embodiments of the present application provide a service gateway machine serial port communication state monitoring method and system, which can be applied to a Linux kernel-based thinking system, as shown in FIG. 1, the method comprises the following steps: Figure 1
[0039] S1. After starting the program, program initialization is performed according to the service gateway machine system configuration file, and serial port device identification information of the service gateway machine is retrieved according to the received system command; wherein the service gateway machine system configuration file comprises a timer cycle parameter.
[0040] The traditional serial port communication state detection method often needs to rely on the application program to actively open the serial port to perform read and write operations on the serial port, and to verify the real-time communication state of the serial port by sending and receiving data to the serial port, and to feed back the state information to the management program. The traditional serial port monitoring method needs the application program to repeatedly open the serial port, which not only increases the complexity of the application program, but also causes resource conflicts and unstable serial port state, and additionally occupies a large amount of CPU and IO resources. The present embodiment discards the direct interaction with the application layer, does not need to reopen the serial port or actively perform data transmission and reception, only needs to monitor the data transmission and reception length record of the serial port at the operating system driver layer, and determines the serial port communication state by periodically comparing the data length of the serial port number, thereby achieving efficient monitoring of the serial port communication state. The monitoring of the serial port communication state is completed without increasing the additional functions of the data communication program and occupying the serial port communication resources, the serial port communication state monitoring and the serial port communication function are decoupled. Specifically, the program is configured on the service gateway machine system and is placed in the self-starting item, so that the program automatically runs when the system starts. After the program starts, the present embodiment reads the parameters in the service gateway machine system configuration file to obtain the key configuration information, performs program initialization according to the key configuration information, and the key configuration information includes but is not limited to the timer cycle parameter and the like. At the same time, the present embodiment retrieves the serial port device identification information of all serial ports that need to be monitored on the service gateway machine by using the received system command. The identification code can be a hexadecimal value.
[0041] S2. The serial port device identification information is parsed, the unique identification code of each serial port is extracted, and the unique identification code of each serial port is stored in a serial port identification code structure array.
[0042] The embodiment parses the unique identification code of each serial port from the serial port device identification information, converts the unique identification code into numerical form, and stores it in the serial port identification code structure array for subsequent serial port identification. In this embodiment, the unique identification code of each serial port includes but is not limited to address, interrupt number, and / or serial port type, etc. Those skilled in the art can set the specific content of the unique identification code according to the specific implementation.
[0043] S3. In response to the timer trigger instruction, periodically open and read the data in the serial port state record file in the operating system driver layer according to the unique identification code of each serial port to obtain the current transmit and receive data byte length information of each serial port.
[0044] S4. According to the unique identification code, the current transmit and receive data byte length information of each serial port is associated and saved in the serial port identification code structure array.
[0045] In this embodiment, the monitoring period of the timer is determined according to the actual communication frequency of the serial port communication application program. Those skilled in the art can flexibly adjust the monitoring period according to the needs of the actual application scene, but should ensure that the period monitoring frequency is lower than the actual communication frequency of the serial port, so as to avoid frequent reading of serial port information files. The monitoring period of the timer should be lower than or equal to the actual communication frequency of the serial port communication application program. According to the monitoring period of the timer, the data starts the periodic monitoring task. When the timer triggers, the embodiment periodically opens and reads the serial port state record file in the operating system driver layer according to the unique identification code of each serial port. The serial port state record file records the serial port data transmission length. The transmit (tx) and receive (rx) data byte length of each serial port is extracted from the serial port state record file to obtain the current transmit and receive data byte length information of each serial port. The current transmit and receive data byte length information of each serial port is associated and saved in the serial port identification code structure array according to the unique identification code of the serial port, so as to ensure that the transmit and receive byte length of each serial port is correctly matched with its corresponding identifier.
[0046] The application monitors the serial port data transmission length record file in the operating system driver layer, instead of relying on the read and write operation of the application layer, realizes the serial port communication state monitoring without interaction with the application program, and does not need to open the serial port or send and receive data separately. This method avoids the cumbersome process of directly operating the serial port, sending and receiving data in the traditional method, not only improves the monitoring efficiency and accuracy, but also reduces the occupation of system resources, providing an effective means for real-time monitoring of serial port communication state.
[0047] S5. Based on the serial port identification code structure array, periodically compare the current transmit and receive data byte length information with the last recorded transmit and receive data byte length information to obtain the serial port transmit and receive state change result.
[0048] S6. Determine the service gateway serial port communication state according to the serial port transceiving state change result, and update the program state information according to the service gateway serial port communication state.
[0049] In the embodiment, the step of determining the service gateway serial port communication state according to the serial port transceiving state change result comprises: if the serial port transceiving state change result is that the lengths of the transceiving data byte numbers of all the serial ports change or are within the normal threshold range, determining that the service gateway serial port communication state is normal, otherwise, determining that the service gateway serial port communication state is abnormal. The embodiment can more accurately determine the communication state of the serial port by comparing the lengths of the transceiving data byte numbers of the drive layer, and avoids misjudgment caused by application program read-write errors.
[0050] Specifically, the embodiment compares the currently read length of the current transceiving data byte number information with the last transceiving data byte number length information saved in the serial port identification code structure array when the timer triggers, determines whether the transceiving data of each serial port changes, determines the serial port communication state according to the change of the lengths of the transceiving data of each serial port, if the lengths of the transceiving data of all the serial ports change and the data change amount is within the normal range and the error rate is lower than the error threshold, determines that the service gateway serial port communication state is normal, and updates the state file to be in the normal state; if the length of the transceiving data of a serial port does not change or only one item changes, determines that the service gateway serial port communication state is abnormal, and triggers the abnormal processing mechanism. The embodiment records the communication state information of each serial port into the state file, the state file uses "1" to represent normal and "0" to represent abnormal, and updates the serial port identification code structure array according to the service gateway serial port communication state for use in the next round of serial port communication state monitoring.
[0051] In the embodiment, the method further comprises: continuously monitoring the external instruction interface when the timer does not trigger, if a program exit instruction is received, performing resource release and program termination processing, releasing all allocated resources, and safely terminating the program running; if no program exit instruction is received, continuing to wait for the next triggering of the timer to perform the next round of serial port communication state monitoring.
[0052] Specifically, the embodiment controls to enter the internal loop of the periodic monitoring task when the timer triggers, and continuously monitors whether there is an external command requiring the program to exit when the timer does not trigger or in the state check after each time the timer triggers, if an exit command is received, releasing all allocated resources and safely exiting.
[0053] For the convenience of understanding, the embodiment will be described below by way of example: as Figure 2As shown, the program developed based on C language is deployed on the service gateway machine and set as the system self-start item to ensure automatic running at system startup. After the program starts, initialization is performed first, including reading the timer cycle parameter in the configuration file. Then, the embodiment uses the system command to cyclically execute the dmesg|grep ttySX command to capture and analyze the unique identification code (in hexadecimal form) of ttyS0 to ttyS7 (corresponding to serial port 1 to serial port 8). These unique identification codes are the unique identity of the serial port device in the system. Then, in order to ensure the accuracy and efficiency of monitoring, the embodiment sets a timer, and the monitoring period of the timer is adjusted according to the actual communication frequency of the serial port communication application program to avoid the adverse effects of too high or too low monitoring frequency on system performance. When the timer triggers, the program regularly accesses the serial port state record file (such as / proc / tty / driver / serial file) in the operating system driver layer. The embodiment obtains the serial port data transmission record by reading the / proc / tty / driver / serial file instead of directly opening the serial port for read and write operations. Unlike traditional serial port opening (such as using the open function) and read and write (such as using the read and write functions) operations, this file is a key location used by the Linux kernel to record the length of the serial port device data transmission byte number. The file content is read line by line by the fgets function. For example, each line of content is 0: uart: 16550A port: 000003F8 irq: 4tx: 0rx: 0. The transmission (tx) and reception (rx) byte numbers of each serial port are extracted to obtain the current data transmission byte number length information of each serial port, and these data are stored in the serial port identification code structure array. Only read operations on system files and comparison and update of memory data are implemented. The array serial numbers 0-7 are determined by comparison after conversion of the identification code and the string after "port:" in the string extracted previously, so as to subsequently determine whether the communication state is normal by comparing the change of the data transmission byte number between the two times saved in the serial port identification code structure array, and record these state information to a file. If the transmission and reception byte numbers of the serial port both change, it is considered that the serial port communication is normal, and the program writes the corresponding "1" (representing normal) status code to the state saving file. Conversely, if the byte numbers do not change or only one of them changes, it is considered to be communication abnormal, and recorded as "0" (representing abnormal). The state saving file consists of 8 characters, which represent the states of all monitored serial ports from serial port 1 to serial port 8.
[0054] The program of the embodiment does not need to interact with the application program, does not rely on the serial communication function of the application program, independently runs on the system, can be compatible with third-party data communication programs, indirectly obtains the monitoring serial communication state information by reading system files, judges the serial communication state without directly operating the serial port resources under the cogitation system, thereby reducing the occupation of system resources, and realizes the decoupling of the state monitoring and the communication function. The decoupling makes the serial communication state monitoring more flexible and independent, avoids the influence of the implementation mode of the communication function.
[0055] In addition, the embodiment also designs an exit mechanism, which ensures that all resources can be safely released and the program can be exited when needed by monitoring whether there is an external command for the program to exit. If not, the timer is triggered again. The embodiment only reads the system files and compares and updates the memory data through the above-mentioned timer triggering mechanism, data comparison logic and external command exit mechanism. No additional serial port opening and reading and writing operations are needed, no active data sending and receiving is involved, and no interaction with the serial application program of the service gateway machine is needed. The application program ensures the exclusivity of the serial port resources, which will not compete with any serial application program for the serial port resources, realizes the decoupling of the serial communication state monitoring and the serial communication function, and therefore, the method proposed in the embodiment can efficiently realize the real-time monitoring of the serial communication state without relying on the interaction of the application program. The system resources occupied by the program during the running process are extremely low, which is particularly prominent in the resource-limited environment, and improves the overall performance and stability of the system.
[0056] The embodiment of the present application provides a service gateway machine serial port communication state monitoring method, the method comprises the following steps: performing program initialization according to a service gateway machine system configuration file, and analyzing serial port device identification information of the service gateway machine, extracting a unique identification code of each serial port, and storing the unique identification code of each serial port in a serial port identification code structure array; in response to a timer trigger instruction, regularly opening and reading data in an operating system driver layer serial port state record file according to the unique identification code of each serial port, obtaining current transceiving data byte length information of each serial port; associating and saving the current transceiving data byte length information of each serial port into the serial port identification code structure array according to the unique identification code; based on the serial port identification code structure array, periodically comparing the current transceiving data byte length information with last recorded transceiving data byte length information, obtaining a serial port transceiving state change result; judging a service gateway machine serial port communication state according to the serial port transceiving state change result, and updating program state information according to the service gateway machine serial port communication state. Compared with the prior art, the embodiment realizes automatic serial port communication state monitoring without opening or reading and writing the serial port by monitoring serial port data transceiving records in the operating system driver layer, ensures exclusive use of serial port resources by the application program, avoids direct interaction with the serial port application program, thereby realizing decoupling of serial port communication state monitoring and serial port communication function, and improving overall stability and resource utilization efficiency of the system.
[0057] It should be noted that the size of the serial number of each process does not mean the order of execution, and the execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
[0058] In one embodiment, as shown in Figure 3 The embodiment of the present application provides a service gateway machine serial port communication state monitoring system, which comprises:
[0059] The initialization module 101 is used for performing program initialization according to a service gateway machine system configuration file after starting a program, and retrieving serial port device identification information of the service gateway machine according to a received system command;
[0060] The identification analysis module 102 is used for analyzing the serial port device identification information, extracting a unique identification code of each serial port, and storing the unique identification code of each serial port in a serial port identification code structure array;
[0061] The periodic monitoring module 103 is used for regularly opening and reading data in an operating system driver layer serial port state record file according to the unique identification code of each serial port in response to a timer trigger instruction, obtaining current transceiving data byte length information of each serial port;
[0062] The identification association module 104 is configured to associate and save the current data byte length information of each serial port into the serial port identification code structure array according to the unique identification code;
[0063] The state monitoring module 105 is configured to periodically compare the current data byte length information with the last recorded data byte length information based on the serial port identification code structure array, and obtain a serial port transmission state change result.
[0064] The state judgment module 106 is configured to judge the service gateway machine serial port communication state according to the serial port transmission state change result, and update the program state information according to the service gateway machine serial port communication state.
[0065] In the embodiment, the judgment of the service gateway machine serial port communication state according to the serial port transmission state change result specifically includes: if the serial port transmission state change result is that the data byte length of all serial ports has changed or is within the normal threshold range, it is judged that the service gateway machine serial port communication state is normal, otherwise, it is judged that the service gateway machine serial port communication state is abnormal.
[0066] In the embodiment, the monitoring period of the timer is determined according to the actual communication frequency of the serial port communication application program; and the monitoring period of the timer should be lower than or equal to the actual communication frequency of the serial port communication application program.
[0067] In the embodiment, the system further comprises a program monitoring module, which is configured to continuously monitor the external instruction interface when the timer is not triggered, if a program exit instruction is received, perform resource release and program termination processing, release all allocated resources, and safely terminate the program running; if no program exit instruction is received, continue to wait for the next trigger of the timer to perform the next round of serial port communication state monitoring.
[0068] The specific limitation of the service gateway machine serial port communication state monitoring system can refer to the limitation of the service gateway machine serial port communication state monitoring method described above, which will not be repeated here. Those skilled in the art can realize that the various modules and steps described in combination with the embodiments disclosed in the present application can be realized by hardware, software or both. Whether the functions are realized by hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0069] The embodiment of the application provides a service gateway machine serial port communication state monitoring system, the system carries out program initialization through an initialization module; the serial port equipment identification information of the service gateway machine is parsed through an identification analysis module, the unique identification code of each serial port is extracted, and the unique identification code of each serial port is stored in a serial port identification code structure array; the periodic monitoring module responds to the timer trigger instruction, the data in the operating system driver layer serial port state record file is periodically opened and read according to the unique identification code of each serial port, and the current receiving and transmitting data byte length information of each serial port is obtained; the identification association module is used for associating and saving the current receiving and transmitting data byte length information of each serial port into the serial port identification code structure array; the state monitoring module periodically compares the current receiving and transmitting data byte length information with the last recorded receiving and transmitting data byte length information, and obtains the serial port receiving and transmitting state change result; the state judgment module is used for judging the service gateway machine serial port communication state, and the program state information is updated according to the service gateway machine serial port communication state. Compared with the prior art, the embodiment realizes the automatic serial port communication state monitoring without opening or reading and writing the serial port by monitoring the serial port data receiving and transmitting record in the operating system driver layer, ensures the exclusive use of the serial port resource by the application program, avoids the direct interaction with the serial port application program, thereby realizing the decoupling of the serial port communication state monitoring and the serial port communication function, and improving the overall stability and resource utilization efficiency of the system.
[0070] The above-described embodiments only express several preferred embodiments of the application, the description is more specific and detailed, but it cannot be understood as the limitation of the patent scope of the application. It should be pointed out that for ordinary skilled in the art, without departing from the technical principles of the application, several improvements and replacements can be made, and these improvements and replacements should be regarded as the protection scope of the application. Therefore, the protection scope of the patent of the application should be subject to the protection scope of the claims.
Claims
1. A service gateway machine serial communication status monitoring method, characterized in that, The method comprises the following steps: After starting the program, program initialization is performed according to a service gateway system configuration file, and serial port device identification information of the service gateway is retrieved according to a received system command; The serial port device identification information is parsed, and a unique identification code of each serial port is extracted and stored in a serial port identification code structure array; In response to a timer trigger instruction, current data byte length information of each serial port is obtained by periodically opening and reading data in an operating system driver layer serial port state record file according to the unique identification code of each serial port; The current data byte length information of each serial port is associated and saved in the serial port identification code structure array according to the unique identification code; Based on the serial port identification code structure array, current data byte length information is periodically compared with last recorded data byte length information to obtain a serial port transmission state change result; The service gateway serial port communication state is judged according to the serial port transmission state change result, and program state information is updated according to the service gateway serial port communication state.
2. The method for monitoring the state of serial communication of a service gateway machine according to claim 1, wherein, The step of judging the service gateway serial port communication state according to the serial port transmission state change result comprises: if the serial port transmission state change result is that the data byte length of all serial ports has changed or is within a normal threshold range, it is judged that the service gateway serial port communication state is normal, otherwise it is judged that the service gateway serial port communication state is abnormal.
3. The method for monitoring the state of serial communication of a service gateway machine according to claim 1, wherein: The monitoring period of the timer is determined according to the actual communication frequency of the serial port communication application program; The monitoring period of the timer should be lower than or equal to the actual communication frequency of the serial port communication application program.
4. The method of claim 1, wherein the method further comprises: determining whether the service gateway is in a normal state or an abnormal state; and outputting a message indicating whether the service gateway is in the normal state or the abnormal state. The unique identification code of each serial port comprises an address, an interrupt number and a serial port type.
5. The method of claim 1, wherein the method further comprises: The method further comprises: continuously monitoring an external instruction interface when the timer is not triggered, if a program exit instruction is received, performing resource release and program termination processing, releasing all allocated resources, and safely terminating program running; If no program exit instruction is received, the next trigger of the timer is waited for, and the next round of serial port communication state monitoring is performed.
6. The method for monitoring the state of a serial communication of a service gateway machine according to claim 1, wherein: The service gateway system configuration file comprises a timer period parameter.
7. A service gateway machine serial communication status monitoring system, characterized by, The system comprises: An initialization module, configured to perform program initialization according to a service gateway system configuration file after starting the program, and retrieve serial port device identification information of the service gateway according to a received system command; An identification parsing module, configured to parse the serial port device identification information, extract a unique identification code of each serial port, and store the unique identification code of each serial port in a serial port identification code structure array; A periodic monitoring module, configured to periodically open and read data in an operating system driver layer serial port state record file according to the unique identification code of each serial port in response to a timer trigger instruction, and obtain current data byte length information of each serial port; An identification association module, configured to associate and save the current data byte length information of each serial port in the serial port identification code structure array according to the unique identification code; An identification association module, configured to associate and save the current data byte length information of each serial port in the serial port identification code structure array according to the unique identification code; The state monitoring module is configured to periodically compare current transceiving data byte length information with last recorded transceiving data byte length information based on the serial port identification code structure array, and obtain serial port transceiving state change results. The state judging module is configured to judge the service gateway machine serial port communication state according to the serial port transceiving state change results, and update program state information according to the service gateway machine serial port communication state.
8. The system of claim 7, wherein the service gateway machine is a server. The judging the service gateway machine serial port communication state according to the serial port transceiving state change results specifically includes: if the serial port transceiving state change results are that the transceiving data byte length of all serial ports has changed or is within a normal threshold range, it is judged that the service gateway machine serial port communication state is normal, otherwise, it is judged that the service gateway machine serial port communication state is abnormal.
9. The service gateway serial communication status monitoring system as described in claim 7, characterized in that: The monitoring period of the timer is determined according to the actual communication frequency of the serial port communication application program. The monitoring period of the timer should be lower than or equal to the actual communication frequency of the serial port communication application program.
10. The system of claim 7, wherein: the service gateway machine is a server; and the server is a Windows® server. The system further comprises a program monitoring module configured to continuously monitor an external instruction interface when the timer is not triggered, and if a program exit instruction is received, perform resource release and program termination processing, release all allocated resources, and safely terminate program running. If no program exit instruction is received, the next trigger of the timer is continued to be waited for, and the next round of serial port communication state monitoring is performed.
Citation Information
Patent Citations
Network element state polling method based on storage process timed scheduling
CN101478432A
Monitoring method and device and computer readable storage medium
CN114158080A