Serial port multiplexing method, device, equipment, medium and product

CN122086818APending Publication Date: 2026-05-26LUXSHARE PRECISION TECH(NANJING) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
LUXSHARE PRECISION TECH(NANJING) CO LTD
Filing Date
2026-02-04
Publication Date
2026-05-26

Smart Images

  • Figure CN122086818A_ABST
    Figure CN122086818A_ABST
Patent Text Reader

Abstract

The invention discloses a serial port multiplexing method and device, equipment, a medium and a product. The method comprises the following steps: acquiring a first communication instruction corresponding to a physical serial port; determining a first resource scheduling strategy under the first working scene according to an instruction mode corresponding to the first communication instruction; based on a first resource scheduling strategy, determining a first target communication task in communication tasks corresponding to a plurality of virtual serial ports corresponding to the physical serial port; and mapping the read-write request of the first target communication task to the physical serial port. The current working scene of the serial port is automatically identified through an instruction mode, the number limitation of physical serial ports is broken through based on the resource virtualization of virtual serial ports according to the service quality requirements of different working scenes, the resources of the serial ports are dynamically and differentially distributed, the serial port communication strategy is adjusted, physical serial port hardware does not need to be added, and the communication efficiency is improved. Therefore, the multi-task parallel communication requirement can be supported, so that the optimization of the overall communication efficiency is realized under the condition that the resources are limited.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, and in particular to a serial port multiplexing method, apparatus, device, medium, and product. Background Technology

[0002] In complex embedded systems, a multi-MCU collaborative architecture is often employed. Each MCU may need to communicate with multiple external devices (such as sensors, actuators, host computers, and displays) via serial ports (UART). However, the number of hardware serial ports built into the MCU is limited, often failing to meet the ever-increasing communication demands.

[0003] Existing technologies typically employ the following methods: adding hardware by using additional serial port expansion chips (such as UART to multiplexed I / O) to increase hardware serial ports; simulating serial ports in software by using the MCU's general-purpose I / O ports to simulate serial port timing; or using a fixed switching method by using analog switches to permanently allocate or simply poll a limited number of serial ports.

[0004] However, adding hardware increases hardware costs, PCB area, and system complexity; software-simulated serial ports severely consume CPU resources, and communication baud rate and stability are difficult to guarantee, making them unsuitable for scenarios with high baud rate or high real-time requirements; fixed switching methods have rigid switching strategies that cannot be dynamically optimized according to the actual communication needs of the system (such as priority, data volume, and real-time requirements), resulting in low communication efficiency, high-priority tasks may be blocked, and serial port bandwidth cannot be fully utilized. Summary of the Invention

[0005] This invention provides a serial port multiplexing method, apparatus, device, medium, and product to achieve automatic identification of working scenarios and dynamic adjustment of serial port resources and communication strategies.

[0006] According to a first aspect of the present invention, a serial port multiplexing method is provided, comprising:

[0007] Obtain the first communication command corresponding to the physical serial port;

[0008] Based on the instruction mode corresponding to the first communication instruction, determine the first resource scheduling strategy under the first working scenario;

[0009] Based on the first resource scheduling strategy, a first target communication task is determined from the communication tasks corresponding to the multiple virtual serial ports corresponding to the physical serial port.

[0010] Map the read / write requests of the first target communication task to the physical serial port.

[0011] According to a second aspect of the present invention, a serial port multiplexing device is provided, comprising:

[0012] The instruction acquisition module is used to acquire the first communication instruction corresponding to the physical serial port;

[0013] The strategy determination module is used to determine the first resource scheduling strategy under the first working scenario based on the instruction mode corresponding to the first communication instruction.

[0014] The task determination module is used to determine a first target communication task from the communication tasks corresponding to the multiple virtual serial ports corresponding to the physical serial port, based on the first resource scheduling strategy.

[0015] The request mapping module is used to map the read and write requests of the first target communication task to the physical serial port.

[0016] According to a third aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0017] At least one processor; and

[0018] A memory communicatively connected to the at least one processor; wherein,

[0019] The memory stores a computer program that can be executed by the at least one processor, which enables the at least one processor to perform the serial port multiplexing method according to any embodiment of the present invention.

[0020] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the serial port multiplexing method according to any embodiment of the present invention.

