Data transmission method and device based on virtual serial port, equipment and storage medium

By mapping a virtual serial port to the main control CPU, the problem of the physical serial port exclusivity limitation is solved, enabling efficient data transmission for multiple business modules to access peripherals simultaneously, and reducing the complexity of system software design.

CN115718712BActive Publication Date: 2026-06-16ZHEJIANG UNIVIEW TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
ZHEJIANG UNIVIEW TECH CO LTD
Filing Date
2021-08-24
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

In existing technologies, the exclusive physical serial port limitation between the main controller and the MCU results in low efficiency and high system software design complexity when multiple business modules access peripherals simultaneously.

Method used

By setting a high-speed bus port on the main control CPU and mapping multiple virtual serial ports, each business module is associated with a virtual serial port and protocol encapsulation and packet processing are performed, enabling multiple business modules to communicate with external devices simultaneously, thus reducing the design complexity of serial communication.

Benefits of technology

It enables multiple business modules to transmit data simultaneously to multiple external devices, improving data transmission efficiency and reducing the complexity of serial communication design.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115718712B_ABST
    Figure CN115718712B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a data transmission method and device based on a virtual serial port, an apparatus and a storage medium. The data transmission method based on the virtual serial port comprises: determining an associated virtual serial port mapped by a high-speed bus port for each service module in a host CPU; performing protocol encapsulation and packet processing on original sending data of at least two service modules simultaneously sent to different external devices through the associated virtual serial port to obtain first packet data; sending the first packet data to the MCU through the high-speed bus port, and returning the original return data to the associated service module through the associated virtual serial port according to second packet data returned by the MCU. The embodiments of the present application solve the problem of serial port monopoly by the virtual serial port mapping mode, realize data transmission of multiple service modules in the host end with multiple external devices at the same time, and reduce the complexity of serial communication design.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of serial communication technology, and in particular to a data transmission method, apparatus, device, and storage medium based on a virtual serial port. Background Technology

[0002] In current hardware system designs, insufficient peripheral interfaces on the main controller often necessitate the use of external microcontrollers to connect multiple peripherals. To reduce the complexity of system software design, the main controller and microcontroller are connected via serial ports or USB-to-serial adapters. For example, the main controller and microcontroller can be connected via a high-speed bus such as USB. The high-speed bus interface is presented as a physical serial port on the main controller. The software business modules running on the main controller can then use the serial port to communicate with the MCU (Microcontroller Unit) to achieve communication between the MCU and the peripherals connected to the MCU.

[0003] A physical serial port is an expansion interface that uses serial communication. A physical serial interface transmits data bit by bit sequentially. Its advantages include simple communication lines, requiring only a pair of transmission lines for bidirectional communication. However, this also limits the physical serial port to exclusivity; only one process can open and use it at a time. But a controller often contains multiple business modules. If multiple processes or threads within these modules need to simultaneously access the serial port to operate different peripheral units on the MCU, a single physical serial port cannot achieve this.

[0004] Existing technologies use thread synchronization or inter-process communication synchronization mechanisms to ensure exclusive operation of the serial port before accessing different peripherals sequentially. However, when multiple threads operate on the serial port, locking is required before read and write operations; and even when using inter-process communication, only one process can operate on the serial port, resulting in low serial port access efficiency, and the synchronization mechanism increases the design complexity of the system software. Summary of the Invention

[0005] This invention provides a data transmission method, apparatus, device, and storage medium based on a virtual serial port. By using virtual serial port mapping, the problem of exclusive serial port access is solved, enabling multiple business modules in the main control terminal to transmit data with multiple external devices simultaneously, thereby reducing the complexity of serial communication design.

[0006] In a first aspect, embodiments of the present invention provide a data transmission method based on a virtual serial port, executed by a main control CPU. A high-speed bus port is configured on the main control CPU and connected to an MCU. The MCU is connected to at least two external devices, including:

[0007] The original data sent by at least two service modules to different external devices simultaneously is processed by protocol encapsulation and packetization through pre-mapped associated virtual serial ports to obtain the first packet data; wherein, the virtual serial port is mapped from the high-speed bus port, and each virtual serial port is associated with any service module in the main control CPU; the first packet data includes at least the mapping relationship between the original sent data and the associated virtual serial port;

