Multi-protocol serial port virtualization communication method and system based on half-duplex bus

By virtualizing the physical serial port of the half-duplex bus into multiple virtual channels, the problem of poor compatibility of multiple protocols on the same bus is solved, enabling parallel development and independent operation of multiple protocols, improving communication accuracy and system flexibility, and reducing hardware costs.

CN121841889APending Publication Date: 2026-04-10BEIJING HYSINE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-26
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

In existing bus communication schemes, it is difficult to support multiple protocols simultaneously on the same physical bus, which leads to communication anomalies, development and maintenance difficulties, and problems such as half-duplex characteristics and poor multi-protocol compatibility.

Method used

By virtualizing a single physical serial port of a half-duplex bus into multiple virtual channels at the software level, with each virtual channel bound to independent communication parameters, parallel development and independent operation of multiple protocols are achieved. A virtualization management module is used to uniformly arbitrate and schedule access, avoiding physical serial port conflicts.

Benefits of technology

It enables multiple protocols to run independently on the same physical bus, reducing development and maintenance difficulty, improving communication accuracy and system flexibility, and reducing hardware costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121841889A_ABST
    Figure CN121841889A_ABST
Patent Text Reader

Abstract

The invention provides a multi-protocol serial port virtualization communication method and system based on a half-duplex bus. A half-duplex bus and a single physical serial port are used for communication between multiple applications and physical equipment, the physical serial port is abstracted into multiple virtual channels corresponding to the multiple applications, and each virtual channel is mapped into logic serial port equipment and is bound with different communication parameters. The communication method comprises the following steps: detecting whether a physical serial port is idle or not in response to a received access request of an application to a corresponding virtual channel; if yes, the application and the virtual channel corresponding to the application serve as the current application and the current virtual channel, the physical serial port is distributed to the current virtual channel, and communication parameters of the physical serial port are switched to be consistent with the current virtual channel, so that the current application conducts communication through the current virtual channel; and if not, enabling the virtual channel corresponding to the application to be in a blocked state, and enabling the application to enter a waiting state. Multi-protocol parallel development and independent operation are realized, and physical serial port conflicts are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of bus communication technology, and in particular to a multi-protocol serial port virtualization communication method and system based on a half-duplex bus. Background Technology

[0002] In applications such as building automation, industrial control, and energy management, communication methods based on half-duplex buses (such as RS-485) are widely used. The basic characteristic of this type of bus communication is that only one device is allowed to send data on the bus at any given time, thus requiring strict timing management.

[0003] In existing bus communication schemes, all devices on the same physical bus often need to use the same communication parameters; otherwise, communication errors will occur. Therefore, in traditional designs, if devices with different protocols or parameters need to be connected, additional independent physical lines are usually required. This not only increases wiring and construction costs but also reduces system flexibility. If a mixed-connection method is adopted, connecting devices with different protocols and baud rates to the same bus, problems such as half-duplex limitations, poor multi-protocol compatibility, and difficulties in development and maintenance will arise at the software development level.

[0004] Therefore, how to support multiple protocols on a single physical bus while reducing the difficulty of development and maintenance has become an urgent problem to be solved. Summary of the Invention

[0005] In view of the above problems, the present invention provides a method and system for multi-protocol serial port virtualization communication based on a half-duplex bus to overcome or at least partially solve the above problems.

[0006] One objective of this invention is to enable parallel development and independent operation of multiple protocols, thereby avoiding the problem of physical serial port conflicts.

[0007] A further objective of this invention is to improve the accuracy and reliability of communication.

[0008] Specifically, according to one aspect of the present invention, a multi-protocol serial port virtualization communication method based on a half-duplex bus is provided, wherein the half-duplex bus and a single physical serial port are used for communication between multiple applications and a physical device, the physical serial port is abstracted into multiple virtual channels corresponding to multiple applications, each virtual channel is mapped to a logical serial port device and bound to communication parameters corresponding to its application; the communication method includes: In response to receiving an application's access request for its corresponding virtual channel, check whether the physical serial port is idle; If so, using the application and its corresponding virtual channel as the current application and the current virtual channel, assign the physical serial port to the current virtual channel and switch the communication parameters of the physical serial port to be consistent with the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel; If not, the virtual channel corresponding to the application will be blocked, and the application will enter a waiting state.

