Multi-virtual serial port implementation method and device, equipment and storage medium

By modifying the USB device type to the combined device type and allocating PMA memory, multiple virtual serial ports are realized, which solves the problem of physical serial ports occupying space and cost in space-constrained environments of USB devices, and improves system efficiency and performance.

CN119105994APending Publication Date: 2024-12-10LIVEFAN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411193772.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-28
Publication Date
2024-12-10

AI Technical Summary

Technical Problem

In application environments where USB devices are space-constrained, multiple physical serial ports have problems such as occupying physical space, increasing hardware cost and volume, and poor scalability, which affects device design and system flexibility.

Method used

By modifying the device type of the USB device to the combined device type, supporting multiple CDC-like interfaces, allocating PMA memory to each interface, configuring operation functions to handle the reception and transmission of data packets, realizing multiple virtual serial ports, and reducing the physical serial ports need.

Benefits of technology

Implementing multiple CDC virtual serial ports on one USB interface avoids the physical interface's space occupied, optimizes the use of system resources, and improves overall efficiency and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119105994A_ABST
    Figure CN119105994A_ABST
Patent Text Reader

Abstract

The invention relates to the field of computers, and discloses a multi-virtual serial port implementation method and device, equipment and a storage medium. The method comprises the steps that the device type of the USB device is modified into a combined device type, so that the USB device supports a plurality of CDC interfaces at the same time; obtaining a PMA memory address of the USB device, and allocating a corresponding PMA memory to the endpoint according to the PMA memory address; modifying a configuration descriptor of the USB device, and combining each CDC type interface together to ensure that each CDC type interface can be identified as a part of the USB device; and according to the endpoints, configuring an operation function of each CDC type interface so as to process receiving and sending of data packets of the USB equipment. In the embodiment of the invention, a plurality of CDC virtual serial ports can be realized on one USB interface, so that the requirement on a physical serial port interface is reduced, the space occupied by the physical interface is avoided, the use of system resources is optimized, and the overall efficiency and performance of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a method, device and storage medium for realizing multiple virtual serial ports. Background Art

[0002] Universal Serial Bus (USB) is an emerging data communication standard that has gradually replaced other interface technologies. The standard was jointly developed by Intel, Compaq, Digital, IBM, Microsoft, NEC, Northern Telecom and other companies in 1995 and has gradually become an industry standard. As a high-speed serial bus, USB's superior transmission speed meets the needs of high-speed data transmission. In addition, USB has many advantages, including simple power supply (supports bus power), convenient installation and configuration (plug and play and hot swap), easy expansion (supports up to 127 peripherals through a hub), various transmission modes (provides 4 transmission modes), and good compatibility (backward compatibility after product upgrades).

[0003] With the advancement of USB technology, USBCDC (Communication Device Class) is widely used for data transmission between microcontrollers and hosts. At the same time, USB serial ports have also been widely used. However, in space-constrained application environments, USB multiple physical serial ports have some obvious disadvantages, such as occupying physical space, increasing hardware costs, increasing device weight and volume, and poor scalability. These disadvantages mainly affect the design, layout, and flexibility of the overall system. Summary of the invention

[0004] The main purpose of the present invention is to solve the technical problem of how to realize multiple virtual serial ports of a USB device.

[0005] A first aspect of the present invention provides a method for implementing multiple virtual serial ports, the method comprising:

[0006] Modify the device type of the USB device to a combined device type, so that the USB device supports multiple CDC class interfaces at the same time, and each of the CDC class interfaces is configured with an endpoint;

[0007] Acquire a PMA memory address of the USB device, and allocate a corresponding PMA memory to the endpoint according to the PMA memory address, wherein the PMA memory is used to store data packets of the USB device;

[0008] Modifying the configuration descriptor of the USB device to group each of the CDC class interfaces together to ensure that each of the CDC class interfaces can be identified as part of the USB device;

[0009] According to the endpoint, an operation function of each of the CDC class interfaces is configured to process the reception and transmission of data packets of the USB device.

[0010] Optionally, in a first implementation of the first aspect of the present invention, modifying the device type of the USB device to a combined device type so that the USB device supports multiple CDC class interfaces simultaneously includes:

[0011] Defining a combined device descriptor in the device descriptor of the USB device, wherein the combined device descriptor includes a plurality of interface descriptors;

[0012] According to the plurality of interface descriptors, configuring the endpoints and functions of each of the CDC class interfaces in the combined device descriptor;

[0013] In the firmware of the USB device, the device descriptor of the USB device is modified to a defined combined device descriptor, so that the USB device supports multiple CDC class interfaces simultaneously.

[0014] Optionally, in a second implementation of the first aspect of the present invention, the modifying the configuration descriptor of the USB device to combine each of the CDC class interfaces together to ensure that each of the CDC class interfaces can be identified as part of the USB device includes:

[0015] Modify the configuration descriptor of the USB device and define an interface association descriptor;

[0016] Each of the CDC class interfaces is grouped together according to the interface association descriptor to ensure that each of the CDC class interfaces can be identified as part of the USB device.

[0017] Optionally, in a third implementation manner of the first aspect of the present invention, obtaining the PMA memory address of the USB device and allocating a corresponding PMA memory to the endpoint according to the PMA memory address includes:

[0018] determining a memory size of the endpoint;

[0019] Obtain the data buffer size and the starting address of the data buffer of the endpoint;

[0020] The PMA memory address of the USB device is obtained, and the corresponding PMA memory is allocated to the endpoint through a control register according to the PMA memory address, the data buffer size of the endpoint, and the data buffer start address.

[0021] Optionally, in a fourth implementation of the first aspect of the present invention, the operation function includes a data receiving function and a data sending function;

[0022] According to the endpoint, configuring the operation function of each CDC class interface includes:

[0023] Obtaining the address, type and maximum packet size of the endpoint;

[0024] Determine the data receiving function and the data sending function according to the address, type and maximum data packet size of the endpoint;

[0025] The receiving and sending of data packets of the USB device are processed according to the data receiving function and the data sending function.

[0026] Optionally, in a fifth implementation of the first aspect of the present invention, the operation function further includes an interrupt processing function, and the interrupt processing function is used to process the received data and the sent data of the USB device.

[0027] Optionally, in a sixth implementation of the first aspect of the present invention, when the USB device is connected to a USB port of a PC, the USB device sends a device descriptor to the PC so that the PC recognizes the USB device;

[0028] The PC side loads a driver so that the PC side communicates with the USB device. The driver is configured to identify endpoints of the USB device and process data transmission of the endpoints.

[0029] A second aspect of the present invention provides a multi-virtual serial port implementation device, comprising: a memory and at least one processor, wherein the memory stores instructions, and the memory and the at least one processor are interconnected through a line; the at least one processor calls the instructions in the memory so that the multi-virtual serial port implementation device executes the above-mentioned multi-virtual serial port implementation method.

[0030] A third aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned method for realizing multiple virtual serial ports.

[0031] In an embodiment of the present invention, the device type of a USB device is modified to a combined device type, so that the USB device supports multiple CDC class interfaces at the same time, and each of the CDC class interfaces is configured with an endpoint; the PMA memory address of the USB device is obtained, and the corresponding PMA memory is allocated to the endpoint according to the PMA memory address, and the PMA memory is used to store data packets of the USB device; the configuration descriptor of the USB device is modified to combine each of the CDC class interfaces together to ensure that each of the CDC class interfaces can be identified as part of the USB device; and the operation function of each of the CDC class interfaces is configured according to the endpoint to process the reception and transmission of data packets of the USB device. In the present invention, by modifying the device type of the USB device to a combined device type, allocating endpoint PMA memory and configuring interface operation functions, multiple CDC virtual serial ports can be implemented on one USB interface, reducing the demand for physical serial port interfaces, avoiding the space occupied by physical interfaces, optimizing the use of system resources, and improving the overall efficiency and performance of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 A schematic diagram of an embodiment of a method for implementing multiple virtual serial ports in an embodiment of the present invention;

[0033] Figure 2 A schematic diagram of an embodiment of a device for realizing multiple virtual serial ports in an embodiment of the present invention;

[0034] Figure 3 The figure is a schematic diagram of an embodiment of a device for realizing multiple virtual serial ports in an embodiment of the present invention. DETAILED DESCRIPTION

[0035] The embodiments of the present invention provide a method, device, equipment and storage medium for realizing multiple virtual serial ports.