[0008] The first packet data is sent to the MCU through the high-speed bus port. The MCU sends the original data in the first packet data to the associated external device and receives the original return data from different associated external devices. According to the mapping relationship, the original return data is encapsulated and packetized to obtain the second packet data. The second packet data is then returned to the main control CPU through the high-speed bus port.

[0009] Based on the second group of packet data returned by the MCU, the original returned data is returned to the associated service module through the associated virtual serial port.

[0010] Secondly, embodiments of the present invention also provide a data transmission device based on a virtual serial port, executed by a main control CPU. A high-speed bus port is provided on the main control CPU and connected to an MCU. The MCU is connected to at least two external devices, including:

[0011] The data packet assembly module is used to perform protocol encapsulation and packet assembly processing on the raw data sent simultaneously by at least two service modules to different external devices through a pre-mapped associated virtual serial port to obtain the first packet data; wherein, the virtual serial port is mapped by the high-speed bus port and associated with each service module in the main control CPU; the first packet data includes at least the mapping relationship between the raw data and the associated virtual serial port.

[0012] The data transmission module is used to send the first group of packet data to the MCU through the high-speed bus port, and the MCU sends the original data in the first group of packet data to the associated external device, and receives the original return data from different associated external devices. According to the mapping relationship, the original return data is processed by protocol encapsulation and packetization to obtain the second group of packet data, and the second group of packet data is returned to the main control CPU through the high-speed bus port.

[0013] The data receiving module is used to return the original returned data to the associated service module through the associated virtual serial port based on the second group of packet data returned by the MCU.

[0014] Thirdly, embodiments of the present invention also provide an electronic device, comprising:

[0015] One or more processors;

[0016] Storage device for storing one or more programs.