[0009] Optionally, after the current application has completed communicating with the physical device through the current virtual channel, the communication method further includes: Release the current virtual channel and release the current virtual channel from its occupation of the physical serial port; Detect whether any applications are in a waiting state; If they exist, the application that first enters the waiting state and its corresponding virtual channel are taken as the current application and the current virtual channel. The physical serial port is assigned to the current virtual channel, and the communication parameters of the physical serial port are switched to be consistent with those of the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel.

[0010] Optionally, if there are multiple applications in a waiting state, each application and its corresponding virtual channel are used as the current application and the current virtual channel in the order in which they entered the waiting state, until all applications in the waiting state have completed communication with the physical device.

[0011] Optionally, the number of physical devices can be multiple; When the current application communicates with physical devices, each physical device receives data frames sent by the current application and identifies or verifies the received data frames; if identification or verification fails, the data frame is discarded.

[0012] Optionally, if a physical device successfully identifies or verifies a data frame, the physical device sends a communication success message to the current application.

[0013] Optionally, the communication parameters include at least one of the following: Protocol, baud rate, data bits, parity bits.

[0014] According to another aspect of the present invention, a multi-protocol serial port virtualization communication system based on a half-duplex bus is also provided, comprising: The application layer includes multiple applications; Physical equipment; A half-duplex bus for connecting to physical devices; A single physical serial port, connected to a half-duplex bus, and the half-duplex bus and the physical serial port are used for communication between multiple applications and the physical device; and The virtualization management module is configured to abstract physical serial ports into multiple virtual channels corresponding to multiple applications. Each virtual channel is mapped to a logical serial port device and bound to the corresponding communication parameters of its application. The virtualization management module is also configured as follows: In response to receiving an application's access request for its corresponding virtual channel, check whether the physical serial port is idle; If so, using the application and its corresponding virtual channel as the current application and the current virtual channel, assign the physical serial port to the current virtual channel and switch the communication parameters of the physical serial port to be consistent with the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel; If not, the virtual channel corresponding to the application will be blocked, and the application will enter a waiting state.

[0015] Optionally, the virtualization management module is also configured as follows: After the current application finishes communicating with the physical device through the current virtual channel, release the current virtual channel and release the current virtual channel from the physical serial port. Detect whether any applications are in a waiting state; If they exist, the application that first enters the waiting state and its corresponding virtual channel are taken as the current application and the current virtual channel. The physical serial port is assigned to the current virtual channel, and the communication parameters of the physical serial port are switched to be consistent with those of the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel.

[0016] Optionally, the virtualization management module is also configured as follows: When multiple applications are in a waiting state, each application and its corresponding virtual channel are used as the current application and the current virtual channel in the order in which they entered the waiting state, until all applications in the waiting state have completed communication with the physical device.

[0017] Optionally, the number of physical devices can be multiple; The physical equipment is configured as follows: When the current application communicates with the physical device, it receives data frames sent by the current application and identifies or verifies the received data frames. If identification or verification fails, the data frame is discarded. If the identification or verification is successful, a communication success message is sent to the current application.

[0018] In the multi-protocol serial port virtualization communication method and system based on a half-duplex bus proposed in this invention, the single physical serial port of the half-duplex bus is abstracted into multiple virtual channels. Each virtual channel corresponds to a logical serial port device, and these multiple virtual channels correspond to multiple applications and can be independently bound to different communication parameters. Whenever an application receives an access request for its corresponding virtual channel, the physical serial port is first checked for idleness. If the physical serial port is idle, the application and its corresponding virtual channel are designated as the current application and current virtual channel, respectively. The physical serial port is allocated to the current virtual channel, and the communication parameters of the physical serial port are switched to match those of the current virtual channel, allowing the current application to communicate with the physical device through the current virtual channel. If the physical serial port is occupied, the virtual channel corresponding to the requesting application is blocked, preventing it from accessing the physical serial port, and the requesting application enters a waiting state. The technical solution of this invention virtualizes the physical serial port at the software layer, providing multiple independent virtual channels to upper-layer applications. This allows upper-layer applications to interact with the physical serial port through their respective virtual channels without interference. At the same time, unified arbitration and scheduling are performed on access to the physical serial port to ensure that only one virtual channel occupies the physical serial port at any given time. This enables parallel development and independent operation of multiple protocols, avoiding the problem of physical serial port conflicts.