[0021] According to a fifth aspect of the present invention, embodiments of the present invention also provide a computer program product, the computer program product including a computer program, which, when executed by a processor, implements the serial port multiplexing method of any embodiment of the present invention.

[0022] The technical solution of this invention involves: acquiring a first communication instruction corresponding to a physical serial port; determining a first resource scheduling strategy under a first working scenario based on the instruction mode corresponding to the first communication instruction; determining a first target communication task among the communication tasks corresponding to multiple virtual serial ports corresponding to the physical serial port based on the first resource scheduling strategy; and mapping the read / write requests of the first target communication task to the physical serial port. By automatically identifying the current working scenario of the serial port through the instruction mode, and based on the service quality requirements of different working scenarios, and leveraging the resource virtualization of virtual serial ports, the limitation on the number of physical serial ports is overcome. Serial port resources are dynamically and differentially allocated and serial port communication strategies are adjusted. This supports multi-task parallel communication needs without adding physical serial port hardware, thereby optimizing overall communication performance under resource-constrained conditions.

[0023] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0024] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0025] Figure 1 This is a flowchart of a serial port multiplexing method provided in Embodiment 1 of the present invention;

[0026] Figure 2 This is a schematic diagram of a serial port multiplexing device according to Embodiment 2 of the present invention;

[0027] Figure 3 This is a schematic diagram of the structure of an electronic device that implements an embodiment of the present invention. Detailed Implementation

[0028] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0029] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0030] Example 1

[0031] Figure 1 This is a flowchart of a serial port multiplexing method provided in Embodiment 1 of the present invention. This embodiment is applicable to the multiplexing of a single serial port. The method can be executed by a serial port multiplexing device, which can be implemented in hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes:

[0032] S110, Obtain the first communication command corresponding to the physical serial port.

[0033] In this embodiment, the physical serial port (UART) can be understood as an interface for communicating with external devices. The first communication command can be understood as a preset command received by the physical serial port that triggers serial communication behavior.

[0034] Specifically, the processor can monitor the data flow on the physical serial bus in real time, capture the communication command that triggers serial communication, and obtain the first communication command.

[0035] S120. Determine the first resource scheduling strategy under the first working scenario based on the instruction mode corresponding to the first communication instruction.

[0036] In this embodiment, the instruction mode can be understood as the set of characteristic attributes presented by the first communication instruction, such as baud rate, data content, protocol structure, and timing behavior corresponding to the instruction. The first working scenario can be understood as different business scenarios divided based on the service characteristics, triggering conditions, and real-time requirements of serial communication. It serves as the basis for the system to select a scheduling strategy. Working scenarios include, but are not limited to, transparent transmission scenarios, debugging scenarios, data acquisition scenarios, real-time control scenarios, and firmware upgrade scenarios. The first resource scheduling strategy can be understood as the serial port resource allocation, task execution priority, and status management rules formulated to adapt to the first working scenario, directly determining the resource usage method.

[0037] Specifically, the processor can extract key features of the first communication instruction (such as data content, baud rate, and protocol structure) as the instruction mode, analyze the instruction mode, determine the corresponding first working scenario, and then determine the resource scheduling strategy of the physical serial port in the first working scenario according to the pre-set mapping relationship.

[0038] S130. Based on the first resource scheduling strategy, determine the first target communication task from the communication tasks corresponding to the multiple virtual serial ports corresponding to the physical serial port.

[0039] In this embodiment, a virtual serial port can be understood as a software-level abstract mapping of physical serial port hardware resources, and is a logical serial port instance allocated for each specific communication session. A communication task can be understood as the specific communication requirement corresponding to each virtual serial port. The first target communication task can be understood as the communication task that currently occupies the physical serial port first among the communication tasks corresponding to multiple virtual serial ports.

[0040] Specifically, the processor can manage a virtualized serial port resource pool, which presents multiple independent virtual serial ports to upper-layer applications, each corresponding to a communication task. When multiple high-priority or mutually exclusive first working scenarios request resources simultaneously, the processor can, based on a first resource scheduling strategy combined with conflict arbitration logic, arbitrate according to preset priority and time slice rules to determine the first target communication task that should occupy the physical serial port first.

