A multi-channel serial port communication management method based on time-division multiplexing mechanism
By introducing a serial port management APP with a time-sharing multiplexing mechanism into the power edge computing terminal products, it provides multiple working modes, solves access conflicts and resource allocation difficulties caused by insufficient serial port equipment, and realizes the stability, flexible sharing of serial port resources and the reliability of data transmission.
Patent Information
- Application Number
- CN202210962354.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-11
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2042-08-11
AI Technical Summary
In the prior art, the number of physical serial devices of power edge computing terminal products is limited, resulting in failure to open the device, disordered data frames, and partial loss of data when multiple APPs compete for use, and the resource allocation cannot be effectively managed and coordinated.
The serial port management APP based on the time-sharing multiplexing mechanism is adopted, which provides three working modes: master mode, slave mode and exclusive mode. The physical serial port equipment is uniformly managed through the serial port management APP, accessed on a first-come, first-served basis, and serial port mode changes are managed through the MQTT library and configuration files, supporting priority and mode switching.
It realizes that multiple APPs can share serial port resources stably and flexibly in power edge computing terminal products, solves the problems of device access conflicts and insufficient resources, and ensures the integrity and reliability of data transmission.
Smart Images

Figure CN115328836B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a serial port communication management method, specifically a multi-channel serial port communication management method based on a time-division multiplexing mechanism, and belongs to the technical field of power edge computing terminal products. Background Art
[0002] Current technologies lack effective management of physical serial port devices. When a data acquisition app needs to use a serial port device, it directly opens the corresponding "device node" for exclusive use. Due to the limited number of physical serial port devices, if multiple apps require serial port access, coordination becomes impossible, requiring manual resource allocation. The fusion terminal device provides four physical serial communication interfaces, corresponding to four standard "character stream devices" within the system.
[0003] Due to the inherent low speed, no encapsulation protocol, and exclusive access requirements of serial character devices, it becomes very difficult for multiple acquisition apps to use serial port devices together. Problems such as device opening failure, data frame confusion, and partial data loss may occur, ultimately resulting in all devices being unable to use the serial port for communication. In most cases, the number of serial port resources cannot meet actual needs. Summary of the Invention
[0004] The purpose of the present invention is to provide a multi-channel serial port communication management method based on a time-division multiplexing mechanism in order to solve at least one of the above technical problems.
[0005] The present invention achieves the above-mentioned object through the following technical solutions: a multi-channel serial port communication management method based on a time-sharing multiplexing mechanism, including a serial port management app as a bridge for interaction between micro-applications and physical serial port devices. The serial port management app calls the actual serial port, is responsible for processing the messages interacting between the device and the micro-application, and provides services for the micro-application;
[0006] The serial port management APP includes three working modes covering all serial port application scenarios: master mode, slave mode and exclusive mode. When the serial port mode is modified through the management APP, it will actively broadcast and send a "serial port mode change notification" to inform all micro-applications of the current serial port working mode and the corresponding mode configuration parameters; after the serial port management APP is restarted, it will also broadcast and send a "serial port mode change notification" message;
[0007] The communication management method of the serial port management APP includes the following steps:
[0008] Step 1: Start the program, host the physical serial port device, and provide a device access conflict solution based on the time-sharing multiplexing principle through protocol encapsulation and message queue;
[0009] Among them, this solution uses the serial port management app to host the physical serial port device. That is, the serial port management app opens the physical serial port device uniformly, and other apps access the physical serial port through the communication protocol provided by this app. During the access period, it follows the first-come, first-served principle;
[0010] Step 2: Initialize the MQTT library, establish an MQTT link and subscribe to related topics;
[0011] Step 3: Load the serial port management app configuration file and check the configuration file compliance. If the configuration file reading fails or the configuration is abnormal, regenerate the configuration file according to the default status;
[0012] Step 4: Create the corresponding serial port channel processing thread according to the configuration file content and start it;
[0013] Step 5: Monitor the serial port mode change message in real time, and perform serial port mode change processing after receiving the serial port mode change message;
[0014] Step 6: After the serial port mode is changed, terminate the original serial port processing thread and recreate a serial port processing thread that conforms to the changed serial port mode;
[0015] Step 7: The main program continues to loop and wait for the serial port mode change message.
[0016] As a further solution of the present invention: the serial port management APP provides a priority processing mechanism with a total of 16 levels from 0 to 15. The smaller the number, the higher the priority, and high-priority requests will be processed first.
[0017] As a further solution of the present invention: the serial port management APP is responsible for the communication management of the 4 serial ports (RS485 or RS232) of the fusion terminal, does not participate in specific business functions, and each serial port (RS485 or RS232) has three working modes: master mode, slave mode and exclusive mode. The authority to switch the serial port working mode is managed by the master station or the bureau, supports remote setting and local modification, and the serial port working mode can be set by modifying the local configuration file and the dedicated JSON interface.
[0018] As a further solution of the present invention: the three working modes of the serial port management APP specifically include:
[0019] The main mode is used to communicate with the serial port when the acquisition app needs to use the serial port to collect data and the single communication time is short;
[0020] The slave mode is used when the APP needs to communicate with the master station or host computer through the serial port. Multiple APPs in the fusion terminal can share a physical serial port in a time-sharing manner to communicate with their own master station or host computer respectively. The APP is usually in a silent state and does not actively send data. It responds after receiving the request data frame from the corresponding master station;
[0021] The exclusive mode provides full serial port functionality in a "specific scenario" and is not shared with other apps. It exclusively occupies a physical serial port. The "specific scenario" refers to when devices using this serial port for communication need to completely and exclusively use the serial port resources when interacting with data. Sharing the serial port resources with other devices or apps may cause communication anomalies such as frame reception and transmission errors, frame sequence errors, and frame check errors.
[0022] As a further solution of the present invention: the master mode is that the serial port can be accessed by multiple APPs together without interfering with each other; in this mode, the serial port only supports master-slave mode, with the fusion terminal side as the master and the end device as the slave; supports devices with different communication parameters; when different micro-applications access the end device through the serial port management APP, the physical serial port is time-shared according to the "preemption" and "priority" principles; when the acquisition APP needs to use the serial port to collect data and the single communication time is short, the master mode is used to communicate with the serial port; the steps are:
[0023] Step 1: The serial port management app starts running and broadcasts the working mode of each serial port;
[0024] Step 2: Data acquisition APP1 sends a serial data sending request command (carrying serial port parameters and data request frame), and the request priority is "medium";
[0025] Step 3: The serial port management app receives the data sending request command and performs a compliance check on it. If the check passes, it is placed in the data sending queue and prepared for sending;
[0026] Step 4: At this time, if the data acquisition APP2 also sends a serial port data sending request command with a request priority of "low", the serial port management APP will insert this sending request into the end of the data sending queue after receiving this command and passing the compliance check;
[0027] Step 5: If the data acquisition APP3 sends a serial data sending request command with a request priority of "medium" at this time, the serial port management APP will receive this command and pass the compliance check. If it finds that the priority of the current request command is higher than the priority of the request command at the end of the data sending queue, it will insert this request into the previous position of the end of the current data request queue according to the priority scheduling principle;
[0028] Step 6: The serial port management APP checks the data sending queue for unprocessed requests, processes them in order, sets the serial port according to the serial port parameters given in each data sending request, and then sends the data. It then opens the data receiving window according to the "frame timeout" and "byte timeout" given in the data sending request. After the data is received, it sends the received content to the corresponding data sending request APP;
[0029] Step 7: After successfully processing a queue send request command, the queue node that has completed the processing is destroyed, and then the next queue send request command is processed.
[0030] As a further solution of the present invention: the slave mode is that the serial port can be used by multiple APPs to share the data received by the serial port; when the serial port works in slave mode, the serial port parameters can only be modified by the management APP or configuration text, and the micro-application cannot modify the serial port parameters; when the serial port works in slave mode, the micro-application needs to register its own information to the corresponding serial port through the "slave mode registration" interface so that the serial port management APP can establish a correspondence between the physical serial port and the micro-application; the serial port is in data monitoring state, and when data is received, the data will be sent to each APP that registers the serial port; the serial port in slave mode can only send data response frames and cannot actively send data request frames; when it is necessary to communicate with the master station through the serial port and the fusion terminal side is a slave, use the slave mode; generally, the fourth serial port defaults to slave mode; the steps are:
[0031] Step 1: The serial port management app starts running and broadcasts the working mode of each serial port;
[0032] Step 2: The master communication APP1 that needs to use this serial port to communicate with the master (host computer) sends a "serial port slave mode APP registration" command to the serial port management APP to inform the serial port management APP that the master communication APP1 is aware of the data frames received on this serial port and needs it to forward the received serial port data to the master communication APP1;
[0033] Step 3: The serial port management app continuously receives data from the serial port in "serial port slave" mode and determines whether a complete frame has been received according to a specific byte timeout. Once a complete frame is received, the frame data is sent to the designated apps in sequence according to the app information recorded in the "slave mode registered app list";
[0034] Step 4: The APP that has sent the "Serial Port Slave Mode APP Registration" command, such as the master communication APP1, receives the data frame, parses it, and if a response is required, generates a response data frame and sends the response data frame through the serial port data send command;
[0035] Step 5: The APP that has not sent the "Serial Port Slave Mode APP Registration" command will not receive the serial port data received by the serial port management APP;
[0036] Step 6: When multiple master communication apps register their information to the serial port management app at the same time, all registered apps will receive the data frames received by the serial port. At this time, each app needs to identify the data frames according to its own business rules. It only needs to respond if it confirms that the data frames are its own business frames. Otherwise, it should ignore the received data frames.
[0037] As a further solution of the present invention: the exclusive mode is that the serial port can only be used by the exclusive APP, and the exclusive APP has full use rights of this serial port; the non-exclusive APP cannot use this serial port to send data, nor will it receive data from this serial port; the serial port exclusive mode is modified by the management APP or configuration file, and the exclusive APP name is specified when modifying; in the serial port exclusive mode, the exclusive APP is allowed to set the serial port parameters each time data is sent; the steps are:
[0038] Step 1: The management party, including the management master station and manual personnel, specifies that a serial port is in exclusive mode and specifies exclusive APP1 information;
[0039] Step 2: APP1 with exclusive permissions sends data through this serial port, and the serial port management APP processes it;
[0040] Step 3: APPn that does not have exclusive permission sends data through this serial port, and the serial port management APP rejects it;
[0041] Step 4: After the serial port management APP receives the data frame of the serial port, it will immediately send this data to APP1 with exclusive full selection.
[0042] This invention has the beneficial effect of completely resolving the issues of limited serial port device resources, device access conflicts, and the inability of multiple apps to flexibly use physical serial ports in power edge computing terminal products. During the inspection and pilot testing of new converged terminal products, it provides a highly stable and flexible solution for serial port data sharing and access for "collection apps" (such as energy meter collection, circuit breaker collection, and temperature and humidity collection) and "master station communication apps" (such as low-voltage centralized metering apps and IEC101 apps). BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 Flowchart of the present invention;
[0044] Figure 2 Framework diagram of the present invention;
[0045] Figure 3 The main mode workflow diagram of the present invention;
[0046] Figure 4 The main mode data interaction flow chart of the present invention;
[0047] Figure 5 The present invention is a flowchart of the interaction of slave mode data;
[0048] Figure 6 Exclusive mode data receiving flow chart of the present invention;
[0049] Figure 7 Exclusive mode data transmission flow chart of the present invention;
[0050] Figure 8 Exclusive mode data interaction flow chart of the present invention;
[0051] Figure 9 Flowchart of data sending request message processing of the present invention;
[0052] Figure 10 The present invention provides an abnormal reporting message processing process. DETAILED DESCRIPTION
[0053] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0054] Example 1
[0055] like Figures 1 to 2 As shown, a multi-channel serial port communication management method based on a time-sharing multiplexing mechanism includes a serial port management app that serves as a bridge for interaction between micro-applications and physical serial port devices. The serial port management app calls the actual serial port and is responsible for processing the messages interacting between the device and the micro-application, providing services for the micro-application;
[0056] The serial port management APP includes three working modes covering all serial port application scenarios: master mode, slave mode and exclusive mode. When the serial port mode is modified through the management APP, it will actively broadcast and send a "serial port mode change notification" to inform all micro-applications of the current serial port working mode and the corresponding mode configuration parameters; after the serial port management APP is restarted, it will also broadcast and send a "serial port mode change notification" message;
[0057] The communication management method of the serial port management APP includes the following steps:
[0058] Step 1: Start the program, host the physical serial port device, and provide a device access conflict solution based on the time-sharing multiplexing principle through protocol encapsulation and message queue;
[0059] Among them, this solution uses the serial port management app to host the physical serial port device. That is, the serial port management app opens the physical serial port device uniformly, and other apps access the physical serial port through the communication protocol provided by this app. During the access period, it follows the first-come, first-served principle;
[0060] Step 2: Initialize the MQTT library, establish an MQTT link and subscribe to related topics;
[0061] Step 3: Load the serial port management app configuration file and check the configuration file compliance. If the configuration file reading fails or the configuration is abnormal, regenerate the configuration file according to the default status;
[0062] Step 4: Create the corresponding serial port channel processing thread according to the configuration file content and start it;
[0063] Step 5: Monitor the serial port mode change message in real time, and perform serial port mode change processing after receiving the serial port mode change message;
[0064] Step 6: After the serial port mode is changed, terminate the original serial port processing thread and recreate a serial port processing thread that conforms to the changed serial port mode;
[0065] Step 7: The main program continues to loop and wait for the serial port mode change message.
[0066] In an embodiment of the present invention, the serial port management APP provides a priority processing mechanism with a total of 16 levels from 0 to 15. The smaller the number, the higher the priority. High-priority requests will be processed first.
[0067] In an embodiment of the present invention, the serial port management APP is responsible for the communication management of the 4 serial ports (RS485 or RS232) of the fusion terminal, and does not participate in specific business functions. Each serial port (RS485 or RS232) has three working modes: master mode, slave mode and exclusive mode. The authority to switch the serial port working mode is managed by the master station or the local party, and supports remote settings and local modifications. The serial port working mode can be set by modifying the local configuration file and the dedicated JSON interface.
[0068] In an embodiment of the present invention, the three working modes of the serial port management APP specifically include:
[0069] The main mode is used to communicate with the serial port when the acquisition app needs to use the serial port to collect data and the single communication time is short;
[0070] The slave mode is used when the APP needs to communicate with the master station or host computer through the serial port. Multiple APPs in the fusion terminal can share a physical serial port in a time-sharing manner to communicate with their own master station or host computer respectively. The APP is usually in a silent state and does not actively send data. It responds after receiving the request data frame from the corresponding master station;
[0071] The exclusive mode provides full serial port functionality in a "specific scenario" and is not shared with other apps. It exclusively occupies a physical serial port. The "specific scenario" refers to when devices using this serial port for communication need to completely and exclusively use the serial port resources when interacting with data. Sharing the serial port resources with other devices or apps may cause communication anomalies such as frame reception and transmission errors, frame sequence errors, and frame check errors.
[0072] In the embodiment of the present invention, the master mode is that the serial port can be accessed by multiple APPs without interfering with each other; in this mode, the serial port only supports the master-slave mode, with the fusion terminal side as the master and the end device as the slave; supports devices with different communication parameters; when different micro-applications access the end device through the serial port management APP, the physical serial port is time-shared according to the "preemption" and "priority" principles; when the acquisition APP needs to use the serial port to collect data and the single communication time is short, the master mode is used to communicate with the serial port; the steps are:
[0073] Step 1: The serial port management app starts running and broadcasts the working mode of each serial port;
[0074] Step 2: Data acquisition APP1 sends a serial data sending request command (carrying serial port parameters and data request frame), and the request priority is "medium";
[0075] Step 3: The serial port management app receives the data sending request command and performs a compliance check on it. If the check passes, it is placed in the data sending queue and prepared for sending;
[0076] Step 4: At this time, if the data acquisition APP2 also sends a serial port data sending request command with a request priority of "low", the serial port management APP will insert this sending request into the end of the data sending queue after receiving this command and passing the compliance check;
[0077] Step 5: If the data acquisition APP3 sends a serial data sending request command with a request priority of "medium" at this time, the serial port management APP will receive this command and pass the compliance check. If it finds that the priority of the current request command is higher than the priority of the request command at the end of the data sending queue, it will insert this request into the previous position of the end of the current data request queue according to the priority scheduling principle;
[0078] Step 6: The serial port management APP checks the data sending queue for unprocessed requests, processes them in order, sets the serial port according to the serial port parameters given in each data sending request, and then sends the data. It then opens the data receiving window according to the "frame timeout" and "byte timeout" given in the data sending request. After the data is received, it sends the received content to the corresponding data sending request APP;
[0079] Step 7: After successfully processing a queue send request command, the queue node that has completed the processing is destroyed, and then the next queue send request command is processed.
[0080] In an embodiment of the present invention, the slave mode is that the serial port can be used by multiple APPs to share the data received by the serial port; when the serial port works in slave mode, the serial port parameters can only be modified by the management APP or configuration text, and the micro-application cannot modify the serial port parameters; when the serial port works in slave mode, the micro-application needs to register its own information to the corresponding serial port through the "slave mode registration" interface so that the serial port management APP can establish a correspondence between the physical serial port and the micro-application; the serial port is in data monitoring state, and when data is received, the data will be sent to each APP that registers the serial port; the serial port in slave mode can only send data response frames and cannot actively send data request frames; when it is necessary to communicate with the master station through the serial port and the fusion terminal side is a slave, use the slave mode; generally, the fourth serial port defaults to slave mode; the steps are:
[0081] Step 1: The serial port management app starts running and broadcasts the working mode of each serial port;
[0082] Step 2: The master communication APP1 that needs to use this serial port to communicate with the master (host computer) sends a "serial port slave mode APP registration" command to the serial port management APP to inform the serial port management APP that the master communication APP1 is aware of the data frames received on this serial port and needs it to forward the received serial port data to the master communication APP1;
[0083] Step 3: The serial port management app continuously receives data from the serial port in "serial port slave" mode and determines whether a complete frame has been received according to a specific byte timeout. Once a complete frame is received, the frame data is sent to the designated apps in sequence according to the app information recorded in the "slave mode registered app list";
[0084] Step 4: The APP that has sent the "Serial Port Slave Mode APP Registration" command, such as the master communication APP1, receives the data frame, parses it, and if a response is required, generates a response data frame and sends the response data frame through the serial port data send command;
[0085] Step 5: The APP that has not sent the "Serial Port Slave Mode APP Registration" command will not receive the serial port data received by the serial port management APP;
[0086] Step 6: When multiple master communication apps register their information to the serial port management app at the same time, all registered apps will receive the data frames received by the serial port. At this time, each app needs to identify the data frames according to its own business rules. It only needs to respond if it confirms that the data frames are its own business frames. Otherwise, it should ignore the received data frames.
[0087] In an embodiment of the present invention, the exclusive mode is that the serial port can only be used by the exclusive APP, and the exclusive APP has full access to this serial port; the non-exclusive APP cannot use this serial port to send data, nor will it receive data from this serial port; the serial port exclusive mode is modified by the management APP or configuration file, and the exclusive APP name is specified when modifying; in the serial port exclusive mode, the exclusive APP is allowed to set the serial port parameters each time data is sent; the steps are:
[0088] Step 1: The management party, including the management master station and manual personnel, specifies that a serial port is in exclusive mode and specifies exclusive APP1 information;
[0089] Step 2: APP1 with exclusive permissions sends data through this serial port, and the serial port management APP processes it;
[0090] Step 3: APPn that does not have exclusive permission sends data through this serial port, and the serial port management APP rejects it;
[0091] Step 4: After the serial port management APP receives the data frame of the serial port, it will immediately send this data to APP1 with exclusive full selection.
[0092] Example 2
[0093] like Figures 3 and 4 As shown, a multi-channel serial port communication management method based on a time-sharing multiplexing mechanism includes a serial port management app that serves as a bridge for interaction between micro-applications and physical serial port devices. When the serial port management app is in master mode, its workflow includes the following steps:
[0094] 1) The serial port master mode thread starts;
[0095] 2) Open the serial port device managed by this thread;
[0096] 3) Waiting for the serial port data sending queue to see if there is a data sending request;
[0097] 4) If there is a data sending request in the current queue, first determine whether the request has exceeded the maximum task timeout. If it has, the request will be treated as a timeout and the request node will be deleted. If the timeout check is qualified, proceed to the next step of processing;
[0098] 5) Send request node information according to current data and set serial port parameters (baud rate, data bits, check mode, etc.);
[0099] 6) Write the data frame in the current data transmission request node into the physical serial port transmission buffer to send the data;
[0100] 7) After the data is sent, wait for the data response according to the frame timeout time in the current data sending request node;
[0101] 8) After receiving the response data within the frame timeout period, the complete frame is judged according to the byte timeout period until the complete data frame is received;
[0102] 9) Send the received complete data frame to the current data sending request APP.
[0103] The data interaction process includes:
[0104] 1) After the serial port management app is started, it broadcasts the current serial port working mode as the main mode;
[0105] 2) APP1 makes a data sending request;
[0106] 3) After receiving the data sending request, the serial port management app will check the compliance of the request and then put the request into the sending request queue for processing;
[0107] 4) APP2 makes a data sending request;
[0108] 5) After receiving the data sending request from APP2, the serial port management app will check the compliance of the sending request and then put the request at the end of the sending request queue to wait for processing;
[0109] 6) The serial port management app processes the sending requests in the data sending request queue in sequence until they are completed.
[0110] Example 3
[0111] like Figure 5 As shown, a multi-channel serial port communication management method based on a time-sharing multiplexing mechanism includes a serial port management app that serves as a bridge for interaction between micro-applications and physical serial port devices. When the serial port management app is in slave mode, the data interaction process of its working mode includes:
[0112] 1) After the serial port management app is started, it broadcasts that the current serial port is in slave mode;
[0113] 2) APP2 and APP3 register their own information to the serial port management APP;
[0114] 3) After receiving a complete frame of data from the physical serial port, the serial port management app sends the data to APP2 and APP3;
[0115] 4) APP2 determines that the data belongs to this APP data, replies with a response frame, and sends it to the serial port management APP;
[0116] 5) The serial port management app writes the response data into the serial port send buffer and sends the data (response);
[0117] 6) APP1 sends data to the serial port management APP. The serial port management APP determines that APP1 has not registered in slave mode and rejects the sending request.
[0118] Example 4
[0119] like Figures 6 to 8 As shown, a multi-channel serial port communication management method based on a time-sharing multiplexing mechanism includes a serial port management app that serves as a bridge for interaction between micro-applications and physical serial port devices. When the serial port management app is in exclusive mode, the data receiving process of its working mode includes:
[0120] 1) The serial port exclusive mode data receiving thread is started;
[0121] 2) Determine whether the current serial port device has been clocked in. If not, enable the serial port;
[0122] 3) Broadcast notification of sending serial port exclusive mode;
[0123] 4) Set the serial port parameters (baud rate, data bits, checksum, etc.) according to the serial port exclusive mode configuration information;
[0124] 5) Wait for serial port data in a loop. After receiving the first byte, determine the complete frame according to the byte timeout time until the complete data frame is received;
[0125] 6) Send the received complete data frame to the APP that currently owns the serial port.
[0126] The data sending process of its working mode includes:
[0127] 1) The serial port exclusive mode data sending thread starts;
[0128] 2) Determine whether the current serial port device has been clocked in. If not, enable the serial port;
[0129] 3) Waiting for the serial port data sending queue to see if there is a data sending request;
[0130] 4) If there is a data sending request in the current data sending queue, determine whether the current data sending request APP is an exclusive APP. If not, reject the sending request. If it is an exclusive APP, proceed to the next step of the processing flow;
[0131] 5) Determine whether the serial port parameters in the current data sending request node information are consistent with the current serial port parameters. If they are inconsistent, set them according to the relevant parameters in the data request node;
[0132] 6) Write the current data request to the serial port buffer to send the data.
[0133] The data interaction process of its working mode includes:
[0134] 1) After the serial port management app is started, it broadcasts that the current serial port working mode is exclusive mode exclusively for APP1;
[0135] 2) Exclusive APP1 sends serial port parameter setting commands, and the serial port management APP receives and sets them;
[0136] 3) APP2 sends a data request to the serial port management APP. After receiving the data sending request, the serial port management APP determines that APP2 is not an exclusive APP and discards the request;
[0137] 4) APP1 sends a data request to the serial port management APP. After receiving the data sending request, the serial port management APP determines that APP1 is the exclusive APP, puts the data sending request into the data sending queue, and sends the data;
[0138] 5) After receiving a complete frame of data from the physical serial port, the serial port management app sends the data to exclusive app 1.
[0139] Example 5
[0140] like Figures 9 and 10 As shown, a multi-channel serial port communication management method based on a time-sharing multiplexing mechanism includes a serial port management app that serves as a bridge for interaction between micro-applications and physical serial port devices. The serial port management app calls the actual serial port and is responsible for processing the messages interacting between the device and the micro-application, providing services for the micro-application;
[0141] The serial port management APP includes three working modes covering all serial port application scenarios: master mode, slave mode and exclusive mode. When the serial port mode is modified through the management APP, it will actively broadcast and send a "serial port mode change notification" to inform all micro-applications of the current serial port working mode and the corresponding mode configuration parameters; after the serial port management APP is restarted, it will also broadcast and send a "serial port mode change notification" message;
[0142] The communication management method of the serial port management APP includes the following steps:
[0143] Step 1: Start the program, host the physical serial port device, and provide a device access conflict solution based on the time-sharing multiplexing principle through protocol encapsulation and message queue;
[0144] Among them, this solution uses the serial port management app to host the physical serial port device. That is, the serial port management app opens the physical serial port device uniformly, and other apps access the physical serial port through the communication protocol provided by this app. During the access period, it follows the first-come, first-served principle;
[0145] Step 2: Initialize the MQTT library, establish an MQTT link and subscribe to related topics;
[0146] Step 3: Load the serial port management app configuration file and check the configuration file compliance. If the configuration file reading fails or the configuration is abnormal, regenerate the configuration file according to the default status;
[0147] Step 4: Create the corresponding serial port channel processing thread according to the configuration file content and start it;
[0148] Step 5: Monitor the serial port mode change message in real time, and perform serial port mode change processing after receiving the serial port mode change message;
[0149] Step 6: After the serial port mode is changed, terminate the original serial port processing thread and recreate a serial port processing thread that conforms to the changed serial port mode;
[0150] Step 7: The main program continues to loop and wait for the serial port mode change message.
[0151] The processing flow of the serial port management APP for sending data request messages is as follows:
[0152] 1) Data sending request message processing;
[0153] 2) Determine the compliance of the data sending request message format. If the compliance check is abnormal, discard the message;
[0154] 3) After the message compliance is determined to be legal, determine whether the data sending queue of the serial port is full. If the queue is full, the APP responds with a "queue full" message to the data sending request. If the queue is not full, the data sending request is inserted into the current serial port sending queue.
[0155] The process of the serial port management APP to process abnormal reporting messages is as follows:
[0156] 1) Handling of abnormal serial port data reception messages;
[0157] 2) Update the serial port exception handling count of the corresponding serial port and perform subsequent logical judgment: When the number of serial port exception reports is greater than 1, determine whether the current serial port send queue is empty. If it is empty, immediately perform serial port initialization (clear the serial port data request queue, clear the serial port send buffer, clear the serial port receive buffer, and reset the serial port parameters). If the current serial port send queue is not empty, the serial port initialization will be performed only when the current serial port exception report accumulates to more than 3.
[0158] 3) Send a serial port exception report response message to the serial port receiving exception message sending APP.
[0159] Working Principle: Use a serial port management app to host physical serial port devices. This means the app opens the physical serial port devices uniformly. Other apps access the physical serial port through the communication protocol provided by the app. Access is based on a first-come, first-served basis. The user selects the working mode of the serial port management app based on the type of device connected to the serial port. Switching is performed by modifying the configuration file or using the serial port mode change command. When the serial port is connected to a passive data acquisition device (such as an electricity meter), "master mode" should be used; when the serial port is connected to local maintenance master software, "slave mode" should be used; when the serial port is connected to a "balanced communication" device (with passive reading and active reporting functions), "exclusive mode" should be used.
[0160] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above and that the invention can be embodied in other specific forms without departing from the spirit or essential characteristics of the invention. Therefore, the embodiments should be considered in all respects as illustrative and non-restrictive, and the scope of the invention is defined by the appended claims, not the foregoing description, and all variations within the meaning and range of equivalents of the claims are intended to be included therein. Any reference sign in a claim should not be construed as limiting the claim to which it relates.
[0161] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.
Claims
1. A multi-channel serial port communication management method based on a time-division multiplexing mechanism, characterized by: It includes a serial port management app that serves as a bridge for interaction between micro-applications and physical serial port devices. The serial port management app calls the actual serial port, is responsible for processing the messages interacting between the device and the micro-application, and provides services for the micro-application; The serial port management APP includes three working modes covering all serial port application scenarios: master mode, slave mode and exclusive mode. When the serial port mode is modified through the serial port management APP, it will actively broadcast and send a "serial port mode change notification" to inform all micro-applications of the current serial port working mode and the corresponding mode configuration parameters; After the serial port management app is restarted, it will also broadcast a "serial port mode change notification" message; The communication management method of the serial port management APP includes the following steps: Step 1: Start the program, host the physical serial port device, and provide a device access conflict solution based on the time-sharing multiplexing principle through protocol encapsulation and message queue; Among them, this solution uses the serial port management app to host the physical serial port device. That is, the serial port management app opens the physical serial port device uniformly, and other apps access the physical serial port through the communication protocol provided by the serial port management app. During access, it follows the first-come, first-served principle; Step 2: Initialize the MQTT library, establish an MQTT link and subscribe to related topics; Step 3: Load the serial port management app configuration file and check the configuration file compliance. If the configuration file reading fails or the configuration is abnormal, regenerate the configuration file according to the default status; Step 4: Create the corresponding serial port channel processing thread according to the configuration file content and start it; Step 5: Monitor the serial port mode change message in real time, and perform serial port mode change processing after receiving the serial port mode change message; Step 6: After the serial port mode is changed, terminate the original serial port processing thread and recreate a serial port processing thread that conforms to the changed serial port mode; Step 7: The main program continues to loop and wait for the serial port mode change message.
2. The multi-channel serial port communication management method based on time division multiplexing mechanism according to claim 1, characterized in that: The serial port management APP provides a total of 16 levels of priority processing mechanism from 0 to 15. The smaller the number, the higher the priority, and high-priority requests will be processed first.
3. The multi-channel serial port communication management method based on time division multiplexing mechanism according to claim 1 is characterized in that: The serial port management APP is responsible for the communication management of the 4 serial ports of the fusion terminal, and does not participate in specific business functions. Each serial port has three working modes: master mode, slave mode and exclusive mode. The authority to switch the serial port working mode is managed by the master station or the bureau. It supports remote settings and local modifications. The serial port working mode can be set by modifying the local configuration file and the dedicated JSON interface.
4. The multi-channel serial port communication management method based on time division multiplexing mechanism according to claim 1 is characterized in that: The three working modes of the serial port management APP include: The main mode is used to communicate with the serial port when the acquisition app needs to use the serial port to collect data and the single communication time is short; The slave mode is used when the APP needs to communicate with the master station or host computer through the serial port. Multiple APPs in the fusion terminal share a physical serial port to communicate with their own master station or host computer respectively. The APP is usually in a silent state and does not actively send data. It responds after receiving the request data frame from the corresponding master station. The exclusive mode provides full serial port functionality in specific scenarios, occupies a specific physical serial port exclusively and is not shared with other apps. "Specific scenarios" refer to when devices using this serial port for data communication require exclusive use of the serial port resources. Sharing the serial port resources with other devices or apps may result in communication anomalies such as frame reception and transmission errors, frame sequence errors, and frame check errors.
5. The multi-channel serial port communication management method based on time division multiplexing mechanism according to claim 1 is characterized in that: The master mode allows the serial port to be accessed by multiple apps without interfering with each other. In the master mode, the serial port only supports the master-slave mode, with the fusion terminal side as the master and the end device as the slave. It supports devices with different communication parameters. When different micro-applications access the end device through the serial port management app, the physical serial port is time-shared according to the "preemption" and "priority" principles. When the acquisition app needs to use the serial port to collect data and the single communication time is short, the master mode is used to communicate with the serial port. The steps are: Step 1: The serial port management app starts running and broadcasts the working mode of each serial port; Step 2: Data acquisition APP1 sends a serial data sending request command with a request priority of "medium"; Step 3: The serial port management app receives the data sending request command and performs a compliance check on it. If the check passes, it is placed in the data sending queue and prepared for sending; Step 4: If the data acquisition app 2 also sends a serial data sending request command with a low priority, the serial port management app will insert the sending request into the end of the data sending queue after receiving the command and passing the compliance check. Step 5: If the data acquisition app 3 sends a serial data transmission request command with a "medium" priority, the serial port management app receives this command and passes the compliance check. If it finds that the priority of the current request command is higher than the priority of the request command at the end of the data transmission queue, it will insert this request into the previous position of the end of the current data request queue according to the priority scheduling principle. Step 6: The serial port management app checks the data sending queue for unprocessed requests, processes them in order, sets the serial port according to the serial port parameters given in each data sending request, sends the data, and then opens the data receiving window according to the "frame timeout" and "byte timeout" given in the data sending request. After the data is received, the received content is sent to the corresponding data sending request app; Step 7: After successfully processing a queue send request command, the queue node that has completed the processing is destroyed, and then the next queue send request command is processed.
6. The multi-channel serial port communication management method based on time division multiplexing mechanism according to claim 1, characterized in that: The slave mode is that the serial port can be used by multiple apps and share the data received by the serial port; When the serial port works in slave mode, the serial port parameters can only be modified by the serial port management app or configuration file. Micro applications cannot modify the serial port parameters. When the serial port works in slave mode, the micro application needs to register its own information to the corresponding serial port through the "slave mode registration" interface so that the serial port management app can establish a corresponding relationship between the physical serial port and the micro application; The serial port is in data monitoring state. When data is received, it will send the data to each APP registered with the serial port. The serial port in slave mode can only send data response frames and cannot actively send data request frames. When it is necessary to communicate with the master station through the serial port and the fusion terminal side is a slave, use the slave mode. The fourth serial port is in slave mode by default. The steps are: Step 1: The serial port management app starts running and broadcasts the working mode of each serial port; Step 2: Master communication app 1, which needs to use this serial port to communicate with the master, sends a "serial port slave mode app registration" command to the serial port management app, informing the serial port management app that master communication app 1 is aware of the data frames received on this serial port and needs it to forward the received serial port data to master communication app 1. Step 3: The serial port management app continuously receives data from the serial port in "serial port slave" mode and determines whether a complete frame has been received based on the byte timeout. Once a complete frame is received, the frame data is sent to the designated apps in sequence according to the app information recorded in the "slave mode registered app list"; Step 4: The master communication APP 1 receives the data frame from the APP that has sent the "serial port slave mode APP registration" command, parses and processes it, and if a response is required, generates a response data frame and sends the response data frame through the serial port data send command; Step 5: The APP that has not sent the "Serial Port Slave Mode APP Registration" command will not receive the serial port data received by the serial port management APP; Step 6: When multiple master communication apps register their information to the serial port management app at the same time, all registered apps will receive the data frames received by the serial port. At this time, each app needs to identify the data frames according to its own business rules. It only needs to respond if it confirms that the data frames are its own business frames. Otherwise, it should ignore the received data frames.
7. The multi-channel serial port communication management method based on time division multiplexing mechanism according to claim 1, characterized in that: The exclusive mode means that the serial port can only be used by the exclusive APP, and the exclusive APP has full access to this serial port; the non-exclusive APP cannot use this serial port to send data, nor can it receive data from this serial port; The serial port exclusive mode is modified by the serial port management app or configuration file, and the exclusive app name is specified during the modification; In the exclusive mode of the serial port, the exclusive APP is allowed to set the serial port parameters each time data is sent; the steps are: Step 1: The management party, including the management master station and manual personnel, specifies that a serial port is in exclusive mode and specifies exclusive APP1 information; Step 2: APP1 with exclusive permissions sends data through this serial port, and the serial port management APP processes it; Step 3: APPn that does not have exclusive permission sends data through this serial port, and the serial port management APP rejects it; Step 4: After the serial port management APP receives the data frame of the serial port, it will immediately send this data to APP1 with exclusive full selection.
Citation Information
Patent Citations
Bridging module for communication between room control terminal and upper computer and method thereof
CN103744365A
A mobile internet audio / video management and control system based on an internet of things
CN106341463A