[0019] Furthermore, in the multi-protocol serial port virtualization communication method and system based on a half-duplex bus proposed in this invention, after the current application completes communication, the corresponding current virtual channel is released, and the right to use the physical serial port is switched to other virtual channels so that waiting applications can communicate, thereby realizing multiple protocols communicating in turn on the same physical bus.

[0020] Furthermore, in the multi-protocol serial port virtualization communication method and system based on half-duplex bus proposed in this invention, when multiple applications are waiting for the use of the channel, the right to use the physical serial port is allocated one by one according to the order of waiting, ensuring that each virtual channel has the opportunity to communicate.

[0021] Furthermore, in the multi-protocol serial port virtualization communication method and system based on half-duplex bus proposed in this invention, when each application communicates with the physical device, the physical device identifies or verifies the data frames received from the application and discards data frames that cannot be identified or fail to be verified, so as to avoid error propagation and thus improve communication accuracy and reliability.

[0022] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below.

[0023] The above and other objects, advantages and features of the present invention will become more apparent to those skilled in the art from the following detailed description of specific embodiments of the invention in conjunction with the accompanying drawings. Attached Figure Description

[0024] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 A flowchart illustrating a multi-protocol serial port virtualization communication method based on a half-duplex bus according to an embodiment of the present invention is shown. Figure 2 A flowchart illustrating a multi-protocol serial port virtualization communication method based on a half-duplex bus according to another embodiment of the present invention is shown. Figure 3 A schematic block diagram of a multi-protocol serial port virtualization communication system based on a half-duplex bus according to an embodiment of the present invention is shown. Detailed Implementation

[0025] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.

[0026] In existing bus communication schemes, all devices on the same physical bus often need to use the same communication parameters. However, in non-critical applications such as building automation, occasional communication errors are tolerable. Therefore, in practical engineering, connecting devices with different protocols and baud rates to the same bus is a cost-effective solution.

[0027] However, this hybrid connection method has the following difficulties in software development: (1) Half-duplex limitation: Only one application can interact with the bus at the same time, and multiple applications using the serial port in parallel are prone to conflicts. (2) Poor compatibility of multiple protocols: If multiple protocols are handled in the same serial port driver, the logic is complex and they are prone to mutual interference. (3) Difficulty in development and maintenance: The code is highly coupled, which is not convenient for multiple people to develop in parallel or for subsequent expansion.

[0028] To address the above problems and difficulties, this invention provides a multi-protocol serial port virtualization communication method based on a half-duplex bus.

[0029] In the multi-protocol serial port virtualization communication method based on half-duplex bus of the present invention, half-duplex bus and a single physical serial port are used for communication between multiple applications and physical devices. The physical serial port is abstracted into multiple virtual channels corresponding to multiple applications respectively. Each virtual channel is mapped to a logical serial port device, and each virtual channel is bound to the corresponding communication parameters of its application.

[0030] Figure 1 A flowchart illustrating a multi-protocol serial port virtualization communication method based on a half-duplex bus according to an embodiment of the present invention is shown. Figure 1 As shown, the multi-protocol serial port virtualization communication method based on a half-duplex bus may include at least the following steps S102 to S106.

[0031] Step S102: In response to receiving an application's access request for its corresponding virtual channel, check whether the physical serial port is idle. If yes, that is, the physical serial port is in an idle state, then proceed to step S104; if no, that is, the physical serial port is in an occupied state, then proceed to step S106.

[0032] Step S104: Using the application and its corresponding virtual channel as the current application and the current virtual channel, assign the physical serial port to the current virtual channel and switch the communication parameters of the physical serial port to be consistent with the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel.

[0033] Step S106: The virtual channel corresponding to the application is blocked, and the application is put into a waiting state.

[0034] Optionally, the moment when the application enters a waiting state can be recorded.