[0041] S140. Map the read / write request of the first target communication task to the physical serial port.

[0042] In this embodiment, read / write request mapping can be understood as a mapping method that converts the read / write operations of the first target communication task on the virtual serial port into actual access control of the physical serial port.

[0043] Specifically, the processor can use virtualization and other technologies to convert the read and write operations of the first target communication task on its corresponding virtual serial port into actual access instructions for the physical serial port; at the same time, it can configure the communication parameters of the physical serial port (such as baud rate and data frame format) to ensure that the first target communication task can send and receive data normally through the physical serial port.

[0044] The technical solution of this invention involves: acquiring a first communication instruction corresponding to a physical serial port; determining a first resource scheduling strategy under a first working scenario based on the instruction mode corresponding to the first communication instruction; determining a first target communication task among the communication tasks corresponding to multiple virtual serial ports corresponding to the physical serial port based on the first resource scheduling strategy; and mapping the read / write requests of the first target communication task to the physical serial port. By automatically identifying the current working scenario of the serial port through the instruction mode, and based on the service quality requirements of different working scenarios, and leveraging the resource virtualization of virtual serial ports, the limitation on the number of physical serial ports is overcome. Serial port resources are dynamically and differentially allocated and serial port communication strategies are adjusted. This supports multi-task parallel communication needs without adding physical serial port hardware, thereby optimizing overall communication performance under resource-constrained conditions.

[0045] Furthermore, based on the above embodiments, the steps of determining the first resource scheduling strategy under the first working scenario according to the instruction mode corresponding to the first communication instruction can be refined as follows:

[0046] Based on the instruction pattern and the predefined scenario rule base, the first working scenario corresponding to the first communication instruction is determined; based on the scenario policy mapping table, the first resource scheduling policy corresponding to the first working scenario is determined.

[0047] In this embodiment, the predefined scenario rule base can be understood as a rule base that automatically maps communication states to working scenarios. Essentially, it solidifies the triggering conditions, feature parameters, and judgment logic of working scenarios into a set of rules that can be recognized and executed by the processor. For example, it can be a triple rule corresponding to each type of working scenario, consisting of "feature dimension, threshold range, and judgment result." The first working scenario can be understood as all working scenarios involving serial port communication. The scenario policy mapping table can be understood as a predefined structured association table that establishes a mapping between working scenario types and corresponding resource scheduling policies.

[0048] Specifically, the processor can compare the instruction pattern with a predefined scenario rule base to determine the corresponding first working scenario. The processor can then search the scenario policy mapping table based on the first working scenario, for example, by looking up the scenario identifier of the working scenario to determine the matching first resource scheduling policy.

[0049] As a first optional embodiment of this example, after mapping the read / write request of the first communication task to the physical serial port, the method further includes:

[0050] Obtain the second communication instruction corresponding to the physical serial port; determine the second resource scheduling strategy under the second working scenario based on the instruction mode corresponding to the second communication instruction; determine the second target communication task from the communication tasks corresponding to the multiple virtual serial ports based on the second resource scheduling strategy and the first resource scheduling strategy; map the read and write requests of the second target communication task to the physical serial port.

[0051] In this embodiment, the second communication instruction can be understood as the second valid communication instruction received by the system through the serial bus after the first communication instruction, which may come from the same or different external devices / applications as the first communication instruction. The second working scenario can be understood as a specific application scenario obtained by matching the instruction pattern of the second communication instruction through a scenario rule base. The second resource scheduling strategy is the strategy that matches the second working scenario. The second target communication task can be understood as the communication task that currently needs to occupy the physical serial port first (which may be a newly triggered task or a continuation of an existing task) selected from the communication tasks corresponding to multiple virtual serial ports by combining the first and second resource scheduling strategies.

[0052] Specifically, the processor can continuously monitor the data flow of the physical serial bus, capture new valid communication instructions (i.e., the second communication instruction) during or after the execution of the task corresponding to the first communication instruction, and extract the instruction pattern of the instruction. Based on the instruction pattern of the second communication instruction, the processor can determine the corresponding second resource scheduling strategy in the manner described above. The processor can arbitrate the first and second resource scheduling strategies to ultimately determine the second target communication task that should preferentially occupy the physical serial port, and map the read / write requests of the second target communication task to the physical serial port.