[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the data transmission method based on a virtual serial port as described in any embodiment of the present invention.

[0018] Fourthly, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the data transmission method based on a virtual serial port as described in any embodiment of the present invention.

[0019] This invention addresses the issue of serial port exclusivity by pre-determining an associated virtual serial port mapped from a high-speed bus port for each service module in the master control unit. Multiple service modules simultaneously encapsulate and assemble raw data destined for different peripherals via these associated virtual serial ports. The assembled data is then transmitted to the MCU via the high-speed bus port. The MCU forwards the raw data to the different peripherals, and the data returned by these peripherals is then sent back to the corresponding service module via the associated virtual serial port. This virtual serial port mapping method solves the problem of exclusive serial port access, enabling multiple service modules in the master control unit to simultaneously transmit data with multiple external devices, thus reducing the complexity of serial communication design. Attached Figure Description

[0020] Figure 1 This is a flowchart of the data transmission method based on a virtual serial port in Embodiment 1 of the present invention;

[0021] Figure 2 This is a schematic diagram of the connection method between the main controller and the MCU in the existing technology;

[0022] Figure 3 This is a schematic diagram of the connection method between the main controller and the MCU in an embodiment of the present invention;

[0023] Figure 4 This is a schematic diagram of the frame structure for data transmission after protocol encapsulation and packet processing;

[0024] Figure 5 This is a schematic diagram illustrating data transmission between the main controller and the MCU via a virtual serial port.

[0025] Figure 6 This is a schematic diagram of the data transmission device based on a virtual serial port in Embodiment 2 of the present invention;

[0026] Figure 7 This is a schematic diagram of the electronic device in Embodiment 3 of the present invention. Detailed Implementation

[0027] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.

[0028] Example 1

[0029] Figure 1 This is a flowchart of a data transmission method based on a virtual serial port according to Embodiment 1 of the present invention. This embodiment is applicable to situations where the main control physical serial port cannot meet the data transmission needs of multiple software business modules to multiple peripheral devices. The method is executed by the main control CPU, which has a high-speed bus port connected to the MCU. The MCU is connected to at least two external devices. This method can be executed by a data transmission device based on a virtual serial port. This device can be implemented in software and / or hardware and can be configured in electronic devices, such as CPUs or hardware systems with communication and computing capabilities. Figure 1 As shown, the method specifically includes:

[0030] Step 101: Perform protocol encapsulation and packetization processing on the raw data sent simultaneously by at least two business modules to different external devices through the pre-mapped associated virtual serial port to obtain the first packet data.

[0031] The virtual serial port is obtained by mapping the high-speed bus port, and each virtual serial port is associated with any business module in the main control CPU; the first group of packet data includes at least the mapping relationship between the original transmitted data and the associated virtual serial port.

[0032] Because the number of physical serial ports between the main control CPU and the MCU in existing hardware systems is limited, multiple business modules in the main control CPU are restricted by the physical serial ports when they need to transmit data simultaneously. In this embodiment of the invention, the high-speed bus port is remapped to multiple virtual serial ports in the driver layer in advance. From the software perspective, each business module can use its associated virtual serial port independently. Each virtual serial port can be regarded as an independent serial port in the software layer. This allows business modules to transmit data without having to worry about whether the high-speed bus port is exclusively used, whether locking is required, or how to synchronize between processes.

[0033] like Figure 2 The diagram shows the connection method between the main controller and the MCU in the prior art. In this diagram, tty represents the physical serial port set on the main controller. In the prior art, there are generally two common processes for the main controller to operate the serial port. One is that the serial port is opened before each business module communicates and closed after data is sent and received. The other is that the serial port is operated uniformly in a process or thread, and each business module needs to use a pre-determined synchronization mechanism to transmit messages.

[0034] like Figure 3 The diagram shown illustrates the connection method between the main controller and the MCU in an embodiment of the present invention. Figure 3 The number of virtual serial ports shown is for illustrative purposes only and is not limited. The actual number of virtual serial ports is determined based on the number of business modules in the main controller. In this embodiment of the invention, multiple virtual serial ports are encapsulated by a driver layer mapping, reducing the complexity of data transmission processing in the business modules. Each business module does not need to consider the issue of serial port exclusivity and can treat its associated virtual serial port as an independent serial port for operation.

[0035] Specifically, the high-speed bus ports are pre-mapped into the same number of virtual serial ports based on the number of business modules in the main control unit, and a one-to-one association is established between the business modules and the virtual serial ports, ensuring that each business module has its own dedicated virtual serial port. When multiple business modules in the main control unit need to transmit data to different external devices simultaneously, the virtual serial port associated with the business module performs protocol encapsulation and packet assembly processing on the raw data to be transmitted, obtaining the first packet data. Protocol encapsulation and packet assembly processing is to establish the mapping relationship between the raw data and the virtual serial ports, clarifying the source of the raw data.

[0036] In one feasible embodiment, step 101 includes:

[0037] The associated virtual serial port node adds an associated serial port identifier, a preset packet header identifier, and a preset packet tail identifier to the original transmitted data to obtain the first group of packet data.

[0038] When determining the mapping relationship in the protocol encapsulation and packet assembly process, an associated serial port identifier, a preset header identifier, and a preset trailer identifier are added to the original transmitted data to achieve protocol encapsulation and packet assembly. Each virtual serial port has a unique serial port identifier, meaning each service module has a unique associated serial port identifier. By adding the associated serial port identifier to the original transmitted data in the first packet data set, the source of the original transmitted data can be determined. Since the first packet data set includes original transmitted data sent by multiple service modules, a preset header identifier is added at the beginning of each original transmitted data set, and a preset trailer identifier is added at the end of each original transmitted data set to distinguish between them. For example... Figure 4 The image shows the frame structure for data transmission after protocol encapsulation and packet processing.

[0039] By encapsulating the packet processing through this protocol, valid data content, i.e., the original sent data, can be parsed from the data transmitted by multiple business modules, and the source business module of each original sent data can be clearly identified.

[0040] Step 102: Send the first group of data packets to the MCU through the high-speed bus port. The MCU sends the original data packets in the first group of data packets to the associated external devices and receives the original return data from different associated external devices. According to the mapping relationship, the original return data is encapsulated and packetized to obtain the second group of data packets. The second group of data packets is then returned to the main control CPU through the high-speed bus port.

[0041] After the original data is encapsulated and packetized by each virtual serial port on the main control end, the first packet of data is sent to the MCU through the high-speed bus port. Since the first packet of data can be regarded as a whole, there is no need to worry about the exclusivity of the physical serial port involved in the existing hardware system. No matter how many original data are contained in the first packet of data, they can be sent sequentially through the high-speed bus port in this embodiment of the invention, so as to realize the simultaneous data transmission between multiple service modules and the MCU through a single high-speed bus port, thereby improving data transmission efficiency.

[0042] Since the original data is sent from different service modules to different peripherals, after receiving the first data packet, the MCU needs to distribute the original data included therein to different peripherals to receive the original return data returned by the peripherals based on the original data. Because there is a correlation between the service modules and the original data, and between the original data and the peripherals, there is also a correlation between the original return data returned by the peripherals and the service modules. That is, the target service module sends the first original data to the target peripheral, and the first original return data returned by the target peripheral also needs to be returned to the target service module. If an error occurs during the return process, the target service module will not receive the return data. Therefore, when the MCU returns the original return data to the main MCU, it needs to perform the same protocol encapsulation and packetization processing on the original return data to obtain the second data packet. The second data packet includes the mapping relationship between the original return data and the virtual serial port, determined based on the mapping relationship between the original data and the virtual serial port.

[0043] For example, the MCU determines the association between the original returned data and the original sent data, and determines the virtual serial port associated with the original sent data, and maps the virtual serial port to the original returned data.

[0044] In one feasible embodiment, step 101 includes:

[0045] Different virtual serial port nodes encapsulate and packetize the raw data sent by the associated business modules to different external devices to obtain the first packet data, and add the first packet data to the send queue associated with the virtual serial port.

[0046] Accordingly, the first group of data packets is sent to the MCU via the high-speed bus port, including:

[0047] A timed polling thread is initiated to periodically poll the transmit queues associated with all virtual serial ports, and the first group of packet data in the transmit queue is sent to the MCU through the high-speed bus port.

[0048] Each virtual serial port's transmitted data is managed by its own transmission queue. Specifically, when a business module sends raw data, it determines the associated virtual serial port node, which adds the raw data to its associated transmission queue. For example, building upon the above example, each virtual serial port node adds its corresponding serial port identifier, a preset header identifier, and a preset trailer identifier to the raw data, and packages them together with the raw data into its associated transmission queue.

[0049] Each business module adds the raw data to the transmission queue according to its own needs. The main controller initiates a timed polling thread to periodically poll the transmission queues of each virtual serial port. If there is data in the transmission queue, the data is sent to the MCU sequentially through the high-speed bus port.

[0050] In one feasible embodiment, the MCU transmits the raw transmission data from the first group of packet data to the associated external device, including:

[0051] The MCU parses the first group of packet data according to the preset packet header identifier and preset packet tail identifier to obtain the associated serial port identifier and the original transmission data, and sends the original transmission data to the associated external device according to the specific information in the original transmission data.

[0052] After receiving the first data packet, the MCU needs to perform protocol parsing and unpacking to extract the actual valid data content. Since the first data packet is encapsulated and packaged according to a preset format, the MCU can locate the original transmitted data and its associated serial port identifier by recognizing the preset header and trailer identifiers. After obtaining the valid original transmitted data, the MCU sends it to the corresponding associated external device based on its content.

[0053] In one feasible embodiment, the mapping relationship between the original transmitted data and the associated virtual serial port is the mapping relationship between the original transmitted data and the serial port identifier of the associated virtual serial port;

[0054] Accordingly, the original returned data is encapsulated and packetized according to the mapping relationship to obtain the second packet data, including:

[0055] The serial port identifier associated with the original returned data is determined based on the mapping relationship;

[0056] Add a serial port identifier, a preset packet header identifier, and a preset packet tail identifier to the original returned data to obtain the second set of packet data.

[0057] The MCU determines the association between the original returned data and the original transmitted data, and identifies the serial port identifier associated with the original transmitted data. It then maps this serial port identifier to the original returned data. Specifically, after determining the serial port identifier associated with the original returned data, the MCU performs the same protocol encapsulation and packetization processing on the original returned data according to the protocol encapsulation and packetization processing method used for the first group of data packets. For example, a preset header identifier is added to the beginning of each original returned data packet, and a preset trailer identifier is added to the end of each original returned data packet. That is, according to… Figure 4 The frame structure of the data transmission shown is subjected to protocol encapsulation and packet assembly to obtain the second packet data.

[0058] Step 103: Based on the second set of packet data returned by the MCU, return the original returned data to the associated service module through the associated virtual serial port.

[0059] The main control CPU, based on the second set of packet data returned by the MCU, extracts the actual valid original return data from the second set of packet data, and then returns the original return data to the associated service module through the associated virtual serial port. For example, based on the above example, the second set of packet data includes the association between the original return data and the virtual serial port, thus the associated virtual serial port of the original return data can be determined.

[0060] In one feasible embodiment, step 103 includes:

[0061] The second group of packet data is parsed based on the preset packet header and preset packet tail identifiers to obtain the serial port identifier and the original return data;

[0062] The associated virtual serial port is determined based on the serial port identifier, and the original returned data is sent to the receiving queue of the associated virtual serial port so that the business module can obtain the original returned data from the receiving queue of the associated virtual serial port.

[0063] The main controller parses the second group of data packets based on preset header and trailer identifiers to obtain the serial port identifier and the original return data. Specifically, after receiving the second group of data packets, the main controller needs to perform protocol parsing and unpacking to separate the actual valid data content from the second group of data packets. Since the second group of data packets is encapsulated and packaged according to a preset format, the main controller can locate the position of the original return data and the serial port identifier associated with it by recognizing the preset header and trailer identifiers. After obtaining the valid original return data, the main controller sends the original return data into the corresponding virtual serial port receive queue according to the associated serial port identifier.

[0064] like Figure 5 The diagram shown illustrates data transmission between the master controller and the MCU via a virtual serial port. Figure 5 As shown, the high-speed bus port is a USB serial port. Virtual serial ports / dev / ttyVirtual0- / dev / ttyVirtual3 are created by repackaging the USB serial port / dev / ttyUSB0. Data for each virtual serial port is managed by its own transmit / receive queue. The raw data sent by each virtual serial port node is appended with the corresponding serial port identifier, a preset header identifier, and a preset trailer identifier, and then packaged into the queue along with the raw data. The kernel's transmit thread periodically polls the transmit queues of each virtual serial port and sends the data sequentially to the MCU via USB. The MCU at the other end unpacks and parses the data packets, extracting the actual valid data content. Based on the serial port identifier of the previously received data packets, it reassembles the packets and fills them into the transmit data buffer, sending them to the host controller via USB. Upon receiving the data, the host controller obtains the raw return data based on the received preset header and trailer identifiers and sends it to the corresponding virtual serial port receive queue according to the serial port identifier.

[0065] In one feasible embodiment, the main control CPU and the MCU are connected via a first bus, and the MCU is connected to external devices via a second bus; wherein the transmission rate of the first bus is greater than the transmission rate of the second bus.

[0066] Building upon the example above, the data transmitted via the first bus is the sum of the data transmitted via the second bus. Since the MCU connects to multiple external devices, the first bus is a high-speed bus, and the second bus is a low-speed bus. The transmission rate of the high-speed bus must be greater than that of the low-speed bus to allow for data buffering and interaction between the two buses via a FIFO (First In First Out) queue. The high-speed bus can utilize USB communication or other high-speed buses such as PCIe or SDIO.

[0067] This invention addresses the issue of serial port exclusivity by pre-determining an associated virtual serial port mapped from a high-speed bus port for each service module in the master control unit. Multiple service modules simultaneously encapsulate and assemble raw data destined for different peripherals via these associated virtual serial ports. The assembled data is then transmitted to the MCU via the high-speed bus port. The MCU forwards the raw data to the different peripherals, and the data returned by these peripherals is then sent back to the corresponding service module via the associated virtual serial port. This virtual serial port mapping method solves the problem of exclusive serial port access, enabling multiple service modules in the master control unit to simultaneously transmit data with multiple external devices, thus reducing the complexity of serial communication design.

[0068] Example 2

[0069] Figure 6 This is a schematic diagram of the data transmission device based on a virtual serial port in Embodiment 2 of the present invention. This embodiment is applicable to situations where the main control physical serial port cannot meet the data transmission needs of multiple software business modules to multiple peripherals. The transmission is executed by the main control CPU, and a high-speed bus port is set up on the main control CPU to connect to the MCU. The MCU is connected to at least two external devices, such as... Figure 6 As shown, the device includes:

[0070] The data packet assembly module 610 is used to perform protocol encapsulation and packet assembly processing on the raw data sent simultaneously by at least two service modules to different external devices through a pre-mapped associated virtual serial port to obtain a first packet data; wherein, the virtual serial port is mapped by the high-speed bus port and associated with each service module in the main control CPU; the first packet data includes at least the mapping relationship between the raw data and the associated virtual serial port.

[0071] The data transmission module 620 is used to send the first group of packet data to the MCU through the high-speed bus port, and the MCU sends the original data in the first group of packet data to the associated external device, and receives the original return data from different associated external devices. According to the mapping relationship, the original return data is processed by protocol encapsulation and packetization to obtain the second group of packet data, and the second group of packet data is returned to the main control CPU through the high-speed bus port.

[0072] The data receiving module 630 is used to return the original returned data to the associated service module through the associated virtual serial port according to the second group of packet data returned by the MCU.

[0073] This invention addresses the issue of serial port exclusivity by pre-determining an associated virtual serial port mapped from a high-speed bus port for each service module in the master control unit. Multiple service modules simultaneously encapsulate and assemble raw data destined for different peripherals via these associated virtual serial ports. The assembled data is then transmitted to the MCU via the high-speed bus port. The MCU forwards the raw data to the different peripherals, and the data returned by these peripherals is then sent back to the corresponding service module via the associated virtual serial port. This virtual serial port mapping method solves the problem of exclusive serial port access, enabling multiple service modules in the master control unit to simultaneously transmit data with multiple external devices, thus reducing the complexity of serial communication design.

[0074] Optional, a data packet sending module, specifically used for:

[0075] Different virtual serial port nodes encapsulate and packetize the raw data sent by the associated business modules to different external devices to obtain the first packet data, and add the first packet data to the sending queue associated with the virtual serial port.

[0076] Correspondingly, the data sending module is specifically used for:

[0077] A timed polling thread is initiated to periodically poll the transmission queues associated with all virtual serial ports, and the first group of packet data in the transmission queue is sent to the MCU through the high-speed bus port.

[0078] Optional, a data packet sending module, specifically used for:

[0079] The associated virtual serial port node adds an associated serial port identifier, a preset packet header identifier, and a preset packet tail identifier to the original transmitted data to obtain the first group of packet data.

[0080] Optionally, the MCU may send the original transmission data from the first group of packet data to the associated external device, including:

[0081] The MCU parses the first group of packet data according to the preset packet header identifier and the preset packet tail identifier to obtain the associated serial port identifier and the original transmission data, and sends the original transmission data to the associated external device according to the specific information in the original transmission data.

[0082] Optionally, the mapping relationship between the original transmitted data and the associated virtual serial port is the mapping relationship between the original transmitted data and the serial port identifier of the associated virtual serial port;

[0083] Accordingly, the original returned data is encapsulated and packetized according to the mapping relationship to obtain a second packet of data, including:

[0084] The serial port identifier associated with the original returned data is determined based on the mapping relationship;

[0085] The serial port identifier, preset packet header identifier, and preset packet tail identifier are added to the original returned data to obtain the second set of packet data.

[0086] Optional, a data receiving module, specifically used for:

[0087] The second group of packet data is parsed according to the preset packet header identifier and the preset packet tail identifier to obtain the serial port identifier and the original return data;

[0088] The associated virtual serial port is determined based on the serial port identifier, and the original returned data is sent to the receiving queue of the associated virtual serial port so that the service module can obtain the original returned data from the receiving queue of the associated virtual serial port.

[0089] Optionally, the main control CPU and the MCU are connected via a first bus, and the MCU is connected to the external device via a second bus; wherein the transmission rate of the first bus is greater than the transmission rate of the second bus.

[0090] The data transmission device based on a virtual serial port provided in this embodiment of the invention can execute the data transmission method based on a virtual serial port provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects for executing the data transmission method based on a virtual serial port.

[0091] Example 3

[0092] Figure 7 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. Figure 7 A block diagram is shown of an exemplary electronic device 12 suitable for implementing embodiments of the present invention. Figure 7 The electronic device 12 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.

[0093] like Figure 7 As shown, the electronic device 12 is represented in the form of a general-purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, system storage device 28, and bus 18 connecting different system components (including system storage device 28 and processing unit 16).

[0094] Bus 18 represents one or more of several bus architectures, including a memory device bus or memory device controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.

[0095] Electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including volatile and non-volatile media, removable and non-removable media.

[0096] System storage device 28 may include computer system readable media in the form of volatile storage devices, such as random access memory (RAM) 30 and / or cache storage device 32. Electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media (… Figure 7Not shown; usually referred to as a "hard drive"). Although Figure 7 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Storage device 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.

[0097] A program / utility 40 having a set (at least one) of program modules 42 may be stored in, for example, storage device 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of the present invention.

[0098] Electronic device 12 can also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), and with one or more devices that enable a user to interact with device 12, and / or with any device that enables device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 22. Furthermore, electronic device 12 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 20. Figure 7 As shown, network adapter 20 communicates with other modules of electronic device 12 via bus 18. It should be understood that, although... Figure 7 As not shown, other hardware and / or software modules may be used in conjunction with electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0099] Processing unit 16 executes various functional applications and data processing by running programs stored in system storage device 28, such as implementing the data transmission method based on a virtual serial port provided in this embodiment of the invention. This method is executed by the main control CPU, which has a high-speed bus port connected to the MCU. The MCU is connected to at least two external devices, including:

[0100] The original data sent by at least two service modules to different external devices simultaneously is processed by protocol encapsulation and packetization through pre-mapped associated virtual serial ports to obtain the first packet data; wherein, the virtual serial port is mapped from the high-speed bus port, and each virtual serial port is associated with any service module in the main control CPU; the first packet data includes at least the mapping relationship between the original sent data and the associated virtual serial port;

[0101] The first packet data is sent to the MCU through the high-speed bus port. The MCU sends the original data in the first packet data to the associated external device and receives the original return data from different associated external devices. According to the mapping relationship, the original return data is encapsulated and packetized to obtain the second packet data. The second packet data is then returned to the main control CPU through the high-speed bus port.

[0102] Based on the second group of packet data returned by the MCU, the original returned data is returned to the associated service module through the associated virtual serial port.

[0103] Example 4

[0104] Embodiment 4 of the present invention also provides a computer-readable storage medium storing a computer program thereon. When executed by a processor, the program implements the data transmission method based on a virtual serial port as provided in the embodiments of the present invention. The program is executed by a main control CPU, and a high-speed bus port is provided on the main control CPU for connection to an MCU. The MCU is connected to at least two external devices, including:

[0105] The original data sent by at least two service modules to different external devices simultaneously is processed by protocol encapsulation and packetization through pre-mapped associated virtual serial ports to obtain the first packet data; wherein, the virtual serial port is mapped from the high-speed bus port, and each virtual serial port is associated with any service module in the main control CPU; the first packet data includes at least the mapping relationship between the original sent data and the associated virtual serial port;