[0036] The embodiments disclosed in the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments disclosed in the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments disclosed in the present invention are only for exemplary purposes and are not intended to limit the scope of protection disclosed in the present invention.

[0037] In the description of the embodiments disclosed in the present invention, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below.

[0038] USB CDC (Universal Serial Bus Communication Device Class) is a standard protocol for serial communication on the USB bus. It is commonly used to communicate between a computer and serial devices such as modems, serial printers, sensors, etc. First, a USB CDC device is connected to the USB port of the computer. The computer communicates with the CDC device through the USB host controller. When the CDC device is connected to the computer, it sends a device descriptor to the computer so that the computer can recognize it as a CDC device and load the corresponding driver. Once the device is recognized and the corresponding driver is loaded, the computer and the CDC device can communicate through the USB bus. The USB CDC device exchanges data with the computer through the USB interface, using a virtual serial port so that the computer can transmit data with the CDC device just like communicating with a standard serial port device. During the data transmission process, the USB CDC device converts the serial data into USB data packets and sends them to the computer through the USB bus. After the computer receives the USB data packet, it converts it into serial data and passes it to the application or operating system for processing.

[0039] A USB device has only one device descriptor, which defines how many configurations the device has, and each configuration has a corresponding configuration descriptor; the configuration descriptor also defines how many interfaces there are in the configuration, and each interface has a corresponding interface descriptor; the interface descriptor also defines how many endpoints the interface has, and each endpoint corresponds to an endpoint descriptor; the endpoint descriptor defines the size and type of the endpoint, etc. The relationship between USB descriptors is layered, with the top layer being the device descriptor, the configuration descriptor below, the interface descriptor below, and the endpoint descriptor below. When obtaining descriptors, first obtain the device descriptor, then obtain the configuration descriptor, and read back the configuration descriptor, interface descriptor, and endpoint descriptor together according to the length of the configuration set in the configuration descriptor. It may also be necessary to obtain the device serial number, manufacturer string, product string, etc.

[0040] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the method for implementing multiple virtual serial ports in an embodiment of the present invention includes:

[0041] S100, modifying the device type of the USB device to a combined device type, so that the USB device supports multiple CDC class interfaces simultaneously.

[0042] In this embodiment, changing the device type of the USB device to a combined device type is one of the key steps to implement multiple virtual serial ports. Wherein, a combined device is a USB device that supports multiple functions or interfaces, which can exist at the same time and be identified as different virtual devices in the operating system. For example, a combined device can contain multiple virtual serial ports, multiple storage devices, or other different types of USB functions. The combined device allows multiple functions to be implemented on the same USB device at the same time. For example, a device can provide multiple virtual serial ports, a storage device, and a HID device (such as a mouse or keyboard) at the same time. Through the combined device, all these functions can be implemented through one USB port, thereby saving hardware resources and reducing system complexity. In addition, the combined device integrates all related interfaces and functions into one device, which simplifies the management of the driver. In the operating system, the operating system can identify and manage each interface through the descriptor of the combined device. Using the combined device, all interfaces and functions of the device are concentrated in one device descriptor, which simplifies the configuration and management of the device. A standard USB CDC class device usually supports a single serial port (a communication interface). If only a single interface is used, only one virtual serial port can be created. By defining the device as a composite device, multiple interfaces can be defined in the device descriptor, and each interface can represent a virtual serial port. Composite devices allow devices to support multiple CDC class interfaces at the same time, and each interface can be recognized by the operating system as a different virtual serial port. The virtual serial port appears as a standard COM port in the operating system, and can be seamlessly integrated with existing serial communication software and systems, supporting communication with standard serial protocols. Multiple virtual serial ports can reduce the need for physical serial port expansion cards or interface modules, thereby simplifying device design, wiring and installation, and reducing hardware costs and size.

[0043] S200, obtaining a PMA memory address of the USB device, and allocating a corresponding PMA memory to the endpoint according to the PMA memory address.