[0053] For example, a pass-through scenario can be used as an example. The host computer sends a verified specific command frame (i.e., the above-mentioned instruction mode) to the main MCU (processor), for example: +++ENTER_PASSTHROUGH_MODE\r\n. The processor captures and parses this command, confirms it as a valid instruction, determines it as a pass-through scenario based on a predefined scenario rule base, and determines the corresponding resource scheduling policy as a pass-through policy through the scenario policy mapping table. The processor can immediately switch the system mode to "pass-through mode". At this time, the host computer can send custom protocol instructions using any serial port tool, just like directly connecting to the underlying UART bus, and communicate directly with any slave MCU. The processor can disable the main MCU application's interrupt handling for UART and start a dedicated "pass-through service". Once the main MCU receives a message, it immediately sends it out through UART; once the slave MCU receives data, it immediately returns it to the host computer without any parsing or buffering.

[0054] Specifically, based on the second resource scheduling strategy and the first resource scheduling strategy, the second target communication task is determined from the communication tasks corresponding to each of the multiple virtual serial ports, including:

[0055] By comparing the priority of the second resource scheduling strategy with the priority of the first resource scheduling strategy, a priority comparison result is obtained. If the priority comparison result indicates that the second resource scheduling strategy takes precedence over the first resource scheduling strategy, the communication task corresponding to the second communication instruction is taken as the second target communication task.

[0056] In this embodiment, priority can be understood as a pre-defined level that determines the priority of communication tasks corresponding to the strategy in resource contention. The priority comparison result can be understood as the conclusion obtained by comparing the priority levels of the first and second resource scheduling strategies, including three cases: the second strategy has priority, the first strategy has priority, and the two have the same priority.

[0057] Specifically, the processor can perform a quantitative or qualitative comparison of two priorities according to preset priority comparison rules (such as setting higher priority values ​​or level identifiers, or determining priorities according to a strategy type level table), and finally obtain the priority comparison result. The processor can then determine the higher-priority communication task from the priority comparison result as the second target communication task.

[0058] This configuration provides a basis for the subsequent switching and allocation of physical serial port resources, ensuring that high-priority tasks have priority access to serial port resources and meet real-time and critical communication requirements.

[0059] Furthermore, when the communication task corresponding to the second communication command is the second target communication task, mapping the read / write request of the second target communication task to the physical serial port also includes:

[0060] Map the read / write requests of the second target communication task to the physical serial port and save the complete communication state of the first target communication task.

[0061] In this embodiment, the complete communication state can be understood as all the running context information of the first target communication task when it is interrupted, including serial port hardware register configuration (such as baud rate, data frame format), software-level receive / transmit buffer data, protocol data packets that have not been parsed (partial packet data), and the current position of the protocol state machine, etc.

[0062] Specifically, the processor can extract the complete communication state of the first target communication task, generate a state snapshot of this information and store it in a dedicated buffer to ensure the complete retention of the task interruption state; and configure the communication parameters of the physical serial port (such as baud rate, data frame format, etc.) to adapt it to the needs of the second target communication task, and map the read and write requests of the virtual serial port corresponding to the second target communication task to the actual hardware interface of the physical serial port, so as to realize the second target communication task's occupation of the physical serial port and data transmission.

[0063] Furthermore, after mapping the read / write requests of the second target communication task to the physical serial port, the method also includes:

[0064] After the second target communication task is completed, the first target communication task is resumed based on the complete communication state.

[0065] Specifically, the processor can monitor the execution progress of the second target communication task in real time. When it detects that the task has completed the preset communication target, it determines that the task has ended. The processor can release the physical serial port resources, call the stored complete communication state snapshot of the first target communication task, reverse restore the communication context of the task to the position before the interruption, and remap the virtual serial port read and write requests corresponding to the first target communication task to the physical serial port, so that the task can continue to execute from the breakpoint.

[0066] The above settings enable lossless resuming of interrupted communication, ensuring the integrity and continuity of data transmission.

[0067] Furthermore, based on the above embodiments, when the resource scheduling strategy is a bandwidth round-robin strategy, the step of mapping the read / write request of the first target communication task to the physical serial port can be refined as follows:

[0068] Based on the bandwidth polling strategy, the task time slice of the first target communication task is determined; if the task time slice has not been reached, the first target communication task is suspended and the complete task communication state of the first target communication task is saved; if the task time slice is reached, the read and write requests of the first target communication task are mapped to the physical serial port, and the first target communication task is resumed based on the complete task communication state of the first target communication task.

[0069] In this embodiment, the bandwidth polling strategy can be understood as a serial port resource scheduling rule designed for soft real-time periodic tasks. Its core is to allocate a fixed-duration time slice to each task and sequentially allocate serial port resources in a cyclical manner. A task time slice can be understood as the duration of dedicated serial port resource allocation for the first target communication task.

[0070] Specifically, the processor can determine the task time slice corresponding to the first target communication task based on a bandwidth polling strategy. When the current time is not within the task time slice interval, the processor can suspend the first target communication task (unbind the first target communication task from the physical serial port and release the hardware resources of the physical serial port) and write the complete task communication state of the first target communication task to the memory buffer. When the current time reaches the task time slice, the processor can map the read and write requests of the first target communication task to the serial port, retrieve the saved complete task communication state from the memory buffer, restore the communication parameters, data buffer, and session progress, and allow the task to continue execution from the last suspended interrupt point. The first target communication task can be processed in parallel with other tasks.

[0071] For example, taking a data acquisition scenario, the processor can detect data response frames (i.e., instruction patterns) sent from a fixed address at fixed time intervals (e.g., every 2 seconds). The processor can determine its corresponding working scenario as "periodic acquisition scenario" through a predefined scenario rule base. Based on the scenario policy mapping table, the processor determines the corresponding resource scheduling strategy as "bandwidth-guaranteed polling strategy". The processor can pre-allocate fixed and periodic time slices to the sensor for querying and responding. Outside of its time slice, the first target communication task of the data acquisition task is suspended, and its physical serial port resources are allocated to other tasks, but its communication state (i.e., the second complete task communication state) is preserved intact. When the task's time slice arrives, the processor can seamlessly restore its state based on the second complete task communication state, enabling it to immediately continue communication, thereby greatly improving the utilization rate of serial port resources while ensuring periodicity.

[0072] Furthermore, based on the above embodiments, when the resource scheduling strategy is a preemptive debugging strategy, the step of mapping the read / write request of the first target communication task to the physical serial port can be refined as follows:

[0073] Based on the preemptive debugging strategy, the third target communication task with the highest priority on the serial port is determined; the complete communication state of the first target communication task is saved; the read and write requests of the third target communication task are mapped to the serial port, and the serial port resources are allocated to the third target communication task to achieve scheduling; after the session of the third target communication task ends, the resources are released and the breakpoint is restored based on the complete communication state.

[0074] In this embodiment, the preemptive debugging strategy can be understood as the resource scheduling rules for high-priority task scenarios, such as a high-priority debugging scenario. The third target communication task can be understood as the logical serial port instance with the highest priority among all current virtual serial ports, corresponding to a high-priority communication task.

[0075] Specifically, the processor can determine the highest-priority third target communication task on the serial port based on a preemptive debugging strategy. The processor can save the complete communication state of the first target communication task to a buffer. The processor can map the read and write requests of the third target communication task to the serial port and allocate serial port resources to the third target communication task to achieve serial port scheduling. After the session of the third target communication task ends, the processor releases the serial port resources and performs interrupt point recovery for interrupted communication tasks based on the complete communication state.

[0076] For example, taking the third target communication task as a debugging task as an example, the processor detects data with a baud rate of 115200 on the bus, and the data content is a parsable ASCII command (such as "get_status\r\n"). Based on a predefined scenario rule base, the processor can identify the corresponding working scenario as a high-priority debugging scenario. According to the scenario policy mapping table, the resource scheduling policy for the high-priority debugging scenario is determined to be a preemptive scheduling policy. The processor immediately establishes the highest-priority channel for the debugging data stream. If the physical serial port is occupied by other tasks (such as data acquisition), the processor first seamlessly saves the complete communication state of the communication task to the buffer, and then allocates the serial port resources to the debugging task (the third target communication task). After the debugging session ends, the resources are released, and previously interrupted tasks can immediately resume execution from the point of interruption, achieving a lossless switchover.