[0035] In the multi-protocol serial port virtualization communication method based on a half-duplex bus proposed in this invention, the single physical serial port of the half-duplex bus is abstracted into multiple virtual channels. Each virtual channel corresponds to a logical serial port device, and these multiple virtual channels correspond to multiple applications and can be independently bound to different communication parameters. Whenever an application receives an access request for its corresponding virtual channel, the physical serial port is first checked for idleness. If the physical serial port is idle, the application and its corresponding virtual channel are designated as the current application and current virtual channel, respectively. The physical serial port is allocated to the current virtual channel, and the communication parameters of the physical serial port are switched to match those of the current virtual channel, allowing the current application to communicate with the physical device through the current virtual channel. If the physical serial port is occupied, the virtual channel corresponding to the requesting application is blocked, preventing it from accessing the physical serial port, and the requesting application enters a waiting state.

[0036] The technical solution of this invention virtualizes the physical serial port at the software layer, providing multiple independent virtual channels to upper-layer applications. This allows upper-layer applications to interact with the physical serial port through their respective virtual channels without interference. At the same time, unified arbitration and scheduling are performed on access to the physical serial port to ensure that only one virtual channel occupies the physical serial port at any given time. This enables parallel development and independent operation of multiple protocols, avoiding the problem of physical serial port conflicts.

[0037] In some embodiments, communication parameters may include at least one of the following: protocol, baud rate, data bits, parity bits, etc.

[0038] Figure 2 A flowchart illustrating a multi-protocol serial port virtualization communication method based on a half-duplex bus according to another embodiment of the present invention is shown.

[0039] like Figure 2 As shown, in some embodiments, after the current application has completed communication through the current virtual channel, the multi-protocol serial port virtualization communication method based on a half-duplex bus may further include the following steps: Step S108: Release the current virtual channel and release the current virtual channel from the physical serial port.

[0040] Step S110: Check if there are any applications in a waiting state; if so, proceed to step S112. If there are no applications in a waiting state, end the current process.

[0041] Step S112: Taking the application that first entered the waiting state and its corresponding virtual channel as the current application and the current virtual channel, the physical serial port is assigned to the current virtual channel, and the communication parameters of the physical serial port are switched to be consistent with those of the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel. It can be understood that at this point, after assigning the physical serial port to the current virtual channel, the original blocking state of the virtual channel is released.

[0042] In this embodiment, after the current application completes communication, the corresponding current virtual channel is released, and the right to use (access right) the physical serial port is switched to other virtual channels so that the waiting application can communicate with the physical device, thereby enabling multiple protocols to communicate in turn on the same physical bus.

[0043] See also Figure 2 In some embodiments, when there are multiple applications in a waiting state, each application and its corresponding virtual channel are used as the current application and the current virtual channel in the order in which they entered the waiting state, until all applications in the waiting state have completed communication with the physical device.

[0044] In other words, such as Figure 2As shown, after step S112, the process returns to step S108 and repeats steps S108 to S112 until there are no more applications in a waiting state, at which point the current process ends.

[0045] Optionally, the order in which applications enter the waiting state can be determined based on the recorded times when the applications enter the waiting state.

[0046] In this embodiment, when multiple applications are waiting for the channel to be used, the right to use the physical serial port is allocated one by one according to the order of waiting, so as to ensure that each virtual channel has the opportunity to communicate.

[0047] by Figure 2 Taking the illustrated embodiment as an example, the technical solution of the present invention has the following characteristics: First, the virtualization layer design. By adding a virtualization program at the operating system level or driver level, access to the physical serial port is managed uniformly, and all data transmission and reception of the virtual channels are handled by this virtualization program.

[0048] Second, the channel exclusivity mechanism. When a virtual channel is in use, other virtual channels are blocked and cannot access the physical serial port. After the currently used virtual channel is released, the virtualization program can switch the right to use the physical serial port to another virtual channel.

[0049] Third, protocol isolation. Each virtual channel can be independently bound to serial communication parameters (such as protocol, baud rate, data bits, parity bits, etc.). When switching channels, the virtualization program can automatically modify the communication parameters of the physical serial port to match the needs of the current virtual channel.

[0050] In some embodiments, the number of physical devices can be multiple. In this half-duplex bus-based multi-protocol serial port virtualization communication method, when the current application communicates with the physical devices, each physical device receives data frames sent by the current application and identifies or verifies the received data frames. If identification or verification fails, the physical device discards the data frame.