[0044] In this embodiment, since the CDC class interface is expanded, the memory allocation of the endpoint needs to be adjusted. PMA (Packet Memory Area) is a memory area in the USB controller for storing USB data packets. Each USB endpoint has a memory area in the PMA. The PMA memory is an area for storing USB data packets. In a single-chip microcomputer, the size of the PMA memory is fixed, generally 1024 bytes (may vary depending on the model). Each USB endpoint allocates a fixed memory area in the PMA memory to store incoming and outgoing data. Each endpoint has two main areas in the PMA: a data buffer for storing the actual content of the data packet; an endpoint descriptor, which contains control information about the endpoint, such as status, address, etc. The PMA address allocation is usually configured through a control register located in the USB peripheral. The memory of each endpoint is allocated based on the starting address of the endpoint data buffer and the maximum packet size of the endpoint. Adjusting the memory allocation of endpoints can: improve data transmission efficiency, ensure that there are no bottlenecks during data transmission, and improve system performance; meet specific application requirements, and reasonably allocate memory based on the actual application data flow requirements and the number of endpoints; optimize resource usage, avoid conflicts and waste of memory areas, and make full use of PMA resources.

[0045] S300, modifying the configuration descriptor of the USB device, and combining each CDC class interface together to ensure that each CDC class interface can be identified as part of the USB device.

[0046] In this embodiment, the configuration descriptor is used to describe the specific configuration of the device. It contains multiple parts, including interface descriptors, endpoint descriptors, and interface association descriptors (IADs), especially when multiple interfaces share certain functions (such as multiple CDC interfaces). The configuration descriptor mainly includes:

[0047] Interface Association Descriptor (IAD): Groups multiple CDC interfaces together.

[0048] CDC control interface: used to handle control transfers.

[0049] CDC data interface: used to handle data transmission.

[0050] Endpoint Descriptor: Defines the properties of each endpoint.

[0051] The purpose of modifying the configuration descriptor is to: define the configuration of the device, tell the host detailed information about each interface and endpoint of the device; allocate resources correctly to ensure that each interface and endpoint has appropriate memory and functions; support multiple functions, support complex device functions such as multiple virtual serial ports through IAD and multiple interfaces.

[0052] S400: Configure the operation function of each CDC class interface according to the endpoint.

[0053] In this embodiment, the operation function of each CDC class interface is configured according to the detailed information of the endpoint. The default library function is only for one CDC case, so it needs to be modified to a multi-channel CDC operation function to pass the port parameters. The specific operation is as follows:

[0054] (1) Implement new functionality: Add or modify interfaces to support new functionality or services.

[0055] (2) Adapting to application requirements: Adjusting interface configuration according to specific applications or user requirements.

[0056] (3) Optimize performance: adjust interface parameters to improve data transmission efficiency or reduce resource consumption.

[0057] In an optional implementation of the first aspect of the present invention, modifying the device type of the USB device to a combined device type so that the USB device supports multiple CDC class interfaces simultaneously includes:

[0058] A combined device descriptor is defined in a device descriptor of a USB device, wherein the combined device descriptor includes a plurality of interface descriptors; endpoints and functions of each CDC class interface are configured in the combined device descriptor according to the plurality of interface descriptors; and in the firmware of the USB device, the device descriptor of the USB device is modified to be the defined combined device descriptor, so that the USB device supports a plurality of CDC class interfaces simultaneously.

[0059] In this embodiment, a combined device descriptor is defined in the device descriptor of the USB device. A typical combined device descriptor may include:

[0060] Configuration descriptor: Specifies the overall configuration of the device, including all interfaces.

[0061] Interface descriptor: A specific description of each interface, such as the CDC class interface.

[0062] Endpoint descriptors: Input and output endpoints for each interface.

[0063] The combined device descriptor contains multiple interface descriptors, each of which corresponds to a function (such as multiple CDC serial ports). In the combined device descriptor, configure the endpoints and functions of each CDC class interface. Then, implement the functions of each CDC class interface. Each interface can have independent endpoints and communication settings. Secondly, in the USB device firmware, the device's descriptor and implementation code need to be modified to support the combined device function. USB libraries or custom code can be used to handle different interface requests. Finally, connect to the host system (such as a PC) and use the appropriate driver. Test each virtual serial port to ensure that they can work independently and that data transmission is normal.

[0064] In an optional implementation of the first aspect of the present invention, the configuration descriptor of the USB device is modified to group each CDC class interface together to ensure that each CDC class interface can be identified as a part of the USB device, including:

[0065] Modify the configuration descriptor of the USB device and define an interface association descriptor; group each CDC class interface together according to the interface association descriptor to ensure that each CDC class interface can be identified as part of the USB device.

[0066] In this embodiment, the configuration descriptor of the CDC class generally includes two interfaces, one control interface and the other data interface. In addition, there is an IAD pointed to by a dotted line, which indicates whether the interface is optional. Whether it actually exists depends on the actual situation. To implement CDC multi-serial ports, IAD must be used for setting. Through IAD, the device type of the corresponding interface enumeration and the interface used can be set. IAD is used in USB devices to group multiple interfaces together to facilitate the operating system to process these interfaces. In the case of implementing multiple virtual serial ports, IAD can correctly associate multiple CDC class interfaces that share certain common features. It is usually used to group multiple interfaces of the same type together, which can avoid the operating system from treating these interfaces as independent devices, ensuring that they are identified as part of a device, and reducing the complexity of device identification and management.

[0067] In an optional implementation of the first aspect of the present invention, obtaining a PMA memory address of a USB device, and allocating a corresponding PMA memory to an endpoint according to the PMA memory address includes:

[0068] Determine the memory size of the endpoint; obtain the data buffer size and the starting address of the data buffer of the endpoint; obtain the PMA memory address of the USB device, and allocate the corresponding PMA memory to the endpoint through the control register according to the PMA memory address, the data buffer size and the starting address of the data buffer.

[0069] In this embodiment, first, determine the memory size required for each endpoint. For example, if the maximum packet size of an endpoint is 64 bytes, then 64 bytes of memory need to be allocated for the endpoint. Typically, it is also necessary to allocate an additional descriptor area for each endpoint, and to allocate and initialize the memory area for each endpoint in the PMA. In addition, when setting the PMA memory, it is also necessary to configure the descriptor and status of each endpoint, including: clearing the control flag to ensure that the control flag of the endpoint is cleared for new data transmission; configuring the data buffer to set the size and direction (IN / OUT) of the data buffer for each endpoint. Allocate the corresponding PMA memory to the endpoint through the control register, and finally, configure the PC-side driver to identify and configure these endpoints.

[0070] In an optional implementation of the first aspect of the present invention, the operation function includes a data receiving function and a data sending function; according to the endpoint, configuring the operation function of each CDC class interface includes: obtaining the address, type and maximum data packet size of the endpoint; determining the data receiving function and the data sending function according to the address, type and maximum data packet size of the endpoint; and processing the reception and sending of data packets of the USB device according to the data receiving function and the data sending function.

[0071] In this embodiment, the USB endpoint needs to be initialized. When initializing the USB endpoint, the endpoint attributes, such as the address, type, and maximum packet size, need to be set. The endpoint buffer also needs to be set, and the buffer needs to be configured according to the maximum packet size. Each CDC class interface requires two endpoints: one for receiving data (IN endpoint) and one for sending data (OUT endpoint). The operation function of each CDC class interface is configured. The operation function of each CDC class interface processes the data according to the configuration of the endpoint. The operation function includes a data receiving function and a data sending function. The data receiving function and the data sending function are used to process the reception and transmission of USB data packets.

[0072] In an optional implementation of the first aspect of the present invention, the operation function further includes an interrupt processing function, and the interrupt processing function is used to process the reception data and the transmission data of the USB device.

[0073] In this embodiment, the interrupt processing function is used to process receiving and sending data. When receiving data, the interrupt processing function first determines whether there is data to be read in the receiving buffer. If there is data to be read, the data is taken out of the buffer and processed. After processing, if there is still data to be read in the buffer, the processing continues until all the data in the buffer is processed. When sending data, the interrupt processing function first determines whether there is free space available in the sending buffer. If there is free space available, the data to be sent is written into the buffer and the sending pointer is increased by 1; if the sending buffer is full, wait for the next interrupt processing function call.

[0074] In an optional implementation of the first aspect of the present invention, when a USB device is connected to a USB port on a PC, the USB device sends a device descriptor to the PC so that the PC identifies the USB device; the PC loads a driver so that the PC communicates with the USB device, and the driver is configured to identify endpoints of the USB device and process data transmission of the endpoints.