[0077] Furthermore, based on the above embodiments, the resource scheduling strategy can also include a time-triggered scheduling strategy. Taking the triggering and execution of tasks controlled by master and slave devices as an example, when the processor detects a strictly periodic broadcast (instruction mode) sent by a master device on the bus, the corresponding working scenario can be determined as a "hard real-time control scenario" based on a predefined scenario rule base. By looking up the scenario policy mapping table, the corresponding resource scheduling strategy is determined to be a "time-triggered scheduling strategy." The processor can allocate a time-limited, exclusive periodic time window to this control bus. Within this time window, all other communication tasks are suspended, ensuring that the transmission of control instructions is absolutely jitter-free and delay-free. This differs from simple priority; it emphasizes the determinism of timing.

[0078] Furthermore, based on the above embodiments, when the resource scheduling strategy is a resource exclusive strategy, the step of mapping the read / write request of the first target communication task to the physical serial port can be refined as follows:

[0079] Save the complete communication state of the first target communication task and exit the first target communication task; map the read and write requests of the communication task under the resource exclusive policy to the serial port and reject other communication requests to the serial port; until the task of the communication task is completed, perform interrupt point recovery based on the complete communication state of the first target communication task.

[0080] In this embodiment, the resource exclusivity strategy can be understood as the target virtual serial port scheduled using the resource exclusivity strategy, which corresponds to the hard real-time critical communication task (such as the logical serial port instance for transmitting master device control commands) and has the highest priority.

[0081] Specifically, the processor can write the third complete communication state of the first target communication task into the memory buffer, exit the first target communication task, and release the serial port resource occupation. The processor can map the read and write requests of the communication task under the resource exclusive strategy to the serial port, giving it complete control over the serial port. During the execution of the communication task, the processor can reject other communication requests to the serial port, regardless of the request priority, and either reject or suspend them to ensure that no task interferes with the current hard real-time communication. Until the communication task is completed, the processor can retrieve the third complete communication state from the memory buffer and perform interrupt point recovery based on the third complete communication state.

[0082] For example, a firmware upgrade task can be used as a case study. The processor receives an encrypted "ENTER_BOOTLOADER" command (instruction mode) sent via a specific serial port. Based on a predefined scenario rule base, the corresponding working scenario is determined to be a "critical maintenance scenario." By looking up the scenario policy mapping table, the corresponding resource scheduling policy is determined to be a "resource exclusivity policy." The processor can suspend all non-essential system functions, allocate 100% of the physical serial port to the firmware upgrade process (i.e., the communication task), and may switch to a higher, more reliable baud rate. During the upgrade process, any other communication requests are rejected to ensure the integrity and reliability of data transmission and prevent the device from becoming unusable due to interference. For such scenarios requiring resource exclusivity, the conflict arbitration logic ensures that all tasks currently using the resource are safely saved and exited. The state saving and restoration process is strictly executed before and after task switching, guaranteeing the absolute reliability of critical tasks and maintaining the overall stability of the system.

[0083] The technical solution of this invention automatically identifies the working scenario corresponding to the instruction pattern through a predefined scenario rule base, determines the corresponding resource scheduling strategy, and dynamically and differentially allocates serial port resources and adjusts serial port communication strategies without manual intervention, adapting to dynamic changes in business scenarios. It layeredly meets the real-time requirements of different services and adapts to mixed scheduling under multiple scenarios. Under the constraint of a single physical serial port hardware, resource virtualization based on virtual serial ports breaks through the limitation of the number of physical serial ports, taking into account the determinism of hard real-time critical tasks, the periodicity of soft real-time periodic tasks, and the overall utilization rate of serial port resources. It supports multi-task parallel communication requirements without adding physical serial port hardware, significantly reducing hardware costs and device size. Through complete communication state saving and breakpoint recovery, it achieves lossless task switching.

[0084] Example 2

[0085] Figure 2 This is a schematic diagram of a serial port multiplexing device provided in Embodiment 3 of the present invention. Figure 2 As shown, the device includes: an information acquisition module 31, a strategy decision module 32, and a serial port scheduling module 33.

[0086] Instruction acquisition module 31 is used to acquire the first communication instruction corresponding to the physical serial port;