[0106] The first packet data is sent to the MCU through the high-speed bus port. The MCU sends the original data in the first packet data to the associated external device and receives the original return data from different associated external devices. According to the mapping relationship, the original return data is encapsulated and packetized to obtain the second packet data. The second packet data is then returned to the main control CPU through the high-speed bus port.

[0107] Based on the second group of packet data returned by the MCU, the original returned data is returned to the associated service module through the associated virtual serial port.

[0108] The computer storage medium of this invention can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0109] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.

[0110] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0111] Computer program code for performing the operations of this invention can be written in one or more programming languages ​​or a combination thereof, including 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 it can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0112] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.

Claims

1. A data transmission method based on a virtual serial port, characterized in that, Executed by the main control CPU, a high-speed bus port is set up on the main control CPU to connect to the MCU, and the MCU is connected to at least two external devices, including: By adding associated serial port identifiers, preset packet header identifiers, and preset packet tail identifiers to the raw data sent simultaneously by at least two service modules to different external devices through pre-mapped associated virtual serial ports, a first group of packet data is obtained; wherein, the virtual serial port is obtained by mapping the high-speed bus port, and each virtual serial port is associated with any service module in the main control CPU; the first group of packet data includes at least the mapping relationship between the raw data and the associated virtual serial port; The first group of packet data is sent to the MCU through the high-speed bus port. The MCU parses the first group of packet data according to the preset packet header identifier and the preset packet tail identifier to obtain the associated serial port identifier and the original transmitted data. Based on the specific information in the original transmitted data, the MCU sends the original transmitted data to the associated external device and receives the original return data from different associated external devices. Based on the mapping relationship, the MCU performs protocol encapsulation and packetization processing on the original return data to obtain the second group of packet data. The second group of packet data is then returned to the main control CPU through the high-speed bus port. Based on the second group of packet data returned by the MCU, the original returned data is returned to the associated service module through the associated virtual serial port.