[0051] This embodiment introduces an error control mechanism. When each application communicates with the physical device, the physical device identifies or verifies the data frames received from the application and discards data frames that cannot be identified or fail to be verified, so as to avoid the spread of errors and improve the accuracy and reliability of communication.

[0052] In some embodiments, in this multi-protocol serial port virtualization communication method based on a half-duplex bus, if a physical device successfully identifies or verifies a data frame, the physical device sends a communication success message to the current application.

[0053] In embodiments of the present invention, a status feedback mechanism is introduced to allow upper-layer applications to determine whether data has been successfully sent and whether communication has been successful.

[0054] Based on the same technical concept, the present invention also provides a multi-protocol serial port virtualization communication system 300 based on a half-duplex bus.

[0055] Figure 3 A schematic block diagram of a multi-protocol serial port virtualization communication system 300 based on a half-duplex bus according to an embodiment of the present invention is shown. Figure 3 As shown, a multi-protocol serial port virtualization communication system 300 based on a half-duplex bus can generally include: a single physical serial port 310, a half-duplex bus 340, an application layer 320, a virtualization management module 330, and a physical device 350.

[0056] The half-duplex bus 340 can use actual RS-485 or other half-duplex buses.

[0057] The physical serial port 310 is connected to the half-duplex bus 340. For example, the physical serial port 310 can be a ttyUSB0. The physical serial port 310 constitutes the physical serial port layer, serving as the underlying hardware for application 321 to communicate (i.e., send and receive data) with external physical device 350.

[0058] The application layer 320 includes multiple applications 321 on the upper layer. Applications 321 can be third-party programs or drivers. Multiple applications 321 can have different communication parameters, for example, using different application layer protocols, such as Modbus RTU protocol, 188 protocol, third-party proprietary protocols, etc.

[0059] Physical device 350 can be field devices, such as Modbus RTU devices, 188 meters, etc.

[0060] The virtualization management module 330 consists of a virtualization management program. As the core module, the virtualization management module 330 is configured to abstract a single physical serial port 310 into multiple virtual channels 311, thereby providing multiple virtual channel interfaces to be exposed to the upper-layer application 321.

[0061] Each virtual channel 311 is mapped to a logical serial port device, such as COMv1, COMv2, COMv3, etc., to be exposed to multiple upper-layer applications 321. These multiple virtual channels 311 correspond to multiple applications 321 and are bound to the corresponding communication parameters of their respective applications 321. For example, different virtual channels 311 can be bound to different baud rates, such as 9600 / 19200 / 115200 baud rates, etc.

[0062] The virtualization management module 330 is also responsible for unified scheduling and arbitration of access to the physical serial port 310, so that various protocol drivers or upper-layer applications can independently send and receive data through their respective virtual channels 311.

[0063] Specifically, the virtualization management module 330 is also configured as follows: In response to receiving an access request from an application 321 to its corresponding virtual channel 311, check whether the physical serial port 310 is idle; If so, take the application 321 and its corresponding virtual channel 311 as the current application 321 and the current virtual channel 311, assign the physical serial port 310 to the current virtual channel 311, and switch the communication parameters of the physical serial port 310 to be consistent with the current virtual channel 311, so that the current application 321 can communicate with the physical device 350 through the current virtual channel 311. If not, the virtual channel 311 corresponding to the application 321 will be blocked, and the application 321 will enter a waiting state.

[0064] It should be noted that, Figure 3 The number of virtual channels 311 and applications 321 shown are merely exemplary and do not limit the invention.

[0065] In some embodiments, the virtualization management module 330 is further configured to: After the current application 321 finishes communicating with the physical device 350 through the current virtual channel 311, the current virtual channel 311 is released, and the current virtual channel 311 is released from its occupation of the physical serial port 310. Detect if any applications are in a waiting state 321; If they exist, the application 321 that first enters the waiting state and its corresponding virtual channel 311 are taken as the current application 321 and the current virtual channel 311. The physical serial port 310 is assigned to the current virtual channel 311, and the communication parameters of the physical serial port 310 are switched to be consistent with those of the current virtual channel 311, so that the current application 321 can communicate with the physical device 350 through the current virtual channel 311.