[0087] The strategy determination module 32 is used to determine the first resource scheduling strategy under the first working scenario based on the instruction mode corresponding to the first communication instruction.

[0088] Task determination module 33 is used to determine a first target communication task from the communication tasks corresponding to the multiple virtual serial ports corresponding to the physical serial port based on the first resource scheduling strategy.

[0089] The request mapping module 34 is used to map the read and write requests of the first target communication task to the physical serial port.

[0090] The technical solution of this invention involves: acquiring a first communication instruction corresponding to a physical serial port; determining a first resource scheduling strategy under a first working scenario based on the instruction mode corresponding to the first communication instruction; determining a first target communication task among the communication tasks corresponding to multiple virtual serial ports corresponding to the physical serial port based on the first resource scheduling strategy; and mapping the read / write requests of the first target communication task to the physical serial port. By automatically identifying the current working scenario of the serial port through the instruction mode, and based on the service quality requirements of different working scenarios, and leveraging the resource virtualization of virtual serial ports, the limitation on the number of physical serial ports is overcome. Serial port resources are dynamically and differentially allocated and serial port communication strategies are adjusted. This supports multi-task parallel communication needs without adding physical serial port hardware, thereby optimizing overall communication performance under resource-constrained conditions.

[0091] Furthermore, the strategy decision module 32 is specifically used for:

[0092] Based on the instruction pattern and the predefined scenario rule base, the first working scenario corresponding to the first communication instruction is determined;

[0093] The first resource scheduling strategy corresponding to the first working scenario is determined based on the scenario policy mapping table.

[0094] Optionally, the device further includes:

[0095] The first determining unit is configured to obtain the second communication instruction corresponding to the physical serial port after mapping the read / write request of the first communication task to the physical serial port;

[0096] The second determining unit is used to determine the second resource scheduling strategy under the second working scenario based on the instruction mode corresponding to the second communication instruction.

[0097] The third determining unit is used to determine the second target communication task from the communication tasks corresponding to the multiple virtual serial ports based on the second resource scheduling strategy and the first resource scheduling strategy.

[0098] The fourth determining unit is used to map the read / write request of the second target communication task to the physical serial port.

[0099] Specifically, the third determining unit is used for:

[0100] By comparing the priority corresponding to the second resource scheduling strategy with the priority corresponding to the first resource scheduling strategy, the priority comparison result is obtained.

[0101] If the priority comparison result indicates that the second resource scheduling strategy takes precedence over the first resource scheduling strategy, the communication task corresponding to the second communication instruction shall be taken as the second target communication task.

[0102] Furthermore, the fourth determining unit is also used for:

[0103] When the communication task corresponding to the second communication instruction is the second target communication task, the read / write request of the second target communication task is mapped to the physical serial port, and the complete communication state of the first target communication task is saved.

[0104] Furthermore, the device also includes a task recovery unit.

[0105] The task recovery unit is specifically used to: after mapping the read / write request of the second target communication task to the physical serial port, and after the second target communication task ends, to recover the first target communication task based on the complete communication state.

[0106] The serial port multiplexing device provided in the embodiments of the present invention can execute the serial port multiplexing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the method.

[0107] Example 3

[0108] Figure 3A schematic diagram of an electronic device 40 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0109] like Figure 3 As shown, the electronic device 40 includes at least one processor 41 and a memory, such as a read-only memory (ROM) 42 or a random access memory (RAM) 43, communicatively connected to the at least one processor 41. The memory stores computer programs executable by the at least one processor. The processor 41 can perform various appropriate actions and processes based on the computer program stored in the ROM 42 or loaded from storage unit 48 into the RAM 43. The RAM 43 may also store various programs and data required for the operation of the electronic device 40. The processor 41, ROM 42, and RAM 43 are interconnected via a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.

[0110] Multiple components in electronic device 40 are connected to I / O interface 45, including: input unit 46, such as keyboard, mouse, etc.; output unit 47, such as various types of monitors, speakers, etc.; storage unit 48, such as disk, optical disk, etc.; and communication unit 49, such as network card, modem, wireless transceiver, etc. Communication unit 49 allows electronic device 40 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0111] Processor 41 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 41 performs the various methods and processes described above, such as serial port multiplexing methods.