2. The method according to claim 1, characterized in that, By using a pre-mapped associated virtual serial port, the raw data sent simultaneously by at least two service modules to different external devices is processed through protocol encapsulation and packet assembly to obtain the first packet data, which includes: Different virtual serial port nodes encapsulate and packetize the raw data sent by the associated business modules to different external devices to obtain the first packet data, and add the first packet data to the sending queue associated with the virtual serial port. Accordingly, the first group of packet data is sent to the MCU through the high-speed bus port, including: A timed polling thread is initiated to periodically poll the transmission queues associated with all virtual serial ports, and the first group of packet data in the transmission queue is sent to the MCU through the high-speed bus port.

3. The method according to claim 1, characterized in that, The mapping relationship between the original transmitted data and the associated virtual serial port is the mapping relationship between the original transmitted data and the serial port identifier of the associated virtual serial port. Accordingly, the original returned data is encapsulated and packetized according to the mapping relationship to obtain the second packet data, including: The serial port identifier associated with the original returned data is determined based on the mapping relationship; The serial port identifier, preset packet header identifier, and preset packet tail identifier are added to the original returned data to obtain the second set of packet data.

4. The method according to claim 3, characterized in that, Based on the second group of packet data returned by the MCU, the original returned data is returned to the associated service module via the associated virtual serial port, including: The second group of packet data is parsed according to the preset packet header identifier and the preset packet tail identifier to obtain the serial port identifier and the original return data; The associated virtual serial port is determined based on the serial port identifier, and the original returned data is sent to the receiving queue of the associated virtual serial port so that the service module can obtain the original returned data from the receiving queue of the associated virtual serial port.

