Processing method, device, storage medium and system for industrial serial port machine communication
By using coroutine technology and asynchronous keywords in industrial serial port communication, configuring pending linked lists and preparing linked lists, the problem of high CPU and memory resource consumption in the existing technology is solved, and efficient and low-latency serial port communication is achieved.
Patent Information
- Application Number
- CN202510333806.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-20
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2045-03-20
AI Technical Summary
The prior art consumes a large amount of CPU and memory resources in industrial serial port communication, resulting in insufficient performance.
Coroutine technology is used to configure pending linked lists, prepare linked lists, cache tags and asynchronous keywords to realize asynchronous communication processing of serial port machines and reduce CPU context switching and memory usage.
It realizes low-power and low-latency serial port communication, reduces the consumption of CPU and memory resources, and improves the stability and performance of the system.
Smart Images

Figure CN120179598A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of communication technologies, and particularly relates to a processing method, device, storage medium, and system for serial port machine communication. Background Art
[0002] Serial communication technology is widely used in fields such as industry, the Internet of Things, and servers. An industrial network serial port server (abbreviated as a serial port machine) can convert TTL, RS-232, and RS-485 signals into TCP signals. When a large number of serial port devices are put into use, there are performance requirements for low power consumption and low latency for the I / O processing and collection device connected to the lower layer of the serial port machine; there are also stability requirements for high reliability and high robustness, as well as requirements for plug-and-play and generating timestamps, etc.
[0003] Related technical solutions, such as a synchronization solution based on multiple processes: each TCP port uses one process. This solution can meet user requirements, but it consumes a large amount of CPU and memory resources. Each TCP port consumes approximately 5% of the time slice of a single CPU core; for example, a non-blocking solution based on multiple threads: there will also be consumption of CPU time slices for context switching and a large heap memory overhead. Summary of the Invention
[0004] The purpose of this application is to provide a processing method, device, storage medium, and system for serial port machine communication, aiming to solve the problem of large consumption of CPU resources and memory resources in the existing technical solutions for industrial serial port machine communication.
[0005] According to the first aspect of this application, a processing method for serial port machine communication is provided. The processing method includes: when communicating with multiple TCP ports, using a first queue pool to store the element information corresponding to the multiple TCP ports; when successfully connecting to one or more of the multiple TCP ports, adding the elements corresponding to the one or more TCP ports to a linked list to be processed. When there is a cache mark for one or more TCP ports in the linked list to be processed, adding the element information corresponding to the one or more TCP ports with the cache mark to a ready linked list, and receiving the output information of the TCP ports in the ready linked list; and when connecting to one or more of the multiple TCP ports, predicting the I / O operations that will occur in the next process and using an asynchronous keyword to mark this process. The asynchronous keyword is used to indicate that when the current operation encounters an I / O block, the operating system is allowed to schedule CPU resources to other execution tasks.
[0006] Based on the coroutine technology, this processing method configures a linked list to be processed, a ready linked list, a cache mark, and an asynchronous keyword, realizing the processing of asynchronous communication of the serial port machine, without the time slice of CPU context switching, thereby reducing the overhead of CPU resources.
[0007] In an alternative embodiment, the processing method further includes: for one or more TCP ports with cache tags, after receiving the corresponding output information, adding the element information of the corresponding TCP port back to the linked list to be processed.
[0008] Adding it to the linked list to be processed and rechecking whether there is a buffer instead of continuously synchronously waiting for the buffer to appear.
[0009] In an alternative embodiment, the asynchronous keyword is configured to generate a corresponding task stack and add it to the linked list to be processed. The processing method further includes managing the stack and the linked list. The linked list to be processed is configured to store task stacks waiting for the completion of I / O operations, and the ready linked list is configured to store stacks that have completed I / O operations.
[0010] Managing the stack and the linked list, when the current operation encounters I / O blocking, allowing the operating system to schedule CPU resources to other executable tasks. If the stack of the corresponding TCP port is in the linked list to be processed, the CPU will not switch to this linked list for I / O processing.
[0011] In an alternative embodiment, when communicating with multiple TCP ports, the processing method further includes: using a pre-configured configuration file to register the port information corresponding to the multiple TCP ports, where the port information includes the TCP port number of the serial device and the IP address of the serial machine connected to the serial device; using the TCP port number of the serial device and the IP address of the serial machine connected to the serial device to distinguish the levels of information output to the file storage module; and when outputting information to the file storage module, cutting the corresponding log file and adding a timestamp to the cut log file.
[0012] Effectively manage the port information corresponding to multiple TCP ports using the configuration file, and manage the file storage module based on this port information; and manage the logs. It is convenient to distinguish the output from which TCP port by level and cut according to the file size for easy browsing.
[0013] In an alternative embodiment, after registering the port information corresponding to the multiple TCP ports using the pre-configured configuration file, the processing method further includes: using a pre-configured WatchDog module to periodically monitor the configuration file; when the change in the configuration file indicates a newly added serial device, registering the corresponding port information and using the TCP port number of the newly added serial device and the IP address of the serial machine connected to the newly added serial device to add a corresponding level.
[0014] Using a pre-configured WatchDog module to monitor and manage configuration files at regular intervals. When adding a new serial port machine, there is no need to restart the system. When the upstream device of the new serial port machine is connected to the serial port machine, it can be plugged and played, and there will be direct log output.
[0015] In an alternative embodiment, the pre-configured WatchDog module is further configured to: reset the timing when an I / O operation is detected; and determine a program failure and initiate a program reset when the timing has not been reset for a preset time interval.
[0016] Use the WatchDog module to monitor the system health. When there are problems with the system itself or the system is caused by external environment problems, the system will automatically reset.
[0017] In an alternative embodiment, when communicating with multiple TCP ports, the processing method further includes: continuously monitoring the connection status with the multiple TCP ports; and when the connection with one or more of the multiple TCP ports is not successful, re-adding the corresponding connection task to the first queue pool and waiting for reconnection.
[0018] The ports that are not successfully connected may be in a state where the serial port is not connected. Therefore, if a serial port device is connected later, plug-and-play can be achieved. Further, the first queue pool keeps trying to connect to ensure plug-and-play when a new device is connected to the upstream of the serial port machine.
[0019] In an alternative embodiment, when communicating with multiple TCP ports, the processing method further includes: for the successfully connected TCP ports, sending a heartbeat packet at preset intervals to continuously asynchronously receive the output information of the TCP ports.
[0020] Maintain the active state of the connection to prevent the serial port machine from actively disconnecting from the system due to no I / O for a long time; sending a heartbeat packet can determine whether the connection status between the system and the serial port machine is normal.
[0021] According to a second aspect of the present application, there is provided a file server, which includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, and the processor executes the computer program to implement the above processing method.
[0022] According to a third aspect of the present application, there is provided a machine-readable storage medium, on which instructions are stored, and the instructions cause the machine to execute the above processing method.
[0023] According to a fourth aspect of the present application, an industrial serial port machine communication system is provided. The industrial serial port machine communication system includes a serial port device, a serial port machine for electrically connecting the serial port device to the aforementioned file server, and a user terminal electrically connected to the file server. The file server deploys application programs using a Linxu virtual machine. The file server is further configured with a log management service to enable the user terminal to search, monitor, and alarm the output logs.
[0024] In an optional implementation, the serial port machine is further configured to convert the physical port of the serial port device electrically connected to it into a TCP port. The file server includes a file storage module, and the file storage module is configured to store the output information of the serial port device.
[0025] The industrial serial port machine communication system realizes asynchronous communication processing based on coroutines, without the time slice of CPU context switching, thereby reducing the overhead of CPU resources. The industrial serial port machine communication system can also realize online viewing of I / O output files on the web page of the browser, eliminating the need to log in to the serial port device or virtual machine. For I / O output files, they are rotated according to size, and timestamps are appended line by line according to the content, facilitating the positioning of the time of I / O output files.
[0026] Through the above technical solution, the processing method for serial port machine communication provided by the embodiments of the present application stores the element information corresponding to multiple ports in a first queue pool when communicating with multiple TCP ports; when successfully connecting to one or more of the multiple TCP ports, add the elements corresponding to the one or more TCP ports to the linked list to be processed. When there is a cache mark for one or more TCP ports in the linked list to be processed, add the element information corresponding to the one or more TCP ports with the cache mark to the ready linked list, and receive the output information of the TCP ports in the ready linked list; and when connecting to one or more of the multiple TCP ports, predict the I / O operations that will occur in the next process, and use the asynchronous keyword to mark this process. Through this asynchronous keyword, when the current operation encounters I / O blocking, the operating system is allowed to schedule CPU resources to other execution tasks. The embodiments of the present application configure a linked list to be processed, a ready linked list, a cache mark, and an asynchronous keyword based on coroutine technology, realizing the asynchronous communication processing of the serial port machine, without the time slice of CPU context switching, thereby reducing the overhead of CPU resources. Due to the use of coroutine technology, there is basically no generation of heap memory. At the same time, because of the performance advantage, the buffer occupies less time in memory and can be written to the file storage module faster, thereby reducing the overhead of memory resources.
[0027] Other features and advantages of the present application will be set forth in the following description, and in part will be obvious from the description, or may be learned by practice of the present application. The objectives and other advantages of the present application may be realized and attained by the structure and processes pointed out in the specification and the drawings. Description of the Drawings
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present application or in the related art, the following briefly introduces the drawings required for use in the description of the embodiments or the related art. Obviously, the drawings in the following description are certain embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0029] Figure 1 It is a schematic flowchart of a processing method for serial port machine communication provided by an exemplary embodiment of the present application.
[0030] Figure 2 It is a schematic diagram of the system topology provided by an exemplary embodiment of the present application.
[0031] Figure 3 It is a schematic flowchart of the processing method provided by an exemplary embodiment of the present application.
[0032] Figure 4 It is a schematic diagram of TCP port communication provided by an exemplary embodiment of the present application. Detailed Embodiments
[0033] In order to make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present application.
[0034] Before explaining the embodiments of the present application in detail, the technical terms involved in the present application are explained as shown in Table 1.
[0035] Table 1
[0036]
[0037]
[0038] Figure 1 It is a schematic flowchart of a processing method for serial port machine communication provided by an exemplary embodiment of the present application, which can be applied to a file server. The processing method may include the following steps:
[0039] Step S110: When communicating with multiple TCP ports, use the first queue pool to store element information corresponding to the multiple TCP ports.
[0040] In an embodiment of the present application, the first queue pool is, for example, a FIFO queue pool, and the first queue pool is used to store element information corresponding to multiple ports.
[0041] Please refer to Figure 2 For example, when the file server communicates with multiple serial devices, the serial devices are connected to the serial machine, and the serial machine can convert the physical port of the serial device to a TCP port to achieve downlink communication between the file server and multiple serial devices. For example, the serial machine can convert the physical port of com1 to "192.168.1.1:5000" and the physical port of com2 to "192.168.1.1:5100".
[0042] In a preferred embodiment of the present application, when communicating with multiple TCP ports, the processing method may also include: using a preconfigured configuration file to register port information corresponding to multiple TCP ports, where the port information may include the TCP port number of the serial port device and the IP address of the serial port machine to which the serial port device is connected; using the TCP port number of the serial port device and the IP address of the serial port machine to which the serial port device is connected to distinguish the level of information output to the file storage module; and when outputting information to the file storage module, cutting the corresponding log file and adding a timestamp to the cut log file.
[0043] For example, the embodiment of the present application can use the Linxu virtual machine to deploy applications on a file server. In the Linxu virtual machine, a configuration file can be pre-configured, which is used to register the IP address and corresponding TCP port number of the serial port machine, and can also register unused TCP port numbers. As described above, the serial port device is connected to the serial port machine, and the serial port machine can convert the physical port of the serial port device into a TCP port. Among them, the TCP port can comply with the preset rules, and the rules of the TCP port numbers of multiple serial port machines can be similar. Preferably, the embodiment of the present application can pre-configure the setting rules of the TCP port number. For example, the industrial serial port machine of the NCOM660 (RS232 / TTL) model has a default TCP port number of 5000, 5100, 5200...6400, 6500, a total of 16 port numbers, and the configuration file can register the number of port numbers, and the corresponding TCP port number can be parsed according to the number. Multiple serial port machines are configured with different IPs and connected to the LAN network. The serial port device and the serial port machine are connected, for example, by using a TTL to RJ45 cable.
[0044] In the embodiments of the present application, the file server may include a file storage module (e.g., a folder), and the TCP port number of the serial device and the IP address of the serial machine connected to the serial device can be used to distinguish the levels at which information is output to the file storage module. The levels of I / O output information can represent the levels of the folder, and are distinguished according to, for example, "ip" and "port" numbers and output to different folders. In a preferred embodiment of the present application, for I / O output information, before writing it into the file storage module, the bytes of the output information can be re-encoded, and a timestamp can be added line by line to identify the time when the serial event occurs. The log file is cut, and a timestamp is added to the cut log file. For example, "SerialLog / 192.168.1.1 / 5100 / serial_2024_1207_1450.log".
[0045] Further, an Nginx WEB file service can be built in the Linxu virtual machine and connected to the local area network, which can facilitate users to preview I / O output information online. In a preferred embodiment of the present application, Loki or ELK log management services can be used to implement functions such as searching, monitoring, and alarming of I / O output logs at the user end.
[0046] In a preferred embodiment of the present application, after registering the port information corresponding to multiple TCP ports using a pre-configured configuration file, the processing method may further include: using a pre-configured WatchDog module to periodically monitor the configuration file; when the change in the configuration file shows a newly added serial device, registering the corresponding port information, and using the TCP port number of the newly added serial device and the IP address of the serial machine connected to the newly added serial device to add a corresponding level.
[0047] Using a pre-configured configuration file, when a new serial machine is added, there is no need to restart the program of the file server. When the upstream device of the new serial machine is connected to the serial machine, it can be plug-and-play and can directly output logs. Further, if a configuration item is reduced in the configuration file, for example, 192.168.1.1 is removed, then for the serial machine corresponding to the ip, the file server will not actively disconnect the connection; if the serial machine itself is disconnected (e.g., the network is disconnected, the power is off, or the serial cable is disconnected, etc.), after disconnection, it will not be automatically added to the first queue pool, and the ip in the configuration file will not be automatically traversed next time, and the connection will not be attempted again. That is, if the Ip is physically disconnected in the configuration, it will be added to the first queue pool. The corresponding TCP port is always in a physically unconnected state, and in the configuration file, it is continuously added to the first queue pool, enabling plug-and-play.
[0048] In a preferred embodiment of the present application, the preconfigured WatchDog module can also be configured to: reset the timer when an I / O operation is monitored; and determine a program failure and initiate a program reset when the timer is not reset after a preset time interval.
[0049] Continuing with the above example, the WatchDog module can monitor the operating status of the system in real time. If the watchdog timer is not reset at the specified time, it indicates that there is an unexpected fault in the environment, and a reset procedure is initiated.
[0050] Please refer to Figure 3 For example, the configuration of the WatchDog module (also known as the watchdog timer) may include: when the system is running normally and generating I / O, the system can periodically "feed the dog", that is, reset the watchdog timer to make it count again; when the "dog" is not "fed" within the specified time, the system may be in an abnormal state, causing the system program to reset. Further, the WatchDog module can also be configured to: regularly monitor the above configuration file; when the change in the configuration file shows that a new serial port device has been added, register the corresponding port information, and use the TCP port number of the newly added serial port device and the IP address of the serial port machine to which the newly added serial port device is connected to add a corresponding level in the file storage module (for example, a folder).
[0051] Step S120: When the connection with one or more TCP ports among the multiple TCP ports is successful, the elements corresponding to the one or more TCP ports are added to the pending list; when one or more TCP ports in the pending list have a cache mark, the element information corresponding to the one or more TCP ports with the cache mark is added to the ready list, and the output information of the TCP ports in the ready list is received.
[0052] The output information of the TCP port can be understood as the original data from the downstream TCP port of the serial port machine. Figure 3 For example, when communicating with multiple TCP ports, a FIFO queue pool is used to store the element information corresponding to the multiple ports. Taking 100 TCP ports being exposed as an example, the initial state of the FIFO queue pool includes the element information corresponding to the 100 TCP ports; when 60 TCP ports out of the 100 TCP ports are successfully connected to the file server, the elements corresponding to the 60 TCP ports are added to the pending list (e.g., a preconfigured pending list); when 25 TCP ports in the pending list have a cache mark (e.g., buffer), the element information corresponding to the 25 TCP ports with the cache mark is added to the ready list (e.g., a preconfigured ready list), and the output information of the TCP ports in the ready list is received.
[0053] In a preferred embodiment of the present application, for one or more TCP ports with cache tags, after receiving the corresponding output information, the element information of the corresponding TCP port is re-added to the linked list to be processed.
[0054] Continuing with the above example, after reading the 25 TCP ports with the above cache tags, they are re-added to the linked list to be processed. Adding to the linked list to be processed, re-judging whether there is a buffer instead of continuing to synchronously wait for the appearance of the buffer.
[0055] In a preferred embodiment of the present application, when communicating with multiple TCP ports, the processing method may further include: real-time monitoring of the connection status with multiple TCP ports; and when the connection with one or more of the multiple TCP ports fails, re-adding the corresponding connection task to the first queue pool and waiting for reconnection.
[0056] Please refer to Figure 3 Example, as described above, when connecting to multiple TCP ports, use a FIFO queue pool to store the element information of multiple ports, and perform connection status judgment, buffer presence judgment for ports, and port exception judgment, etc. When the connection with one or more of the multiple TCP ports fails, re-adding the corresponding connection task to the first queue pool and waiting for reconnection. The ports with failed connections may be in a state where the serial port is not connected. Therefore, if a serial port device is connected later, plug-and-play can be achieved.
[0057] In a preferred embodiment of the present application, when communicating with multiple TCP ports, the processing method may further include: for the TCP ports with successful connections, sending a heartbeat packet at preset intervals to continuously asynchronously receive the output information of the TCP ports.
[0058] For example, for the TCP ports with successful connections, a heartbeat packet can be sent every 15s, for example. When there is a buffer in the TCP port, I / O reception can be performed. After being processed inside the system, the I / O is written to the file storage module. Keep the connection active to prevent the serial port machine from actively disconnecting from the system due to no I / O for a long time; sending a heartbeat packet can determine whether the connection status between the system and the serial port machine is normal.
[0059] Step S130: When connecting to one or more of the multiple TCP ports, predict the I / O operations that will occur in the next process and mark the process with an asynchronous keyword, where the asynchronous keyword is used to indicate that when the current operation encounters an I / O block, the operating system is allowed to schedule the CPU resources to other execution tasks.
[0060] Among them, the I / O operation may refer to cross-device data exchange. Among them, the asynchronous keyword (await) can be configured to: wait for an asynchronous operation to complete, and the asynchronous operation may include an asynchronous function call, etc. Using await can prevent the program from blocking the main thread when waiting for the asynchronous operation to complete, so as to achieve concurrent execution.
[0061] In a preferred embodiment of the present application, the asynchronous keyword can also be configured to generate a corresponding task stack and add it to the linked list of pending tasks. The embodiment of the present application may also include a management stack and a linked list. Among them, the linked list of pending tasks can be configured to store the task stacks that are waiting for the I / O operation to complete; the ready list can be configured to store the stacks that have completed the I / O operation.
[0062] For example, for the function called in the next process, etc., the I / O that will be generated can be predicted, and this process can be marked with await. That is, when the current operation encounters I / O blocking, the operating system is allowed to schedule the CPU resources to other executable tasks.
[0063] As described above, the embodiment of the present application provides a pre-configured linked list of pending tasks (pending list) and a ready list (ready list). The unblocked I / O task stack can be added to the pending list. That is, the pending list is used to store all the task stacks that are waiting for the I / O operation to complete, ensuring that they can resume execution after the I / O is completed; at the same time, other tasks that can continue to execute can be scheduled from the ready list to make full use of the CPU resources. Further, when the I / O operation of a task is completed, it can be removed from the pending list, and its task stack can be added back to the ready list. At this time, the WatchDog timer can be reset to mark that the task has completed waiting and can continue to execute.
[0064] Accordingly, for the processing method for serial port machine communication provided by the embodiments of the present application, when communicating with multiple TCP ports, a first queue pool is used to store the element information corresponding to the multiple ports; when successfully connecting to one or more of the multiple TCP ports, the elements corresponding to the one or more TCP ports are added to the linked list to be processed. When there is a cache flag for one or more TCP ports in the linked list to be processed, the element information corresponding to the one or more TCP ports with the cache flag is added to the ready linked list, and the output information of the TCP ports in the ready linked list is received; and when connecting to one or more of the multiple TCP ports, predict the I / O operations that will occur in the next process, and use the asynchronous keyword to mark this process. Through this asynchronous keyword, when the current operation encounters I / O blocking, the operating system is allowed to schedule the CPU resources to other execution tasks. The embodiments of the present application configure a linked list to be processed, a ready linked list, a cache flag, and an asynchronous keyword based on the coroutine technology, realizing the processing of asynchronous communication of the serial port machine, without the time slice of CPU context switching, thereby reducing the overhead of CPU resources. Due to the use of coroutine technology, there is basically no generation of heap memory. At the same time, because of the performance advantage, the buffer occupies less time in memory and can be written to the file storage module faster, thereby reducing the overhead of memory resources. Further, in terms of reliability, the embodiments of the present application will reconnect in case of serial port anomalies and reset in case of unexpected errors, and the application program will restart. Functionally, it is realized that when the serial port device is inserted into the serial port machine, there is no need for configuration, and the I / O output can be directly viewed at the specified path.
[0065] The embodiments of the present application further provide a file server, which may include: a memory, a processor, and a computer program stored on the memory and executable on the processor. The processor executes the computer program to implement the above-mentioned processing method.
[0066] The embodiments of the present application further provide a machine-readable storage medium, on which instructions are stored, and the instructions cause the machine to execute the above-mentioned processing method.
[0067] The embodiments of the present application further provide an industrial serial port machine communication system, which may include a serial port device, a serial port machine for electrically connecting the serial port device to the above-mentioned file server, and a user terminal electrically connected to the file server. Among them, the file server deploys application programs using a Linxu virtual machine, and the file server is further configured with a log management service to realize the search, monitoring, and alarm of output logs by the user terminal.
[0068] Preferably, the serial port machine in the embodiments of the present application is further configured to convert the physical port of the serial port device electrically connected thereto into a TCP port. The file server includes a file storage module, and the file storage module is configured to store the output information of the serial port device.
[0069] In a preferred embodiment of the application, the data transmission between the file server, the serial port device, and the file storage module is asynchronous. However, for non-core but necessary functions, when the I / O volume is very small, the state stack does not need to be switched, and it can wait until the I / O is completed. For example, creating an I / O output path folder.
[0070] Please refer to Figure 2 and Figure 4 Example, the configuration of an industrial serial port machine communication system may include: connecting the serial port device to the serial port machine, which can convert the physical port of the serial port into a TCP port; configuring different IPs for multiple serial port machines and accessing the local area network; the serial port device and the serial port machine can be connected by means of a TTL to RJ45 connection line. Using a Linux virtual machine to store the output information of the serial port device and access the local area network. In the above Linux virtual machine, build an Nginx WEB file service and access the local area network for users to preview I / O output files online. Deploy the application corresponding to the above processing method in the above Nginx virtual machine and use the daemon process method to daemonize the application, and the application can be restarted by the daemon process again after a reset occurs through the WatchDog module.
[0071] In the Linxu virtual machine, a configuration file can be pre-configured to register the IP address of the serial port machine and the corresponding TCP port number, and the unused TCP port numbers can also be registered. Preferably, the TCP port number setting rules are restricted, and the configuration file only needs to register the number of port numbers, and the application program resolves the TCP port numbers according to the number. For the I / O output file, the TCP port number of the serial port device and the IP address of the serial port machine connected to the serial port device can be used to distinguish the levels of the I / O output information. And the log is cut according to the size, and a timestamp is added to the cut log file, so that the I / O output file realizes rotation according to the size and content-by-line appending of the timestamp, which is convenient for locating the time when the event occurs.
[0072] In the file service system, use the pre-configured WatchDog module to monitor the configuration file regularly; when the change in the configuration file shows a newly added serial port device, register the corresponding port information, and use the TCP port number of the newly added serial port device and the IP address of the serial port machine connected to the newly added serial port device to add the corresponding level.
[0073] When the file server connects to a TCP port, if the handshake fails, it will periodically retry. The TCP port may not be in the serial port access state. If a serial device is connected later, plug-and-play will be implemented. After a successful connection, a heartbeat packet is sent every preset time (e.g., 15s). When there is a buffer in the TCP port, I / O reception is performed, and after internal processing in the program, I / O is written to the file storage module.
[0074] Furthermore, if there is no I / O output on a certain TCP port for a long time, it may be as expected, or the serial device or serial cable may be in an abnormal state. In this case, the heartbeat may still be maintained, but the actual I / O cannot be output. The file server can disconnect from the TCP port, issue a warning, and reconnect. For I / O output, before writing to the file storage module, the bytes can be re-encoded, and a timestamp can be added line by line to identify the time when the serial port event occurred.
[0075] When the file server connects to multiple TCP ports, a FIFO queue pool can be used to store the element information of multiple TCP ports; connection status judgment, buffer presence judgment on ports, and port abnormality judgment are performed. For the asynchronous I / O processing of multiple serial machines and multiple TCP ports, it can be as Figure 3 shown. Furthermore, for functions, iterators, etc. called in the next process, the generated I / O can be predicted, and the process can be marked with await. That is, when the current operation encounters I / O blocking, the operating system is allowed to schedule CPU resources to other executable tasks.
[0076] Accordingly, the industrial serial machine communication system provided by the embodiments of the present application realizes asynchronous communication processing based on coroutines, without the time slice of CPU context switching, thus reducing the overhead of CPU resources. Through verification, in a production environment with 600 TCP ports, the actual consumption of resources of a single CPU core is 30%, and the actual physical memory used is 55MB. Furthermore, the industrial serial machine communication system can also realize online viewing of I / O output files on the web page of the browser, eliminating the need to log in to the serial device or virtual machine. The I / O output files are rotated according to size and a timestamp is appended line by line to the content, facilitating the positioning of the time when the event occurred.
[0077] It should be noted that the above control device, machine-readable storage medium, and industrial serial machine communication system can implement the processing method provided in the above embodiments. The specific implementation method can refer to the description of the processing method in the above embodiments and will not be elaborated here.
[0078] It can be understood that the circuit structures, names, and parameters described in the above embodiments are only examples. Those skilled in the art can also easily combine and adjust the structural features of the above multiple embodiments according to the usage needs, and should not limit the concept of this application to the specific details of the above examples.
[0079] Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A processing method for serial port machine communication, characterized in that: The processing method comprises: When communicating with multiple TCP ports, using the first queue pool to store element information corresponding to the multiple TCP ports; When connection with one or more TCP ports among the multiple TCP ports is successful, adding elements corresponding to the one or more TCP ports to a pending list, and when one or more TCP ports in the pending list have a cache mark, adding element information corresponding to the one or more TCP ports with the cache mark to a preparation list, and receiving output information of the TCP ports in the preparation list; and When connecting to one or more of the multiple TCP ports, predict the I / O operation that will be generated by the next process, and mark the process with an asynchronous keyword, wherein the asynchronous keyword is used to indicate that when the current operation encounters I / O blocking, the operating system is allowed to schedule CPU resources to other execution tasks.
2. The processing method according to claim 1, characterized in that: The processing method also includes: For the one or more TCP ports with cache marks, after receiving the corresponding output information, the element information of the corresponding TCP port is added back into the to-be-processed linked list.
3. The processing method according to claim 1, characterized in that: The asynchronous keyword is configured to generate a corresponding task stack and add it to the pending linked list. The processing method also includes managing the stack and the linked list. The pending linked list is configured to store a task stack that is waiting for the I / O operation to be completed. The ready list is configured to store a stack of completed I / O operations.
4. The processing method according to claim 1, characterized in that: When communicating with multiple TCP ports, the processing method further includes: Using a preconfigured configuration file, registering port information corresponding to the multiple TCP ports, the port information including the TCP port number of the serial port device and the IP address of the serial port machine to which the serial port device is connected; Using the TCP port number of the serial device and the IP address of the serial machine to which the serial device is connected, distinguish the level at which information is output to the file storage module; and When the information is output to the file storage module, the corresponding log file is cut and a time stamp is added to the cut log file.
5. The processing method according to claim 4, characterized in that: After registering the port information corresponding to the multiple TCP ports using the pre-configured configuration file, the processing method further includes: Using a pre-configured WatchDog module, regularly monitoring the configuration file; When the change in the configuration file indicates that a new serial port device is added, the corresponding port information is registered, and a corresponding level is added using the TCP port number of the new serial port device and the IP address of the serial port machine to which the new serial port device is connected.
6. The processing method according to claim 4, characterized in that: The pre-configured WatchDog module is also configured to: When an I / O operation is detected, resetting the timer; and When the timer is not reset for a preset time interval, a program failure is determined and a program reset is initiated.
7. The processing method according to claim 1, characterized in that: When communicating with multiple TCP ports, the processing method further includes: monitoring the connection status with the multiple TCP ports in real time; and When the connection with one or more TCP ports among the multiple TCP ports is unsuccessful, the corresponding connection task is re-added to the first queue pool to wait for reconnection.
8. The processing method according to claim 6, characterized in that: When communicating with multiple TCP ports, the processing method further includes: For a successfully connected TCP port, a heartbeat packet is sent at a preset interval to maintain continuous asynchronous reception of the TCP port's output information.
9. A file server, characterized in that: The file server comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the processing method according to any one of claims 1 to 8.
10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores instructions, which enable the machine to execute the processing method according to any one of claims 1-8.
11. An industrial serial port machine communication system, characterized in that: The industrial serial port machine communication system comprises a serial port device, a serial port machine for electrically connecting the serial port device with the file server according to claim 9, and a user terminal electrically connected to the file server. The file server uses the Linux virtual machine to deploy applications. The file server is also configured with a log management service to enable the user terminal to search, monitor and alarm the output log.
12. The industrial serial port machine communication system according to claim 11, characterized in that: The serial port machine is also configured to convert the physical port of the serial port device electrically connected thereto into a TCP port. The file server comprises a file storage module, and the file storage module is configured to store output information of the serial port device.
Citation Information
Patent Citations
High-speed serial port communication network
CN108228521A
Multi-serial-port transponder
CN110309096A
Method for supporting data disconnection retransmission and serial port server
CN115086104A