[0112] In some embodiments, the serial port multiplexing method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 48. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 40 via ROM 42 and / or communication unit 49. When the computer program is loaded into RAM 43 and executed by processor 41, one or more steps of the serial port multiplexing method described above may be performed. Alternatively, in other embodiments, processor 41 may be configured to perform the serial port multiplexing method by any other suitable means (e.g., by means of firmware).

[0113] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0114] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0115] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0116] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0117] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0118] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0119] In one embodiment, the present invention further includes a computer program product, which includes a computer program that, when executed by a processor, implements the serial port multiplexing method of any embodiment of the present invention.

[0120] In implementing the computer program product, computer program code for performing the operations of this invention can be written in one or more programming languages ​​or a combination thereof. Programming languages ​​include object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0121] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0122] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A serial port multiplexing method, characterized in that, include: Obtain the first communication command corresponding to the physical serial port; Based on the instruction mode corresponding to the first communication instruction, determine the first resource scheduling strategy under the first working scenario; Based on the first resource scheduling strategy, a first target communication task is determined from the communication tasks corresponding to the multiple virtual serial ports corresponding to the physical serial port. Map the read / write requests of the first target communication task to the physical serial port.

2. The method according to claim 1, characterized in that, The step of determining the first resource scheduling strategy under the first working scenario based on the instruction mode corresponding to the first communication instruction includes: Based on the instruction pattern and the predefined scenario rule base, the first working scenario corresponding to the first communication instruction is determined; The first resource scheduling strategy corresponding to the first working scenario is determined based on the scenario policy mapping table.

3. The method according to claim 1, characterized in that, After mapping the read / write request of the first communication task to the physical serial port, the method further includes: Obtain the second communication command corresponding to the physical serial port; Based on the instruction mode corresponding to the second communication instruction, determine the second resource scheduling strategy under the second working scenario; Based on the second resource scheduling strategy and the first resource scheduling strategy, a second target communication task is determined from the communication tasks corresponding to each of the multiple virtual serial ports. Map the read / write requests of the second target communication task to the physical serial port.

4. The method according to claim 3, characterized in that, The step of determining the second target communication task from the communication tasks corresponding to each of the multiple virtual serial ports based on the second resource scheduling strategy and the first resource scheduling strategy includes: By comparing the priority corresponding to the second resource scheduling strategy with the priority corresponding to the first resource scheduling strategy, the priority comparison result is obtained. If the priority comparison result indicates that the second resource scheduling strategy takes precedence over the first resource scheduling strategy, the communication task corresponding to the second communication instruction shall be taken as the second target communication task.

5. The method according to claim 3, characterized in that, When the communication task corresponding to the second communication instruction is the second target communication task, the step of mapping the read / write request of the second target communication task to the physical serial port further includes: The read / write requests of the second target communication task are mapped to the physical serial port, and the complete communication state of the first target communication task is saved.

6. The method according to claim 5, characterized in that, After mapping the read / write request of the second target communication task to the physical serial port, the method further includes: After the second target communication task is completed, the first target communication task is resumed based on the complete communication state.

7. The method according to claim 1, characterized in that, When the resource scheduling strategy is a bandwidth round-robin strategy, mapping the read / write requests of the first target communication task to the physical serial port includes: The task time slice of the first target communication task is determined according to the bandwidth polling strategy. If the task time slice has not been reached, the first target communication task is suspended and the complete task communication state of the first target communication task is saved. When the task time slice is reached, the read and write requests of the first target communication task are mapped to the physical serial port, and the first target communication task is restored based on the complete task communication state of the first target communication task.

8. A serial port multiplexing device, characterized in that, include: The instruction acquisition module is used to acquire the first communication instruction corresponding to the physical serial port. The strategy determination module is used to determine the first resource scheduling strategy under the first working scenario based on the instruction mode corresponding to the first communication instruction. The task determination module is used to determine a first target communication task from the communication tasks corresponding to the multiple virtual serial ports corresponding to the physical serial port, based on the first resource scheduling strategy. The request mapping module is used to map the read and write requests of the first target communication task to the physical serial port.

9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the serial port multiplexing method according to any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the serial port multiplexing method according to any one of claims 1-7.

11. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the serial port multiplexing method according to any one of claims 1-7.