[0075] In this embodiment, after configuring the PMA memory, the PC driver is configured. On the PC side, the driver needs to identify and configure these endpoints. Usually, the operating system can automatically identify standard USB devices and load the corresponding driver. In order to ensure that all functions work properly, the driver modification needs to ensure that the driver correctly identifies multiple endpoints of the device and ensures that the driver can correctly process data transmitted from and to the device.

[0076] See also Figure 2 A second aspect of the present invention provides a device for implementing multiple virtual serial ports, the device comprising:

[0077] The device type modification module 10 is used to modify the device type of the USB device to a combined device type, so that the USB device supports multiple CDC class interfaces at the same time, and each CDC class interface is configured with an endpoint;

[0078] The endpoint memory allocation module 20 is used to obtain the PMA memory address of the USB device and allocate the corresponding PMA memory to the endpoint according to the PMA memory address. The PMA memory is used to store the data packets of the USB device.

[0079] A descriptor modification module 30, for modifying the configuration descriptor of the USB device, combining each CDC class interface together to ensure that each CDC class interface can be identified as part of the USB device;

[0080] The operation function configuration module 40 is used to configure the operation function of each CDC class interface according to the endpoint to process the reception and transmission of data packets of the USB device.

[0081] In an optional implementation of the second aspect of the present invention, the device type modification module 10 is also used to define a combined device descriptor in the device descriptor of the USB device, the combined device descriptor including multiple interface descriptors; according to the multiple interface descriptors, the endpoints and functions of each CDC class interface are configured in the combined device descriptor; in the firmware of the USB device, the device descriptor of the USB device is modified to the defined combined device descriptor, so that the USB device supports multiple CDC class interfaces at the same time.

[0082] In an optional implementation of the second aspect of the present invention, the descriptor modification module 30 is also used to modify the configuration descriptor of the USB device and define an interface association descriptor; according to the interface association descriptor, each CDC class interface is combined together to ensure that each CDC class interface can be identified as part of the USB device.

[0083] In an optional implementation of the second aspect of the present invention, the endpoint memory allocation module 20 is also used to determine the memory size of the endpoint; obtain the data buffer size and the data buffer starting address of the endpoint; obtain the PMA memory address of the USB device, and allocate corresponding PMA memory to the endpoint through the control register according to the PMA memory address, the data buffer size and the data buffer starting address of the endpoint.

[0084] In an optional implementation of the second aspect of the present invention, the multi-virtual serial port implementation device further includes:

[0085] The data receiving and sending module is used to obtain the address, type and maximum data packet size of the endpoint; determine the data receiving function and the data sending function according to the address, type and maximum data packet size of the endpoint; and process the reception and transmission of data packets of the USB device according to the data receiving function and the data sending function.

[0086] In an optional implementation of the second aspect of the present invention, the multi-virtual serial port implementation device further includes:

[0087] The driver module is used when the USB device is connected to the USB port of the PC. The USB device sends a device descriptor to the PC so that the PC can identify the USB device. The PC loads the driver so that the PC can communicate with the USB device. The driver is configured to identify the endpoints of the USB device and handle the data transmission of the endpoints.

[0088] Figure 31 is a schematic diagram of the structure of a multi-virtual serial port implementation device provided by an embodiment of the present invention. The multi-virtual serial port implementation device 500 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 (for example, one or more mass storage devices) storing application programs 533 or data 532. Among them, the memory 520 and the storage medium 530 can be temporary storage or permanent storage. The program stored in the storage medium 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the multi-virtual serial port implementation device 500. Furthermore, the processor 510 can be configured to communicate with the storage medium 530 to execute a series of instruction operations in the storage medium 530 on the multi-virtual serial port implementation device 500.

[0089] The device 500 based on multiple virtual serial ports may also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input and output interfaces 560, and / or one or more operating systems 531, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. It can be understood by those skilled in the art that Figure 3 The illustrated structure of the device for implementing multiple virtual serial ports does not constitute a limitation on the device for implementing multiple virtual serial ports, and may include more or less components than those illustrated, or may combine certain components, or may have different component arrangements.

[0090] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the method for implementing multiple virtual serial ports.

[0091] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0092] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.

[0093] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

Claims