5. The method according to claim 1, characterized in that, The main control CPU and the MCU are connected via a first bus, and the MCU is connected to the external device via a second bus; wherein the transmission rate of the first bus is greater than the transmission rate of the second bus.

6. A data transmission device based on a virtual serial port, characterized in that, Executed by the main control CPU, a high-speed bus port is set up on the main control CPU to connect to the MCU, and the MCU is connected to at least two external devices, including: The data packet assembly module is used to add an associated serial port identifier, a preset packet header identifier, and a preset packet tail identifier to the raw data sent simultaneously by at least two service modules to different external devices through a pre-mapped associated virtual serial port, thereby obtaining a first packet data set; wherein, the virtual serial port is mapped from the high-speed bus port and associated with each service module in the main control CPU; the first packet data set includes at least the mapping relationship between the raw data and the associated virtual serial port; The data transmission module is used to send the first group of packet data to the MCU through the high-speed bus port. The MCU parses the first group of packet data according to the preset packet header identifier and the preset packet tail identifier to obtain the associated serial port identifier and the original transmission data. The MCU then sends the original transmission data to the associated external device according to the specific information in the original transmission data, and receives the original return data from different associated external devices. The MCU performs protocol encapsulation and packetization processing on the original return data according to the mapping relationship to obtain the second group of packet data. The second group of packet data is then returned to the main control CPU through the high-speed bus port. The data receiving module is used to return the original returned data to the associated service module through the associated virtual serial port based on the second group of packet data returned by the MCU.

7. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the data transmission method based on a virtual serial port as described in any one of claims 1-5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by the processor, the program implements the data transmission method based on a virtual serial port as described in any one of claims 1-5.