[0066] In some embodiments, the virtualization management module 330 is further configured to: In the case of multiple applications 321 in a waiting state, each application 321 and its corresponding virtual channel 311 are used as the current application 321 and the current virtual channel 311 in the order in which they entered the waiting state, until all applications 321 in the waiting state have completed communication with the physical device 350.

[0067] In some embodiments, the number of physical devices 350 is multiple. These multiple physical devices 350 have different communication parameters, for example, they support different protocols.

[0068] Each physical device 350 can be configured as follows: When the current application 321 communicates with the physical device 350, it receives data frames sent by the current application 321 and identifies or verifies the received data frames. If identification or verification fails, the data frame is discarded.

[0069] In some embodiments, each physical device 350 may also be configured as follows: If the data frame is successfully identified or verified, a communication success message is sent to the current application 321.

[0070] The following is combined with Figure 3 An illustrative description is provided of the data flow during the communication process between application 321 and physical device 350.

[0071] Assume that among the multiple applications 321, the application supporting the first protocol is designated as the first application, and among the multiple physical devices 350, the physical device that also supports the first protocol is designated as the first physical device. When the first application sends data to the first physical device, the data is sent by the first application and sequentially passes through the virtual channel 311 corresponding to the first application, the virtualization management module 330, the physical serial port 310, and the half-duplex bus 340 to reach the first physical device. When the data is transmitted from the half-duplex bus 340 to the physical device 350, because the protocol of the first physical device matches that of the first application, the data verification is successful, and the first physical device successfully receives and processes the data. However, although other physical devices 350 also receive the data transmitted by the half-duplex bus 340, due to protocol and format mismatch, the data verification fails, and therefore the data is discarded without processing.

[0072] When the first physical device sends data to the first application, the data is sent by the first physical device and sequentially passes through the half-duplex bus 340, the physical serial port 310, the virtualization management module 330, and the virtual channel 311 corresponding to the first application before reaching the first application. While the data sent by the first physical device is being transmitted on the half-duplex bus 340, other physical devices 350 will also receive the data, but due to protocol and format mismatch and data verification errors, the data will be discarded.

[0073] Compared with the prior art, the present invention has the following advantages: (1) No need to lay additional physical lines for different protocols or baud rates, thereby reducing construction and hardware costs.

[0074] (2) Different protocol drivers can be developed independently without interfering with each other, thereby reducing code complexity and improving development efficiency.

[0075] (3) Multiple protocols and devices can be dynamically accessed on the same physical bus, improving system flexibility.

[0076] (4) Enhanced scalability, supporting multi-person parallel development, and facilitating subsequent maintenance and functional expansion.

[0077] Those skilled in the art will clearly understand that the specific working process of the systems, units and components described above can be referred to the corresponding process in the foregoing method embodiments. For the sake of brevity, it will not be repeated here.

[0078] Furthermore, the functional units in the various embodiments of the present invention can be physically independent of each other, or two or more functional units can be integrated together, or all functional units can be integrated into one processing unit. The integrated functional units described above can be implemented in hardware, or in software or firmware.

[0079] Those skilled in the art will understand that if the integrated functional unit is implemented in software and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or all or part of it, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computing device (e.g., a personal computer, server, or network device) to execute all or part of the steps of the methods described in the embodiments of the present invention when running the instructions. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0080] Alternatively, all or part of the steps of the foregoing method embodiments can be implemented by hardware (such as a computing device, personal computer, server, or network device) related to program instructions. The program instructions can be stored in a computer-readable storage medium. When the program instructions are executed by the processor of the computing device, the computing device executes all or part of the steps of the methods described in the various embodiments of the present invention.

[0081] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that within the spirit and principles of the present invention, modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein; and these modifications or substitutions do not cause the corresponding technical solutions to depart from the protection scope of the present invention.

Claims

1. A multi-protocol serial port virtualization communication method based on a half-duplex bus, characterized in that, The half-duplex bus and the single physical serial port are used for communication between multiple applications and physical devices. The physical serial port is abstracted into multiple virtual channels corresponding to the multiple applications. Each virtual channel is mapped to a logical serial port device and bound to the corresponding communication parameters of its application. The communication method includes: In response to receiving an application's access request for its corresponding virtual channel, the system checks whether the physical serial port is idle. If so, using the application and its corresponding virtual channel as the current application and the current virtual channel, the physical serial port is assigned to the current virtual channel, and the communication parameters of the physical serial port are switched to be consistent with the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel; If not, the virtual channel corresponding to the application will be blocked, and the application will enter a waiting state.