1. A method for implementing multiple virtual serial ports, characterized in that: The method for implementing multiple virtual serial ports includes: Modify the device type of the USB device to a combined device type, so that the USB device supports multiple CDC class interfaces at the same time, and each of the CDC class interfaces is configured with an endpoint; Acquire a PMA memory address of the USB device, and allocate a corresponding PMA memory to the endpoint according to the PMA memory address, wherein the PMA memory is used to store data packets of the USB device; Modifying the configuration descriptor of the USB device to group each of the CDC class interfaces together to ensure that each of the CDC class interfaces can be identified as part of the USB device; According to the endpoint, an operation function of each of the CDC class interfaces is configured to process the reception and transmission of data packets of the USB device.

2. The method for implementing multiple virtual serial ports according to claim 1, characterized in that: The step of modifying the device type of the USB device to a combined device type so that the USB device supports multiple CDC class interfaces simultaneously comprises: Defining a combined device descriptor in the device descriptor of the USB device, wherein the combined device descriptor includes a plurality of interface descriptors; According to the plurality of interface descriptors, configuring the endpoints and functions of each of the CDC class interfaces in the combined device descriptor; In the firmware of the USB device, the device descriptor of the USB device is modified to a defined combined device descriptor, so that the USB device supports multiple CDC class interfaces simultaneously.

3. The method for implementing multiple virtual serial ports according to claim 1, characterized in that: The part of modifying the configuration descriptor of the USB device to group each of the CDC class interfaces together to ensure that each of the CDC class interfaces can be identified as the USB device includes: Modify the configuration descriptor of the USB device and define an interface association descriptor; Each of the CDC class interfaces is grouped together according to the interface association descriptor to ensure that each of the CDC class interfaces can be identified as part of the USB device.

4. The method for implementing multiple virtual serial ports according to claim 1, characterized in that: The obtaining of the PMA memory address of the USB device and allocating corresponding PMA memory to the endpoint according to the PMA memory address comprises: determining a memory size of the endpoint; Obtain the data buffer size and the starting address of the data buffer of the endpoint; The PMA memory address of the USB device is obtained, and the corresponding PMA memory is allocated to the endpoint through a control register according to the PMA memory address, the data buffer size of the endpoint, and the data buffer start address.

5. The method for implementing multiple virtual serial ports according to claim 1, characterized in that: The operation function includes a data receiving function and a data sending function; According to the endpoint, configuring the operation function of each CDC class interface includes: Obtaining the address, type and maximum packet size of the endpoint; Determine the data receiving function and the data sending function according to the address, type and maximum data packet size of the endpoint; The receiving and sending of data packets of the USB device are processed according to the data receiving function and the data sending function.

6. The method for implementing multiple virtual serial ports according to claim 5, characterized in that: The operation function also includes an interrupt processing function, and the interrupt processing function is used to process the received data and the sent data of the USB device.

7. The method for implementing multiple virtual serial ports according to claim 1, characterized in that: When the USB device is connected to a USB port on a PC, the USB device sends a device descriptor to the PC so that the PC can identify the USB device. The PC side loads a driver so that the PC side communicates with the USB device. The driver is configured to identify endpoints of the USB device and process data transmission of the endpoints.

8. A device for realizing multiple virtual serial ports, characterized in that: The multi-virtual serial port implementation device comprises: A device type modification module, used for modifying the device type of a USB device to a combined device type, so that the USB device supports multiple CDC class interfaces at the same time, each of which is configured with an endpoint; An endpoint memory allocation module, used for acquiring the PMA memory address of the USB device, and allocating corresponding PMA memory to the endpoint according to the PMA memory address, wherein the PMA memory is used for storing data packets of the USB device; A descriptor modification module, used to modify the configuration descriptor of the USB device, and group each of the CDC class interfaces together to ensure that each of the CDC class interfaces can be identified as part of the USB device; The operation function configuration module is used to configure the operation function of each of the CDC class interfaces according to the endpoints to process the reception and transmission of data packets of the USB device.

9. A device for implementing multiple virtual serial ports, characterized in that: The multi-virtual serial port implementation device comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instruction in the memory to enable the multi-virtual serial port implementation device to execute the multi-virtual serial port implementation method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for realizing multiple virtual serial ports according to any one of claims 1 to 7 is implemented.