Processing methods, devices, storage media, and systems for industrial serial communication
By combining coroutine technology and the WatchDog module, low power consumption and high reliability of industrial serial communication are achieved, solving the problem of high CPU and memory resource consumption in existing technologies, and supporting plug-and-play and online viewing of I/O output files.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-20
- Publication Date
- 2026-03-31
AI Technical Summary
Existing technologies consume significant CPU and memory resources in industrial serial communication, failing to meet the demands for low power consumption, low latency, and high reliability.
The system employs coroutine technology to configure the pending linked list, the preparation linked list, the cache marker, and the asynchronous keyword to achieve asynchronous communication processing, reduce CPU context switching time slices, and utilizes a pre-configured WatchDog module to monitor the system health status. It also supports plug-and-play functionality and heartbeat packets to keep the connection active.
It achieves low-power, low-latency serial communication, reduces CPU and memory resource overhead, supports plug-and-play and online viewing of I/O output files, and improves system stability and reliability.
Smart Images

Figure CN120179598B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of communication technology, and specifically relates to a processing method, apparatus, storage medium and system for serial communication. Background Technology
[0002] Serial communication technology is widely used in industries, the Internet of Things (IoT), and servers. Industrial network serial servers (serial servers for short) can convert TTL, RS-232, and RS-485 signals into TCP signals. When a large number of serial devices are deployed, there are performance requirements for the downstream I / O processing and collection devices of serial servers, such as low power consumption and low latency; as well as high reliability, high robustness, and plug-and-play functionality, and the ability to generate timestamps.
[0003] Related technical solutions include, for example, a multi-process-based synchronization scheme: each TCP port uses one process. This scheme can meet user needs, but it consumes a lot of CPU and memory resources. Each TCP port consumes about 5% of the time slice of a single CPU core. Another example is a multi-threaded non-blocking scheme: it also consumes CPU time slices due to context switching and has a large heap memory overhead. Summary of the Invention
[0004] The purpose of this application is to provide a processing method, apparatus, storage medium and system for serial communication, aiming to solve the problem of high CPU and memory resource consumption in existing technologies for industrial serial communication.
[0005] According to a first aspect of this application, a processing method for serial port communication is provided, the processing method comprising: when communicating with multiple TCP ports, storing element information corresponding to the multiple TCP ports using a first queue pool; when a connection to one or more TCP ports among the multiple TCP ports is successful, adding the element corresponding to the one or more TCP ports to a pending processing list; when one or more TCP ports in the pending processing list have a cached flag, adding the element information corresponding to the one or more TCP ports with the cached flag to a preparation list; and receiving output information from the TCP ports in the preparation list; and when connecting to one or more TCP ports among the multiple TCP ports, predicting the I / O operation to be generated in the next process, and marking the process with an asynchronous keyword, the asynchronous keyword being 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.
[0006] This processing method, based on coroutine technology, configures a pending list, a preparation list, a cache marker, and an asynchronous keyword to handle asynchronous communication on a serial port. It eliminates the CPU context switching time slice, thereby reducing CPU resource overhead.
[0007] In an optional implementation, the processing method further includes: for one or more TCP ports with cached tags, after receiving the corresponding output information, adding the element information of the corresponding TCP port back to the list to be processed.
[0008] Instead of continuing to synchronously wait for the buffer to appear, add it to the pending list and re-check whether the buffer exists.
[0009] In an optional implementation, the asynchronous keyword is configured to generate a corresponding task stack, which is added to the pending list. The processing method further includes managing the stack and the list. The pending list is configured to store task stacks waiting for I / O operations to complete, and the preparation list is configured to store stacks that have completed I / O operations.
[0010] The management of stacks and linked lists allows the operating system to allocate CPU resources to other executable tasks when the current operation encounters I / O blocking. If the stack for the corresponding TCP port is already in the pending list, the CPU will not switch to that list for I / O processing.
[0011] In an optional implementation, when communicating with multiple TCP ports, the processing method further includes: registering port information corresponding to the multiple TCP ports using a pre-configured configuration file, the port information including the TCP port number of the serial port device and the IP address of the serial machine connected to the serial port device; distinguishing the level of information output to the file storage module using the TCP port number of the serial port device and the IP address of the serial machine connected to the serial port device; and when outputting information to the file storage module, segmenting the corresponding log file and adding a timestamp to the segmented log file.
[0012] This system effectively manages port information for multiple TCP ports using configuration files, and manages the file storage module and logs based on this port information. It also facilitates hierarchical differentiation of output from different TCP ports and allows for file splitting by size for easy browsing.
[0013] In an optional implementation, after registering the port information corresponding to the multiple TCP ports using a pre-configured configuration file, the processing method further includes: periodically monitoring the configuration file using a pre-configured WatchDog module; when a change in the configuration file indicates the addition of a serial port device, registering the corresponding port information, and adding a corresponding layer using the TCP port number of the newly added serial port device and the IP address of the serial machine connected to the newly added serial port device.
[0014] The pre-configured WatchDog module is used to periodically monitor and manage configuration files. Adding a new serial port device does not require a system restart, and when an upstream device of the new serial port device is connected, it can be used immediately with log output.
[0015] In an optional implementation, the pre-configured WatchDog module is further configured to: reset the timer when an I / O operation is detected; and determine a program fault and initiate a program reset when the timer is not reset within a preset time interval.
[0016] Use the WatchDog module to monitor system health. When there are problems with the system itself or when external factors cause problems, the system will automatically reset.
[0017] In an optional implementation, when communicating with multiple TCP ports, the processing method further includes: real-time monitoring of the connection status with the multiple TCP ports; and when a connection with one or more of the multiple TCP ports fails, adding the corresponding connection task back to the first queue pool and waiting for reconnection.
[0018] Ports that fail to connect may be in a serial port not connected state. Therefore, if a serial device is connected later, plug-and-play functionality will be implemented. Furthermore, the first queue pool continuously attempts to connect, ensuring plug-and-play functionality when a new device connects to the serial port.
[0019] In an optional implementation, when communicating with multiple TCP ports, the processing method further includes: for a successfully connected TCP port, sending a heartbeat packet at a preset time interval to maintain continuous asynchronous reception of the TCP port's output information.
[0020] Maintaining an active connection prevents the serial port from disconnecting from the system due to prolonged lack of I / O; sending heartbeat packets helps determine if the connection between the system and the serial port is normal.
[0021] According to a second aspect of this application, a file server is provided, the file server comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the processor executing the computer program to implement the above-described processing method.
[0022] According to a third aspect of this application, a machine-readable storage medium is provided, on which instructions are stored, causing a machine to perform the above-described processing method.
[0023] According to a fourth aspect of this application, an industrial serial communication system is provided, the industrial serial communication system including 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 using a Linux virtual machine for application deployment, and the file server also being configured with a log management service to enable the user terminal to search, monitor, and alarm on the output logs.
[0024] In an optional implementation, the serial port device is further configured to convert the physical port of the serial port device electrically connected to it into a TCP port, and the file server includes a file storage module configured to store the output information of the serial port device.
[0025] This industrial serial communication system implements asynchronous communication processing based on coroutines, eliminating CPU context switching time slices and thus reducing CPU resource overhead. The system also allows online viewing of I / O output files via a web browser, eliminating the need to log in to the serial device or virtual machine. I / O output files are sorted by size and timestamps are appended line by line based on content, facilitating easy location of I / O output file timestamps.
[0026] Through the above technical solution, the processing method for serial port communication provided in this application embodiment utilizes a first queue pool to store element information corresponding to multiple ports when communicating with multiple TCP ports; when a connection is successfully established with one or more TCP ports, the element corresponding to one or more TCP ports is added to a pending processing list; when one or more TCP ports in the pending processing list have a cache mark, the element information corresponding to the one or more TCP ports with the cache mark is added to a preparation list, and the output information of the TCP ports in the preparation list is received; and when connecting with one or more TCP ports, the I / O operation to be generated in the next process is predicted, and the process is marked with an asynchronous keyword. 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. This application embodiment configures a pending processing list, a preparation list, a cache mark, and an asynchronous keyword based on coroutine technology, realizing the processing of asynchronous serial port communication without CPU context switching time slices, thereby reducing CPU resource overhead. Because of the use of coroutine technology, there is virtually no heap memory usage. At the same time, due to its performance advantage, the buffer occupies less time in memory and can be written to the file storage module more quickly, thereby reducing memory resource overhead.
[0027] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures and processes shown in the description and the accompanying drawings. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 This is a flowchart illustrating a processing method for serial communication provided in an exemplary embodiment of this application.
[0030] Figure 2 This is a schematic diagram of the system topology provided in an exemplary embodiment of this application.
[0031] Figure 3 This is a flowchart illustrating the processing method of an exemplary embodiment of this application.
[0032] Figure 4 This is a schematic diagram of TCP port communication according to an exemplary embodiment of this application. Detailed Implementation
[0033] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0034] Before explaining the embodiments of this application in detail, the technical terms involved in this application will be explained as shown in Table 1.
[0035] Table 1
[0036]
[0037]
[0038] Figure 1 This is a flowchart illustrating a processing method for serial communication provided in an exemplary embodiment of this application, which can be applied to a file server. The processing method includes the following steps:
[0039] Step S110: When communicating with multiple TCP ports, use the first queue pool to store the element information corresponding to the multiple TCP ports.
[0040] In this embodiment of the application, the first queue pool is, for example, a FIFO queue pool, which is used to store element information corresponding to multiple ports.
[0041] Please refer to Figure 2 For example, when a file server communicates with multiple serial devices, each serial device connects to a serial port machine. The serial port machine can convert the physical port of the serial device to a TCP port, enabling downstream communication between the file server and multiple serial devices. For instance, the serial port 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 this application, when communicating with multiple TCP ports, the processing method may further include: registering port information corresponding to multiple TCP ports using a pre-configured configuration file, wherein the port information may include the TCP port number of the serial port device and the IP address of the serial machine to which the serial port device is connected; distinguishing the level at which information is output to the file storage module using the TCP port number of the serial port device and the IP address of the serial machine to which the serial port device is connected; and when outputting information to the file storage module, segmenting the corresponding log file and adding a timestamp to the segmented log file.
[0043] For example, this application embodiment can use a Linux virtual machine to deploy the application on a file server. Within the Linux virtual machine, a configuration file can be pre-configured to register the IP address and corresponding TCP port number of the serial port device, as well as unused TCP port numbers. As described above, when a serial device connects to a serial port machine, the serial port machine can convert the physical port of the serial device to a TCP port. The TCP port can conform to preset rules, and the rules for the TCP port numbers of multiple serial ports can be similar. Preferably, this application embodiment can pre-configure the TCP port number setting rules. For example, the default TCP port numbers for the NCOM660 (RS232 / TTL) industrial serial port machine are 5000, 5100, 5200...6400, 6500, a total of 16 port numbers. The configuration file can register the number of port numbers, and the corresponding TCP port number can be resolved based on the number. Multiple serial ports are configured with different IP addresses and connected to a local area network. The serial devices are connected to the serial port machine, for example, using a TTL-to-RJ45 cable.
[0044] In this embodiment, the file server may include a file storage module (e.g., a folder). The TCP port number of the serial port device and the IP address of the serial machine connected to the serial port device can be used to distinguish the hierarchy of information output to the file storage module. The hierarchy of I / O output information can represent the hierarchy of folders, distinguished by, for example, "ip" and "port" numbers, with output in different folders. In a preferred embodiment of this application, before writing I / O output information to the file storage module, the bytes of the output information can be re-encoded, and timestamps can be added line by line to identify the time of serial port events. The log file is segmented, and timestamps are added to the segmented log file. For example, "SerialLog / 192.168.1.1 / 5100 / serial_2024_1207_1450.log".
[0045] Furthermore, by setting up an Nginx web file service in a Linux virtual machine and connecting it to a local area network, users can conveniently preview I / O output information online. In a preferred embodiment of this application, Loki or ELK log management services can be used to enable users to search, monitor, and issue alerts on I / O output logs.
[0046] In a preferred embodiment of this application, after registering port information corresponding to multiple TCP ports using a pre-configured configuration file, the processing method may further include: periodically monitoring the configuration file using a pre-configured WatchDog module; when a change in the configuration file indicates the addition of a serial port device, registering the corresponding port information, and adding a corresponding layer using the TCP port number of the newly added serial port device and the IP address of the serial machine connected to the newly added serial port device.
[0047] Using pre-configured configuration files, adding a new serial port device does not require restarting the file server program. When a new serial port device is connected to an upstream device, it is plug-and-play and can directly output logs. Furthermore, if configuration items are removed from the configuration file, for example, removing 192.168.1.1, the file server will not actively disconnect the serial port device with the corresponding IP address. If the serial port device itself disconnects (e.g., due to network outage, power failure, or a broken serial cable), it will not be automatically added to the first queue pool, and will not be automatically iterated through again for that IP address in the configuration file, nor will it attempt to reconnect. In other words, if an IP address is physically disconnected, it will be added to the first queue pool. The corresponding TCP port remains in a non-physically connected state and is continuously added to the first queue pool in a loop according to the configuration file, enabling plug-and-play functionality.
[0048] In a preferred embodiment of this application, the pre-configured WatchDog module can also be configured to: reset the timer when an I / O operation is detected; and determine a program fault and initiate a program reset when the timer is not reset within a preset time interval.
[0049] Following the example above, the WatchDog module can monitor the system's operating status in real time. If the watchdog timer does not reset within a 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, configuring the WatchDog module (also known as a watchdog timer) can include: when the system is running normally and generating I / O, the system can periodically "feed" the watchdog, i.e., reset the watchdog timer to start counting again; if the watchdog is not "fed" at a specified time, the system may be in an abnormal state, causing the system program to reset. Furthermore, the WatchDog module can also be configured to: periodically monitor the above configuration file; when changes in the configuration file indicate the addition of a serial port device, register the corresponding port information, and use the TCP port number of the new serial port device and the IP address of the serial machine connected to the new serial port device to add the corresponding level in the file storage module (e.g., a folder).
[0051] Step S120: When a connection to one or more TCP ports is successfully established, add the element corresponding to one or more TCP ports to the pending list. When one or more TCP ports in the pending list have a cache mark, add the element information corresponding to one or more TCP ports with a cache mark to the preparation list, and receive the output information of the TCP ports in the preparation list.
[0052] The output information of the TCP port can be understood as the raw data from the downstream TCP port of the serial port machine. Please refer to [link / reference]. Figure 3 For example, when communicating with multiple TCP ports, a FIFO queue pool is used to store the element information corresponding to multiple ports. Taking 100 TCP ports as an example, the initial state of the FIFO queue pool includes the element information corresponding to the 100 TCP ports. When 60 of the 100 TCP ports successfully connect to the file server, the elements corresponding to these 60 TCP ports are added to the pending list (e.g., a pre-configured pending list). When 25 TCP ports in the pending list have a buffer flag (e.g., buffer), the element information corresponding to these 25 TCP ports with a buffer flag is added to the ready list (e.g., a pre-configured ready list), and the output information of the TCP ports in the ready list is received.
[0053] In a preferred embodiment of this application, for one or more TCP ports with a cached flag, after receiving the corresponding output information, the element information of the corresponding TCP port is added back to the pending list.
[0054] Continuing with the example above, after reading the 25 TCP ports marked with a buffer, they are added back to the pending list. Adding them to the pending list allows for a re-evaluation of whether a buffer exists, instead of continuing to synchronously wait for the buffer to appear.
[0055] In a preferred embodiment of this 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 a connection with one or more of the multiple TCP ports fails, adding the corresponding connection task back to the first queue pool and waiting for reconnection.
[0056] Please refer to Figure 3 For example, as described above, when connecting to multiple TCP ports, a FIFO queue pool is used to store element information for multiple ports and to perform connection status checks, port buffer presence checks, and port anomaly checks. When a connection to one or more TCP ports fails, the corresponding connection task is added back to the first queue pool, waiting for reconnection. Ports that failed to connect may be in a serial port not connected state; therefore, if a serial device is connected later, plug-and-play functionality is implemented.
[0057] In a preferred embodiment of this application, when communicating with multiple TCP ports, the processing method may further include: for a successfully connected TCP port, sending a heartbeat packet at a preset time interval to maintain continuous asynchronous reception of the TCP port's output information.
[0058] For example, for a successfully connected TCP port, a heartbeat packet can be sent every 15 seconds. When the TCP port has a buffer, I / O can be received. After processing within the system, the I / O is written to the file storage module. This maintains the connection's active state and prevents the serial device from actively disconnecting from the system due to prolonged lack of I / O. Sending heartbeat packets can determine whether the connection between the system and the serial device is normal.
[0059] Step S130: When connecting to one or more TCP ports among multiple TCP ports, predict the I / O operation that the next process will produce, and mark the process with the asynchronous keyword. 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.
[0060] I / O operations refer to data exchange across devices. The asynchronous keyword (await) can be configured to wait for an asynchronous operation to complete. This asynchronous operation can include asynchronous function calls, etc. Using await allows the program to wait for the asynchronous operation to complete without blocking the main thread, thus achieving concurrent execution.
[0061] In a preferred embodiment of this application, the asynchronous keyword can also be configured to generate a corresponding task stack and add it to the pending list. This embodiment may also include a management stack and a list. The pending list can be configured to store task stacks waiting for I / O operations to complete; the preparation list can be configured to store stacks that have completed I / O operations.
[0062] For example, for functions called in the next process, the I / O that will occur can be predicted. The process is marked with await, which means that when the current operation encounters I / O blocking, the operating system is allowed to schedule CPU resources to other executable tasks.
[0063] As described above, embodiments of this application provide a pre-configured pending list and ready list. Non-blocking I / O task stacks can be added to the pending list; that is, the pending list stores all task stacks waiting for I / O operations to complete, ensuring they can resume execution after I / O is complete. Simultaneously, other tasks that can continue execution can be scheduled from the ready list to fully utilize CPU resources. Furthermore, when a task's I / O operation completes, it can be removed from the pending list and its task stack added back to the ready list. At this time, the WatchDog timer can be reset to mark that the task has finished waiting and can continue execution.
[0064] Accordingly, the processing method for serial port communication provided in this application embodiment utilizes a first queue pool to store element information corresponding to multiple ports when communicating with multiple TCP ports; when a connection is successfully established with one or more TCP ports, the elements corresponding to one or more TCP ports are added to a pending processing list; when one or more TCP ports in the pending processing list have a cache mark, the element information corresponding to the one or more TCP ports with the cache mark is added to a preparation list, and the output information of the TCP ports in the preparation list is received; and when connecting with one or more TCP ports, the I / O operation to be generated in the next process is predicted, and the process is marked with an asynchronous keyword. 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. This application embodiment configures the pending processing list, preparation list, cache mark, and asynchronous keyword based on coroutine technology, realizing the processing of asynchronous serial port communication without CPU context switching time slices, thereby reducing CPU resource overhead. Because of the use of coroutine technology, there is virtually no heap memory usage. Furthermore, due to performance advantages, the buffer spends less time in memory, allowing for faster writing to the file storage module and reducing memory resource overhead. In terms of reliability, this embodiment reconnects in case of serial port abnormalities and resets in case of unexpected errors, restarting the application. Functionally, it allows serial devices to be plugged into a serial port machine without configuration, and I / O output can be viewed directly at a specified path.
[0065] This application also provides a file server, which may include: a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor executes the computer program to implement the above-described processing method.
[0066] This application also provides a machine-readable storage medium storing instructions that cause a machine to perform the above-described processing method.
[0067] This application also provides an industrial serial communication system, which may include a serial port device, a serial port computer 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 utilizes a Linux virtual machine for application deployment and is also configured with a log management service to enable the user terminal to search, monitor, and issue alarms for the output logs.
[0068] In a preferred embodiment of this application, the serial port device is further configured to convert the physical port of the serial port device electrically connected to it into a TCP port, and the file server includes a file storage module configured to store the output information of the serial port device.
[0069] In the preferred embodiment of the application, 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 the process 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 For example, the configuration of an industrial serial communication system can include: connecting serial devices to serial machines, with the serial machine converting the physical serial port to a TCP port; configuring multiple serial machines with different IPs and connecting them to a local area network (LAN); and connecting the serial devices to the serial machines using a TTL-to-RJ45 cable. A Linux virtual machine is used to store the output information of the serial devices and connect it to the LAN. Within this Linux virtual machine, an Nginx web file service is set up and connected to the LAN for users to preview I / O output files online. The application corresponding to the above processing method is deployed within the Nginx virtual machine, and a daemon process is used to monitor the application. This application can be restarted by the daemon process after a reset via the WatchDog module.
[0071] In Linux virtual machines, configuration files can be pre-configured to register the IP address and corresponding TCP port number of serial devices, as well as unused TCP port numbers. Preferably, TCP port number setting rules are constrained, and the configuration file only needs to register the number of port numbers; the application resolves the TCP port number based on this number. For I / O output files, the TCP port number of the serial device and the IP address of the serial machine to which it is connected can be used to distinguish the hierarchy of I / O output information. Furthermore, logs are segmented by size, and timestamps are added to the segmented log files. This enables I / O output files to rotate by size and append timestamps line by line, facilitating the location of events.
[0072] In the file service system, the pre-configured WatchDog module is used to monitor the configuration file periodically. When a change in the configuration file indicates the addition of a serial port device, the corresponding port information is registered, and the corresponding level is added using the TCP port number of the new serial port device and the IP address of the serial machine connected to the new serial port device.
[0073] When establishing a connection between the file server and the TCP port, if the handshake fails, a retry is performed periodically. This TCP port may not be in serial port access mode at first; if a serial device is connected later, plug-and-play functionality is implemented. After a successful connection, a heartbeat packet is sent every preset time interval (e.g., 15 seconds). When a TCP port has available buffer, I / O reception is performed, and after internal processing, I / O is performed to write the data to the file storage module.
[0074] Furthermore, if a TCP port has no I / O output for an extended period, it may be as expected, or it may indicate an abnormal state of the serial device or serial connection cable. In this case, it may still maintain a heartbeat, but will not actually output I / O. 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 timestamps can be added line by line to identify the time of the serial port event.
[0075] When a file server connects to multiple TCP ports, a FIFO queue pool can be used to store element information for these TCP ports. This allows for connection status checks, checks for buffer availability on ports, and port anomaly detection. For asynchronous I / O processing of multiple serial port machines and multiple TCP ports, this can be achieved as follows: Figure 3 As shown. Furthermore, for the function or iterator called by the next process, the I / O that will occur can be predicted, and the process is 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 port communication system provided in this application embodiment implements asynchronous communication processing based on coroutines, eliminating CPU context switching time slices and thus reducing CPU resource overhead. Verification shows that in a production environment with 600 TCP ports, it actually consumes 30% of the resources of a single CPU core, and the actual physical memory usage is 55MB. Furthermore, this industrial serial port communication system also allows online viewing of I / O output files on a web browser, eliminating the need to log in to the serial port device or virtual machine. The I / O output files are rotated by size, and timestamps are appended line by line, facilitating the location of events.
[0077] It should be noted that the control device, machine-readable storage medium, and industrial serial communication system described above can implement the processing method provided in the above embodiments. For specific implementation details, please refer to the description of the processing method in the above embodiments, which will not be repeated here.
[0078] It is understood that the circuit structures, names, and parameters described in the above embodiments are merely examples. Those skilled in the art can also make readily conceived combinations and adjustments to the structural features of the above embodiments according to their needs, and the concept of this application should not be limited to the specific details of the above examples.
[0079] Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions 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 this application.
Claims
1. A processing method for serial machine communication, characterized by, The processing method comprises: storing element information corresponding to a plurality of TCP ports in a first queue pool when communicating with the plurality of TCP ports; when connection with one or more TCP ports in the plurality of TCP ports is successful, adding elements corresponding to the one or more TCP ports to a to-be-processed linked list, adding element information corresponding to one or more TCP ports with a cache flag in the to-be-processed linked list to a preparation linked list, and receiving output information of the TCP ports in the preparation linked list; and when connection with one or more TCP ports in the plurality of TCP ports is successful, predicting I / O operations generated in a next process, and marking the process with an asynchronous keyword, the asynchronous keyword being used to indicate that, when an I / O block is encountered, the current operation allows the operating system to schedule CPU resources to other execution tasks; The processing method further comprises: registering port information corresponding to the plurality of TCP ports by using a preconfigured configuration file, the port information comprising a TCP port number of a serial device and an IP address of a serial machine connected by the serial device; distinguishing a level of information output to a file storage module by using the TCP port number of the serial device and the IP address of the serial machine connected by the serial device; and when outputting information to the file storage module, cutting a corresponding log file, and adding a timestamp to the cut log file.
2. The treatment method according to claim 1, characterized in that, The processing method further comprises: for the one or more TCP ports with the cache flag, after receiving corresponding output information, re-adding element information of the corresponding TCP ports to the to-be-processed linked list.
3. The treatment method of claim 1, wherein The asynchronous keyword is configured to generate a corresponding task stack and add the task stack to the to-be-processed linked list, and the processing method further comprises a management stack and a linked list, the to-be-processed linked list is configured to store task stacks waiting for completion of I / O operations, the preparation linked list is configured to store stacks of completed I / O operations.
4. The treatment method of claim 1, wherein After the registration of the port information corresponding to the plurality of TCP ports by using the preconfigured configuration file, the processing method further comprises: timely monitoring the configuration file by using a preconfigured WatchDog module; when a change in the configuration file shows that a serial device is added, registering corresponding port information, and adding a corresponding level by using a TCP port number of the added serial device and an IP address of a serial machine connected by the added serial device.
5. The treatment method according to claim 4, characterized in that, The preconfigured WatchDog module is further configured to: when an I / O operation is monitored, resetting a timer; and when the timer is not reset for more than a preset time interval, determining a program failure, and initiating a program reset.
6. The treatment method of claim 1, wherein When communicating with the plurality of TCP ports, the processing method further comprises: real-time monitoring connection states of the plurality of TCP ports; and when connection with one or more TCP ports in the plurality of TCP ports is not successful, re-adding a corresponding connection task to the first queue pool and waiting for re-connection.
7. The treatment method of claim 5, wherein When communicating with the plurality of TCP ports, the processing method further comprises: For the TCP port connected successfully, a heartbeat packet is sent once every preset time interval to keep the output information of the TCP port continuously received asynchronously.
8. A file server, characterized by The file server comprises 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 processing method according to any one of claims 1-7.
9. A machine-readable storage medium, characterized in that, The machine readable storage medium stores instructions which cause the machine to execute the processing method according to any one of claims 1-7.
10. An industrial serial machine communication system, characterized by The industrial serial port machine communication system comprises a serial port device, a serial port machine for electrically connecting the serial port device and the file server of claim 8, and a user terminal electrically connected with the file server, The file server deploys application programs by using a Linxu virtual machine, The file server is further configured with a log management service to realize searching, monitoring and alarming of the output log by the user terminal.
11. The industrial serial machine communication system of claim 10, wherein, The serial port machine is further configured to convert the physical port of the serial port device electrically connected therewith into a TCP port, The file server comprises a file storage module configured to store the output information of the serial port device.
Citation Information
Patent Citations
Method for supporting data disconnection retransmission and serial port server
CN115086104A