2. The multi-protocol serial port virtualization communication method based on a half-duplex bus according to claim 1, characterized in that, After the current application completes communication with the physical device through the current virtual channel, the communication method further includes: Release the current virtual channel and release the current virtual channel from its occupation of the physical serial port; Detect whether any applications are in a waiting state; If they exist, the application that first enters the waiting state and its corresponding virtual channel are taken as the current application and the current virtual channel. The physical serial port is assigned to the current virtual channel, and the communication parameters of the physical serial port are switched to be consistent with those of the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel.

3. The multi-protocol serial port virtualization communication method based on a half-duplex bus according to claim 2, characterized in that, In the case of multiple applications in a waiting state, each application and its corresponding virtual channel are used as the current application and the current virtual channel in the order in which they entered the waiting state, until all applications in the waiting state have completed communication with the physical device.

4. The multi-protocol serial port virtualization communication method based on a half-duplex bus according to any one of claims 1-3, characterized in that, The number of the physical devices is multiple; When the current application communicates with the physical device, each physical device receives a data frame sent by the current application and identifies or verifies the received data frame; if the identification or verification fails, the data frame is discarded.

5. The multi-protocol serial port virtualization communication method based on a half-duplex bus according to claim 4, characterized in that, If a physical device successfully identifies or verifies the data frame, the physical device sends a communication success message to the current application.

6. The multi-protocol serial port virtualization communication method based on a half-duplex bus according to any one of claims 1-3, characterized in that, The communication parameters include at least one of the following: Protocol, baud rate, data bits, parity bits.

7. A multi-protocol serial port virtualization communication system based on a half-duplex bus, characterized in that, include: The application layer includes multiple applications; Physical equipment; A half-duplex bus, connected to the physical device; A single physical serial port is connected to the half-duplex bus, and the half-duplex bus and the physical serial port are used for the multiple applications to communicate with the physical device; as well as The virtualization management module is configured to abstract the physical serial port into multiple virtual channels corresponding to the multiple applications, and each virtual channel is mapped to a logical serial port device and bound to the corresponding communication parameters of its application; The virtualization management module is further configured as follows: In response to receiving an application's access request for its corresponding virtual channel, the system checks whether the physical serial port is idle. If so, using the application and its corresponding virtual channel as the current application and the current virtual channel, the physical serial port is assigned to the current virtual channel, and the communication parameters of the physical serial port are switched to be consistent with the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel; If not, the virtual channel corresponding to the application will be blocked, and the application will enter a waiting state.

8. The multi-protocol serial port virtualization communication system based on a half-duplex bus according to claim 7, characterized in that, The virtualization management module is also configured as follows: After the current application finishes communicating with the physical device through the current virtual channel, the current virtual channel is released, and the current virtual channel is released from its occupation of the physical serial port. Detect whether any applications are in a waiting state; If they exist, the application that first enters the waiting state and its corresponding virtual channel are taken as the current application and the current virtual channel. The physical serial port is assigned to the current virtual channel, and the communication parameters of the physical serial port are switched to be consistent with those of the current virtual channel, so that the current application can communicate with the physical device through the current virtual channel.

9. The multi-protocol serial port virtualization communication system based on a half-duplex bus according to claim 8, characterized in that, The virtualization management module is also configured as follows: In the case of multiple applications in a waiting state, each application and its corresponding virtual channel are used as the current application and the current virtual channel in the order in which they entered the waiting state, until all applications in the waiting state have completed communication with the physical device.

10. The multi-protocol serial port virtualization communication system based on a half-duplex bus according to any one of claims 7-9, characterized in that, The number of the physical devices is multiple; The physical devices described are configured as follows: When the current application communicates with the physical device, the system receives data frames sent by the current application and identifies or verifies the received data frames. If identification or verification fails, the data frame is discarded; If the identification or verification is successful, a communication success message is sent to the current application.