Remote serial port control method, serial port control device and computer
By receiving and processing wireless data packets from the host computer through a serial port control device on the lower-level side, generating standard serial port data, and performing transparent transmission or logic control, the problem of redundant hardware resource configuration and high cost in traditional wireless serial communication is solved, and efficient data interaction and control are achieved.
Patent Information
- Application Number
- CN202611198116.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-07
- Publication Date
- 2026-11-03
AI Technical Summary
Traditional wireless serial communication solutions require separate wireless communication devices on both the host computer and the slave computer, leading to redundant hardware resource configuration, increased costs, and high deployment complexity.
A remote serial port control method and device are provided. The device receives wireless network data packets from the host computer, parses and generates standard serial port data, and transmits downlink service data to the external device through the target serial port hardware, or converts virtual logic signals into hardware execution instructions, thereby realizing bidirectional data interaction and logic control between the host computer and the external device.
It enables transparent transmission of business data and logical control between the host computer and external devices, reduces redundant hardware resource configuration and system costs, simplifies deployment complexity, and improves integrated control capabilities and scenario adaptability.
Smart Images

Figure CN123030535A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of serial communication control technology, specifically to a remote serial port control method, a serial port control device, and a computer. Background Technology
[0002] Data exchange between the host computer and the slave computer typically occurs via serial port devices. Traditional wireless serial communication solutions are usually implemented using a two-end separation architecture. This requires a separate wireless communication device on the host computer side to send network data out and receive data from the wireless network; and another separate wireless communication device on the slave computer side to receive data from the wireless network, convert it into a serial signal for transmission, and then send data uploaded by the slave computer back to the host computer via the wireless network. This two-end separation architecture leads to redundant hardware resource configuration, a sharp increase in cost, and the deployment and configuration of the separate wireless communication devices also increases the complexity of field deployment and subsequent maintenance. Summary of the Invention
[0003] In view of the above problems, embodiments of the present invention provide a remote serial port control method, a serial port control device, and a computer to solve the problem that traditional wireless serial communication adopts a two-end separation architecture, which requires configuring independent wireless communication devices on the host computer side and the slave computer side respectively.
[0004] According to one aspect of the present invention, a remote serial port control method is provided, the remote serial port control method being applied to a serial port control device; the serial port control device includes target serial port hardware and general-purpose input / output hardware, both the target serial port hardware and the general-purpose input / output hardware being electrically connected to an external device; the method includes: Receive data packets sent by the host computer via a wireless network; wherein, the data packets are obtained by the virtual serial port driver built into the host computer encapsulating the raw data sent by the application according to the network serial port mapping protocol; The data packet is parsed according to the network serial port mapping protocol to generate the standard serial port data; the standard serial port data includes at least one of downlink service data and virtual logic signals. When the standard serial port data contains the downlink service data, the downlink service data is transmitted transparently to the external device via the target serial port hardware; and / or the uplink service data transmitted back by the target serial port hardware is received, encapsulated according to the network serial port mapping protocol, and uploaded to the host computer. When the standard serial port data contains the virtual logic signal, the virtual logic signal is converted into a hardware execution instruction according to the preset conversion logic and sent to the general-purpose input / output hardware to output a control level to the external device.
[0005] In one alternative approach, the virtual logic signal includes at least one of RTS, CTS, DTR, DSR, DCD, RI, and / or includes API control commands.
[0006] In one optional approach, when the standard serial port data contains the virtual logic signal, converting the virtual logic signal into a hardware execution instruction according to a preset conversion logic and sending it to the general-purpose input / output hardware to output a control level to the external device includes: Based on the pre-stored target configuration file, locate the target input / output pins and target level states corresponding to the virtual logic signals; The driver interface of the general-purpose input / output hardware is invoked to drive the target input / output pin to output the target level state in order to output a control level to the external device; or the input level of the target input / output pin is sampled, the input level is converted into the logic state value of the virtual logic signal, and fed back to the host computer through the serial port access channel.
[0007] In an alternative approach, the standard serial port data further includes serial port configuration parameters; the method further includes performing parameter configuration on the target serial port hardware according to the serial port configuration parameters, including: According to the preset conversion logic, the baud rate value, data bit length value, parity mode value, stop bit length value, and flow control strategy value in the serial port configuration parameters are converted into the corresponding configuration words of the target serial port hardware. Write the configuration word into the hardware configuration register corresponding to the target serial port hardware.
[0008] In one optional embodiment, the serial port control device is provided with at least two types of communication access channels for communication with the host computer: a wired communication channel and a wireless communication channel. The data packets are parsed according to the network serial port mapping protocol to generate the standard serial port data. The standard serial port data includes at least one of downlink service data and virtual logic signals, including: When the data packet is sent to the wired communication channel via a wired communication connection, the wired communication channel generates the standard serial port data from the data packet; wherein, the data packet is encapsulated by the virtual serial port driver according to the USB CDC protocol; When the data packet is sent to the wireless communication channel via the wireless communication connection, the wired communication channel generates the standard serial port data from the data packet; wherein the network serial port mapping protocol is the RFC 2217 protocol.
[0009] In one alternative approach, before receiving the data packets sent by the host computer via the wireless network, the method further includes: Receive a session request sent by the host computer, identify the channel identifier carried in the session request, and obtain the corresponding communication access channel; Query the status of the resource locks bound to the target serial port hardware and the general input / output hardware; When the resource lock is in an idle state, the target serial port hardware and the general-purpose input / output hardware are connected to the corresponding communication access channel to establish a session connection; When the resource lock is in an occupied state, the session request is rejected and a device busy prompt is returned to the host computer.
[0010] In one alternative approach, the serial port control device further includes at least one of the following extended communication access channels: Mod TCP communication channel, private TCP communication channel, WebSocket communication channel, and Bluetooth communication channel.
[0011] In an optional embodiment, the serial port control device further includes a storage medium and a log writing module, and the method further includes: the log writing module determining the current operating mode of the serial port control device, the operating mode including serial port mode and offline mode, including: Real-time monitoring and acquisition of the interaction log stream of the target serial port hardware, and recording index information and event information; The acquired interaction log stream is written to the storage medium; the interaction log stream includes at least the serial port data transmitted and received by the target serial port hardware. In the serial port mode, the index information includes one or more of the following: operation identifier, type of serial port access channel, serial port parameters, start and end times of log recording, and byte count; the event information includes one or more of the following: connection establishment and disconnection of session requests, resource lock acquisition and release, and level state changes of the general-purpose input / output hardware. In the offline mode, the index information includes at least one or more of the following: the operation identifier, the start and end times of the log record, the byte count, and the log file storage location; the event information includes one or more of the following: the log record start event, the log record stop event, and the storage medium status event.
[0012] According to a second aspect of the present invention, a serial port control device is provided, the serial port control device including target serial port hardware and general-purpose input / output hardware, wherein the target serial port hardware and the general-purpose input / output hardware are both electrically connected to an external device; the serial port control device further includes: The receiving module is used to receive data packets sent by the host computer through a wireless network; wherein, the data packets are obtained by the virtual serial port driver built into the host computer encapsulating the raw data sent by the application according to the network serial port mapping protocol; A serial port bridging module is used to parse the data packets according to the network serial port mapping protocol and generate the standard serial port data; the standard serial port data includes at least one of downlink service data and virtual logic signals; The central scheduling module is used to transmit the downlink service data through the target serial port hardware to the external device when the standard serial port data contains the downlink service data; and / or receive the uplink service data returned by the target serial port hardware, encapsulate it according to the network serial port mapping protocol, and upload it to the host computer; when the standard serial port data contains the virtual logic signal, convert the virtual logic signal into a hardware execution instruction according to a preset conversion logic, and send it to the general-purpose input / output hardware to output a control level to the external device.
[0013] According to a third aspect of the present invention, a computer device is provided, comprising a serial port control device provided in the second aspect above, a host computer communicatively connected to the serial port control device, and an external device electrically connected to a target serial port hardware and control hardware of the serial port control device; the serial port control device performs the operation of the remote serial port control method as described in any one of the first aspects above.
[0014] The remote serial port control method provided in this invention is applied to a serial port control device to achieve bidirectional data interaction between a host computer and an external device. The serial port control device is located on the side of the external device (lower-level device), and is electrically connected to the external device through the target serial port hardware and the general-purpose input / output hardware. The serial port control device receives data packets sent by the host computer via a wireless network, which are encapsulated by a virtual serial port driver according to a network serial port mapping protocol. It parses and generates standard serial port data, and performs splitting processing on the standard serial port data: downlink service data is transparently transmitted to the external device through the target serial port hardware, and virtual logic signals are converted into hardware execution instructions according to preset conversion logic and sent to the general-purpose input / output hardware to output control levels. The serial port control device with wireless and wired serial communication modes provided in this invention uses a central scheduling module to select the target serial port hardware and general-purpose input / output hardware to transmit data to the lower-level device according to the data type received from the host computer, thus realizing the coordinated management of service data communication and IO control. It fundamentally solves the technical problems of traditional wireless serial communication, which requires a two-end separation architecture and separate wireless communication devices on the host computer and slave computer sides, resulting in redundant hardware resource configuration, high system cost, and complex deployment.
[0015] This invention provides a serial port control device with a built-in network serial port mapping protocol server that works in conjunction with a virtual serial port driver on the host computer side. This allows the host computer's application program to control external devices by sending data packets through the virtual serial port driver without needing to modify its network programming interface, significantly reducing software development difficulty and maintenance costs. Furthermore, this invention not only enables bidirectional transparent transmission of business data between the host computer and the external device, but also achieves remote logic control of the serial port control device's general input / output hardware through preset conversion logic. This allows the host computer to directly control the voltage levels of external devices through virtual logic signals without requiring additional hardware, further enhancing the integrated control capabilities and scenario adaptability of the serial port control device.
[0016] The above description is merely an overview of the technical solutions of the embodiments of the present invention. In order to better understand the technical means of the embodiments of the present invention and to implement them in accordance with the contents of the specification, and to make the above and other objects, features and advantages of the embodiments of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0017] 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 the remote serial port control method provided in an embodiment of the present invention is shown. Figure 2 This diagram illustrates the connection between the serial port control device and external devices and the host computer provided in an embodiment of the present invention. Figure 3 This diagram illustrates another connection between the serial port control device and external devices and the host computer provided in this embodiment of the invention. Figure 4 A schematic diagram of the structure of the serial port control device provided in an embodiment of the present invention is shown. Detailed Implementation
[0018] Exemplary embodiments of the invention will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Example 1
[0019] Please see Figure 1This embodiment 1 provides a remote serial port control method, which is executed by a serial port control device. The serial port control device includes target serial port hardware and general-purpose input / output hardware, both of which are electrically connected to an external device. This external device includes any one of a sensor, actuator, industrial instrument, embedded development board, etc. The serial port control device is used by a lower-level machine to send test commands, configuration parameters, or firmware upgrade data to the external device, and to receive collected data, status information, or test results reported by the external device. The method includes: S1: Receive data packets sent by the host computer via the wireless network; wherein the data packets are obtained by the virtual serial port driver built into the host computer encapsulating the raw data sent by the application according to the network serial port mapping protocol.
[0020] A host computer refers to a control terminal device that sends data to serial port control devices via network communication. This includes PC hosts, industrial control computers, servers, and other similar devices. Network communication can utilize wireless data transmission methods such as Wi-Fi AP, Wi-Fi STA, Bluetooth (BLE), or other wireless links. It can also connect to a local area network (LAN) via a LAN gateway, transmitting data over the LAN or public network, and can be encrypted via VPN networks.
[0021] The host computer has a Virtual Serial Port Driver (VSPD) installed inside. This driver registers and creates a virtual serial port device object (such as a COM port in Windows or a TTY device in Linux) in the host computer's operating system.
[0022] The host application sends operation commands through the virtual serial port device object. The virtual serial port driver captures these commands as raw data, encapsulates the raw data into data packets according to the network serial port mapping protocol, and sends them to the serial port control device via the wireless network. This allows the host computer application to access and control remote serial ports (the target serial port hardware and general-purpose input / output hardware of the serial port control device) as if they were local serial ports. The host computer application can include one or more of the following: serial port debugging assistants, firmware download tools, production testing tools, log monitoring tools, industrial control configuration software, and command-line terminals, etc.
[0023] Furthermore, the network serial port mapping protocol is a remote serial port control protocol (Telnet COM PortControl Option or RFC 2217 protocol). The serial port control device internally runs an RFC 2217 service program. The host computer's virtual serial port driver establishes a TCP connection with the RFC 2217 service program via a wireless network and completes negotiation according to the RFC 2217 protocol. This enables the host computer to perform arbitrary operations on the virtual serial port device object, achieving equivalent binding with the actions of the target serial port hardware and general-purpose input / output hardware of the remote serial port control device. This enables wireless serial communication and bidirectional conversion between standard serial port data and network data (data packets).
[0024] Furthermore, the virtual serial port driver of the host computer negotiates with the RFC 2217 service program via the wireless network according to the RFC 2217 protocol. This includes: the virtual serial port driver sending a data packet to the RFC 2217 service program, which includes serial port configuration parameters. The serial port control device internally performs the following operations: configuring parameters for the target serial port hardware according to the serial port configuration parameters. This includes: the RFC 2217 service program parsing the data packet, generating the serial port configuration parameters and writing them into the hardware registers of the target serial port hardware, and returning an acknowledgment response to the virtual serial port driver, thus completing the negotiation. The serial port configuration parameters include one or more of the following: baud rate value, data bit length value, parity check value, stop bit length value, and flow control strategy value.
[0025] Furthermore, the serial port configuration parameters are generated and written to the hardware registers of the target serial port hardware, including: According to the preset conversion logic, the baud rate value, data bit length value, parity mode value, stop bit length value, and flow control strategy value in the serial port configuration parameters are converted into the corresponding configuration words of the target serial port hardware. Write the configuration word into the hardware configuration register corresponding to the target serial port hardware.
[0026] like Figure 2 and Figure 3 As shown, the host computer is the user's PC. The virtual serial port driver registers and creates a virtual serial port device object (COM port) in the host computer's operating system. After the application on the host computer inputs operation command data to the virtual serial port driver through this COM port, the virtual serial port driver encapsulates the data into data packets of the corresponding protocol and sends them to the serial port control device to realize operations such as sending session requests and data packets to the host computer's application.
[0027] In one implementation, such as Figure 2 and Figure 3As shown, the serial port control device also has an application programming interface (API interface). This API interface is used to connect with an application program (APP) in a host computer or a third-party software system to receive API control commands and configure, control, and query the status of the serial port control device. The format of the API control commands is defined by the API interface and may include advanced control commands such as BOOT, RESET, MODE, and WAKE.
[0028] In one implementation, the serial port control device has a local control entry point. This local control entry point includes physical buttons, DIP switches, or a touchscreen on the device's panel, or a control channel accessed via a reserved local debugging interface (such as a JTAG debugging interface). Users can directly perform operations such as serial port parameter configuration, firmware upgrades, or external device resets by operating this local control entry point. This is suitable for on-site maintenance of external devices or emergency debugging or device initialization configuration in environments without a network.
[0029] The serial port control device provided in this invention establishes a TCP communication connection with the virtual serial port driver of the host computer via a wireless network, and provides a unified wireless communication connection between the host computer and the external device based on the network serial port mapping protocol. This allows the host computer's application program to control the external device by sending data packets through the virtual serial port driver without needing to modify its network programming interface. The host computer can perform complete remote operation of the target serial port hardware of the serial port control device via the wireless network without any modifications. This remote operation includes opening the port, setting the baud rate, data bits, parity bits, stop bits, flow control strategy, switching the RTS / DTR control line status, querying the CTS / DSR / DCD control line status, clearing data, and bidirectional transparent transmission of service data, achieving an interactive experience consistent with the host computer's operation of the local physical serial port. This overcomes the limitation of existing technologies where the host computer application program needs to use a network programming interface to remotely access the serial port control device, greatly reducing software development difficulty and maintenance costs.
[0030] After the virtual serial port driver on the host computer completes negotiation with the RFC 2217 service program via the wireless network according to the RFC 2217 protocol, the virtual serial port driver on the host computer encapsulates the raw data sent by the application according to the RFC 2217 protocol to obtain a data packet, and sends it to the RFC 2217 service program via a TCP connection (wireless network).
[0031] S2: Parse the data packet according to the network serial port mapping protocol to generate the standard serial port data; the standard serial port data includes at least one of downlink service data and virtual logic signals.
[0032] Standard serial port data includes at least one of downlink service data and / or virtual logic signals. The content of standard serial port data depends on the type of operation commands issued by the application through the virtual serial port device object.
[0033] In one implementation, when the application sends operation instructions via the virtual serial port device object that are ordinary business data, such as text or binary data frames, the virtual serial port driver captures this business data as raw data, encapsulates it according to the network serial port mapping protocol, and obtains a data packet. After the data packet is parsed and extracted by the serial port control device, the generated standard serial port data contains downlink business data. Downlink business data refers to data that needs to be transmitted to external devices through the basic transmit / receive pins of the target serial port hardware, such as sensor configuration parameters, text to be printed, and actuator control instructions.
[0034] In another implementation, when the application sends a serial port control signal command through the virtual serial port device object (such as checking the RTS or DTR checkboxes on the human-machine interface, or clicking the "Reset Device" or "Wake Up Device" button), the virtual serial port driver captures the control command as raw data, encapsulates it according to the network serial port mapping protocol, and obtains a data packet. After the data packet is parsed and extracted by the serial port control device, the generated standard serial port data contains virtual logic signals.
[0035] In another implementation, when the application sends operation instructions containing both general service data and serial port control signal instructions simultaneously through the virtual serial port device object, the virtual serial port driver captures both the general service data and the serial port control signal instructions. These are then used together as raw data and encapsulated according to the network serial port mapping protocol to obtain a data packet. After being parsed and extracted by the serial port control device, the generated standard serial port data contains both downlink service data and virtual logic signals.
[0036] Furthermore, the virtual logic signals include at least one of RTS, CTS, DTR, DSR, DCD, and RI, and / or include API control commands. This embodiment achieves precise control of the target serial port device and external devices by processing the serial port control signal commands input from the host computer through the virtual serial port driver and the serial port control device. It not only enables the transparent transmission of TX / RX data (service data) between the host computer and external devices, but also allows for operations such as resetting, startup mode selection, flow control handshake, wake-up, or download timing on external devices.
[0037] Standard serial port data conforms to the unified data format used internally by the serial port control device. For downlink service data, this data format is the byte stream format that the basic transmit and receive pins of the target serial port hardware can directly output; for virtual logic signals, this data format is the signal instruction format that the serial port control device can recognize and execute the conversion of.
[0038] S3: Perform splitting processing on standard serial port data, including: when the standard serial port data contains the downlink service data, transmitting the downlink service data through the target serial port hardware to the external device; and / or receiving the uplink service data returned by the target serial port hardware, encapsulating it according to the network serial port mapping protocol, and uploading it to the host computer; when the standard serial port data contains the virtual logic signal, converting the virtual logic signal into a hardware execution instruction according to a preset conversion logic, and sending it to the general-purpose input / output hardware to output a control level to the external device.
[0039] Specifically, downlink business data includes configuration parameters or pending data sent from the host computer to the external device, while uplink business data includes collected data, status information, or response results reported by the external device to the host computer.
[0040] The difference between business data (uplink business data and downlink business data) and virtual logic signals lies in the following: business data is bidirectional transparent data transmission between the host computer and external devices via the target serial port hardware. Specifically, the target serial port hardware directly sends data to the target device via its basic transceiver pin (TX pin); simultaneously, uplink business data returned via the target serial port hardware's basic transceiver pin (RX pin) is directly forwarded back to the host computer. This transparent transmission mode ensures the real-time performance and integrity of the business data.
[0041] The virtual logic signals need to be converted according to preset conversion logic. The specific operation includes: converting the virtual logic signals into instructions that can be executed by the general-purpose input / output (GPIO) hardware according to the preset conversion logic, and sending them to the GPIO hardware. The GPIO hardware then outputs the corresponding control level to the external device, or reads the current input level of the GPIO hardware pin to sample the input state of the external device.
[0042] This invention not only enables bidirectional transparent transmission of business data between the host computer and external devices, but also enables remote logic control of the general input / output hardware of serial port control devices through preset conversion logic. This allows the host computer to directly control the level state of external devices through virtual logic signals without the need for additional hardware, further improving the integrated control capability and scenario adaptability of serial port control devices.
[0043] In one implementation of this embodiment, when the standard serial port data contains the virtual logic signal, the virtual logic signal is converted into a hardware execution instruction according to a preset conversion logic and sent to the general-purpose input / output hardware to output a control level to the external device, including: Based on the pre-stored target configuration file, locate the target input / output pins and target level states corresponding to the virtual logic signals; The driver interface of the general-purpose input / output hardware is invoked to drive the target input / output pin to output the target level state in order to output a control level to the external device; or the input level of the target input / output pin is sampled, the input level is converted into the logic state value of the virtual logic signal, and fed back to the host computer through the serial port access channel.
[0044] After parsing the data packets from the host computer to obtain standard serial port data, the serial port control device performs corresponding conversion operations according to the preset conversion logic defined in the target configuration file. This conversion operation includes: when the data is a virtual logic signal in the data packet, querying the mapping relationship in the target configuration file to determine the corresponding target input / output pin, pin direction, and target level state; if the pin direction is output, calling the driver interface of the general-purpose input / output hardware (target input / output pin) to output the target level state to output a control level to the external device; if the pin direction is input, calling the driver interface of the general-purpose input / output hardware (target input / output pin) to sample the current input level, converting the sampling result into the logic state value of the virtual logic signal, and feeding it back to the host computer.
[0045] In this embodiment of the invention, the preset conversion logic is a target configuration file pre-stored in the serial port control device. This target configuration file records the correspondence between the strings of virtual logic signals and the pin numbers and target level states in the general-purpose input / output hardware. For example, in this target configuration file, virtual logic signal RTS=1 corresponds to "outputting a high level from pin 1"; virtual logic signal DTR=0 corresponds to "outputting a low level from pin 2"; when the virtual logic signal is CTS, the pin (such as pin 3) and operation type (such as input sampling) corresponding to the virtual logic signal CTS are determined by querying the target configuration file. Then, the driver interface of the general-purpose input / output hardware is called to perform the corresponding input sampling operation, and the sampling result (the input level sampled by pin 3) is converted into the logic state value of the virtual logic signal and fed back to the host computer.
[0046] In one implementation of this embodiment, before step S1, the method further includes configuring parameters for the target serial port hardware according to the serial port configuration parameters, including: According to the preset conversion logic, the baud rate value, data bit length value, parity mode value, stop bit length value, and flow control strategy value in the serial port configuration parameters are converted into the corresponding configuration words of the target serial port hardware. Write the configuration word into the hardware configuration register corresponding to the target serial port hardware.
[0047] Specifically, the preset conversion logic is predefined by the target profile stored locally on the serial port control device. This target profile records: the mapping rules between serial port configuration parameters and the configuration words of the hardware registers corresponding to the target serial port hardware, as well as the mapping relationship between virtual logic signals and the pin numbers and corresponding control level states of general-purpose input / output hardware.
[0048] When the standard serial port data obtained by parsing the data packet sent by the host computer is used as the serial port configuration parameters, the serial port control device performs the following operations based on the serial port configuration parameters: according to the mapping rules in the target configuration file, the baud rate value, data bit length value, parity mode value, stop bit length value, and flow control strategy value are converted into the corresponding configuration words of the target serial port hardware, and written into the corresponding hardware configuration register of the target serial port hardware, so that the downlink service data and virtual logic signals sent by the host computer can match the external device.
[0049] Furthermore, the target configuration file supports online updates. When the serial port control device needs to adapt to different types of external devices, the host computer sends update data to the serial port control device through the communication access channel. This update data includes either of the following two methods: the host computer sends a complete target configuration file, and the serial port control device stores the received target configuration file in its local memory and replaces the original target configuration file. Alternatively, the host computer sends a mapping relationship modification command, and the serial port control device performs add, delete, or modify operations on the locally stored target configuration file according to the mapping relationship items carried in the mapping relationship modification command (including virtual logic signal names, corresponding pin numbers, pin directions, and level states). After the update is completed, the serial port control device performs mapping according to the updated target configuration file.
[0050] In one implementation of this embodiment, the serial port control device uses an ESP32 main control chip. This ESP32 chip integrates target serial port hardware and configurable target input / output pins (general purpose input / output hardware). The target serial port hardware and target input / output pins are connected to corresponding pins of an external device. These corresponding pins include serial port pins and target-side control lines. The basic transmit / receive pins (TX / RX) of the target serial port hardware are used to connect to the serial port pins of the external device, enabling business data interaction between the host computer and the external device. The target input / output pins are used to connect to the target-side control lines of the external device, outputting control levels to the external device. In one implementation of this embodiment, the target serial port hardware is a universal asynchronous transceiver (UART controller), and the GPIO pins (general purpose input / output hardware) of the ESP32 can be configured as input / output pins.
[0051] Furthermore, the target-side control lines include at least one of the following: reset control line (RESET), boot mode control line (BOOT), working mode control line (MODE), wake-up control line (WAKE), firmware burning control line (PROG), device selection control line (SEL), power enable control line (POWER_EN), and manufacturer-defined control lines; the general-purpose input / output hardware of the serial port control device is connected to the target-side control lines of the external device for outputting control levels.
[0052] In one implementation of this embodiment, the virtual logic signal includes RTS. The mapping relationship in the target configuration file is queried to determine the hardware execution instruction corresponding to RTS: the target input / output pin outputs a control level, and the corresponding target input / output pin and target level state are determined. The driver interface of the general-purpose input / output hardware is called to drive the target input / output pin to output the corresponding control level, used to control the external device to perform a reset operation, enter download mode, or pause data transmission. For example, when the host computer sends a valid RTS signal, the serial port control device outputs a low-level pulse to the RESET pin of the external device through the driver interface, resetting the external device; or outputs a high level to the EN pin (enable control line) of the external device through the target input / output pin, enabling the external device to enter download mode; or outputs a specific level through the target input / output pin to control the external device to pause data transmission.
[0053] In one implementation of this embodiment, when the virtual logic signal is CTS or DTR, the target configuration file is queried to determine the hardware execution instruction corresponding to CTS or DTR. If it is an output control (such as DTR), the corresponding target input / output pin is driven to output the corresponding level to control the BOOT mode selection, RESET reset, or handshake control of the external device. If it is an input status feedback (such as CTS), the current input level of the corresponding target input / output pin is sampled, the sampling result is converted into a CTS logic status value, and fed back to the host computer to indicate the busy / idle status, download handshake status, or hardware flow control status of the external device.
[0054] In one implementation of this embodiment, when the virtual logic signal is DSR, DCD, or RI, the target configuration file is queried to determine that the target input / output pin and pin direction corresponding to the above signal are inputs. The driver interface of the general-purpose input / output hardware is called to sample the current input level of the target input / output pin, and the sampling results are converted into logic state values of DSR, DCD, and RI respectively, and fed back to the host computer to indicate the online status, connection status, or alarm event of the external device.
[0055] In one implementation of this embodiment, when the virtual logic signal is an API control command (such as BOOT, RESET, MODE, WAKE, etc.), the target configuration file is queried to determine that the hardware execution instruction corresponding to the API control command outputs a specific input / output timing sequence according to the target configuration file. The driver interface of the general-purpose input / output hardware is called, and the corresponding target input / output pin is driven to output the corresponding timing signal according to the predefined timing parameters in the target configuration file (such as level duration, number of pulses, rising / falling edge triggering mode, etc.) to control the external device to select the boot mode, enter the bootloader, or perform a wake-up operation. For example, when the host computer issues a RESET command, the target configuration file is queried to determine that the target level state of the control level corresponding to pin 5 of the RESET command is low and the duration is 200ms. Then, pin 5 is driven to output a 200ms low-level pulse to realize the reset control of the external device.
[0056] Furthermore, by predefining the mapping relationship between virtual logic signals and input / output pins through the target configuration file, the RTS can be configured as input sampling and the CTS as output control, thereby breaking the limitation of fixed control line direction and realizing flexible control of external devices. For example, for external devices that require bidirectional handshake control, the RTS can be mapped to pin 1 for output control (such as controlling device enable), while the CTS can be mapped to pin 3 for input sampling (such as sampling the busy / idle status of the external device), realizing flexible configuration of bidirectional handshake signals.
[0057] The remote serial port control method provided in this invention eliminates the need for separate wireless communication devices on the host computer and the slave computer (external device). Serial communication between the host computer and the slave computer is achieved through a serial port control device. This method avoids the resource redundancy caused by having separate wireless communication devices on the host computer and slave computer sides in existing serial port control devices, and reduces hardware complexity and cost.
[0058] In one implementation of this embodiment, the serial port control device has at least two types of communication access channels for communicating with the host computer: a wired communication channel and a wireless communication channel. The data packets are parsed according to the network serial port mapping protocol to generate the standard serial port data. The standard serial port data includes at least one of downlink service data and virtual logic signals, including: When the data packet is sent to the wired communication channel via a wired communication connection, the wired communication channel generates the standard serial port data from the data packet; wherein, the data packet is encapsulated by the virtual serial port driver according to the USB CDC protocol; When the data packet is sent to the wireless communication channel via the wireless communication connection, the wired communication channel generates the standard serial port data from the data packet; wherein the network serial port mapping protocol is the RFC 2217 protocol.
[0059] Specifically, when the host computer establishes a wired communication connection with the serial port control device via a USB cable, the USB cable is connected to the wired communication channel within the serial port control device. Upon receiving data packets, this wired communication channel parses and extracts the data according to the USB CDC protocol specification, generating standard serial port data.
[0060] When the host computer connects wirelessly to the serial port control device via a wireless network, the host computer communicates with the device through the network serial port mapping protocol service program (RFC 2217 service program) in the wireless communication channel. Upon receiving data packets, this wireless communication channel parses and extracts data according to the network serial port mapping protocol specification, generating standard serial port data.
[0061] This invention integrates wired and wireless communication channels into a serial port control device, allowing the host computer to flexibly select either communication access channel to connect to the serial port control device based on on-site network conditions, cabling environment, and communication requirements. This eliminates the need to replace the serial port control device electrically connected to external devices or add additional hardware, thus improving the flexibility of device deployment and use. The wired and wireless communication channels share the same target serial port hardware and general-purpose input / output hardware, avoiding the need for separate hardware for each access method and improving resource utilization.
[0062] In one implementation of this embodiment, before step S1, the following steps are further included: Receive a session request sent by the host computer, identify the channel identifier carried in the session request, and obtain the corresponding communication access channel; Query the status of the resource locks bound to the target serial port hardware and the general input / output hardware; When the resource lock is in an idle state, the target serial port hardware and the general-purpose input / output hardware are connected to the corresponding communication access channel to establish a session connection; When the resource lock is in an occupied state, the session request is rejected and a device busy prompt is returned to the host computer.
[0063] Specifically, when the host computer needs to establish a communication connection with the serial port control device, it sends a session request to the serial port control device. This session request is used to request the establishment of a communication connection between the host computer and the serial port control device, and at least includes the channel identifier of the communication access channel to be accessed. For example, the channel identifier "0x01" represents a wired communication channel, and "0x02" represents a wireless communication channel.
[0064] When a serial port control device has multiple communication access channels (wired and wireless communication channels), a resource lock is a mutex lock set up to ensure that only one communication access channel has exclusive access to the same target serial port hardware and general-purpose input / output hardware. The resource lock ensures that only one communication access channel can occupy the target serial port hardware and general-purpose input / output hardware at any given time, preventing data conflicts or hardware state corruption caused by multiple communication access channels simultaneously operating the same resource serial port (target serial port hardware and general-purpose input / output hardware). This resource lock is always bound to the target serial port hardware and general-purpose input / output hardware. The resource lock has two states: idle and occupied. The idle state indicates that no communication access channel is currently using the target serial port hardware and general-purpose input / output hardware, meaning that the target serial port hardware and general-purpose input / output hardware are available; the occupied state indicates that a communication access channel is already using the target serial port hardware and general-purpose input / output hardware.
[0065] When a session request is received from the host computer, if the resource lock is in an idle state, the lock's state is switched from idle to occupied, and the target serial port hardware and general-purpose input / output hardware are bound to the selected communication access channel. After binding, a successful session connection establishment response is returned to the host computer, allowing subsequent data interaction through this communication access channel. During this time, the communication access channel exclusively uses the target serial port hardware and general-purpose input / output hardware until the session ends or is abnormally disconnected. If the resource lock is in an occupied state, it indicates that the target serial port hardware and general-purpose input / output hardware are currently occupied by the communication access channel and cannot provide service for a new session request. The session request is rejected, and a device busy message is returned to the host computer that sent the request. Upon receiving this message, the host computer can choose to wait for a period of time and re-initiate the session request, or indicate to the user that the device is currently busy.
[0066] This embodiment ensures that the target serial port hardware and general-purpose input / output hardware can only be used by one communication access channel at any given time by setting resource locks bound to the target serial port hardware and general-purpose input / output hardware. This effectively prevents conflicts caused by wired and wireless communication channels operating the same target serial port hardware and general-purpose input / output hardware simultaneously, thus guaranteeing the stability and reliability of data transmission.
[0067] Furthermore, prior to step S1, the process includes: upon receiving a session request, retrieving pre-stored device specification information, encapsulating it according to a preset message format to generate a capability declaration message, and uploading it to the host computer. This capability declaration message is used to declare to the host computer all the hardware capabilities and supported service types of the current serial port control device, enabling the host computer to understand the complete capability boundaries of the serial port control device, thereby avoiding subsequent communication failures due to capability mismatches of the serial port control device.
[0068] The device specification information is a set of structured data written to the serial port control device at the factory or during initialization. It includes at least the serial port parameters of the target serial port hardware (such as the supported baud rate range, data bits, stop bits, parity method, flow control method, etc.), the number and pin numbers of the general input / output hardware pins, the wired protocol type supported by the wired communication channel (such as the USB CDC protocol), the wireless protocol type supported by the wireless communication channel (such as the RFC 2217 protocol), and other optional auxiliary information.
[0069] After receiving the capability declaration message, the host computer parses the device specification information, generates serial port configuration parameters, and encapsulates them into a data packet for transmission. The serial port control device parses the data packet and executes operations according to the configuration parameters.
[0070] In one implementation of this embodiment, the serial port control device further includes at least one of the following extended communication access channels: a Mod TCP communication channel, a private TCP communication channel, a WebSocket communication channel, and a Bluetooth communication channel, used to enable the host computer to supplement the access and control of the serial port control device.
[0071] Specifically, after receiving a data packet from the host computer, the serial port control device sends the packet to the corresponding communication access channel for processing based on the protocol type it carries. Data packets carrying the Modbus TCP protocol are parsed into Modbus commands by the Modbus TCP communication channel to obtain standard serial port data. Data packets carrying a proprietary TCP protocol are parsed into standard serial port data according to a custom protocol format by the proprietary TCP communication channel. Data packets carrying the WebSocket protocol are parsed and processed by the WebSocket communication channel to obtain standard serial port data. Data frames carrying the BLE protocol are parsed and processed by the BLE communication channel to obtain standard serial port data.
[0072] Standard serial port data obtained from parsing and processing any of the above communication access channels is split according to data type: if it is downlink service data, it is transmitted to the external device through the basic transmit and receive pins of the target serial port hardware; if it is virtual logic signal or control instruction, it is mapped to the corresponding hardware execution instruction according to the target configuration file and executed through general-purpose input / output hardware, thereby realizing data interaction and control of the external device.
[0073] The serial port control device provided in this embodiment can be accessed and controlled via a web browser without installing dedicated host computer software, or through a host computer application (APP) for near-field debugging and configuration, or connected to a standard Modbus TCP industrial network by expanding multiple extended communication access channels. This significantly improves the applicability and deployment flexibility of the device.
[0074] In another implementation of this embodiment, the serial port control device includes at least two sets of independent resource serial ports. Each set of resource serial ports includes target serial port hardware, general-purpose input / output hardware, and corresponding hardware registers. It can independently execute serial port configuration parameter operations and independently perform data transmission and reception and level control. Each set of serial ports is electrically connected to an external device. The serial port control device also includes a resource arbitration module, which manages the mapping relationship and allocation between multiple sets of resource serial ports and multiple communication access channels, so as to exchange standard serial port data from different communication access channels with different external devices through different serial ports. After S2, the device further includes: The target resource serial port identifier carried in the standard serial port data is obtained. This target resource serial port identifier is used to indicate the target resource serial port corresponding to the current standard serial port data. When the host computer sends a data packet, it carries a target resource serial port identifier in the header or protocol field of the data packet to indicate which group of resource serial ports the data packet should be routed to for processing.
[0075] The target resource serial port identifier is sent to the resource arbitration module. The resource arbitration module queries the resource allocation table to determine whether the resource serial port corresponding to the target resource serial port identifier is in an idle state. The resource allocation table is pre-stored in the resource arbitration module. The resource allocation table records the current occupancy status (idle or occupied) of each group of resource serial ports and the communication access channel identifier occupying the resource serial port.
[0076] If the resource serial port corresponding to the target resource serial port identifier is in an idle state, the resource arbitration module allocates the resource serial port corresponding to the target resource serial port identifier to the current communication access channel, marks the status of the corresponding resource serial port as occupied in the resource allocation table, and records the communication access channel identifier occupying the resource serial port. The host computer transmits service data to the corresponding external device through the resource serial port, or outputs control levels to the external device through the general input / output hardware of the resource serial port. At this time, the communication access channel exclusively occupies this group of resource serial ports until the session ends or the resource is released.
[0077] If the resource serial port corresponding to the target resource serial port identifier is in an occupied state, the resource arbitration module outputs a resource busy response and returns a device busy prompt to the host computer.
[0078] Furthermore, after the resource arbitration module assigns the resource serial port corresponding to the target resource serial port identifier to the current communication access channel, it also includes: Extract the data category flag from the standard serial port data; this flag identifies whether the standard serial port data contains downlink service data or virtual logic signals. For example, data category flag "01" indicates downlink service data, and "02" indicates virtual logic signals.
[0079] The pre-stored routing table is consulted based on the data category identifier to determine the processing path. The routing table records the correspondence between data category identifiers and processing paths. For example, downlink service data with data category identifier "01" is processed through transparent transmission, passing through the target serial port hardware corresponding to the target resource serial port identifier; for example, virtual logic signals with data category identifier "02" are processed by conversion according to preset conversion logic and sent to the general input / output hardware corresponding to the target resource serial port identifier.
[0080] At the same time, the received uplink business data is encapsulated according to the protocol format of the current communication access channel and uploaded to the host computer that has established a communication connection with the current communication access channel.
[0081] In one implementation of this embodiment, the serial port control device further includes a storage medium and a log writing module. The storage medium is used for persistent storage of log data. The log writing module is a software or firmware module responsible for collecting, processing, and writing log data, and is communicatively connected to the central scheduling module and the target serial port hardware. The method further includes: the log writing module determining the current operating mode of the serial port control device, the operating mode including serial port mode and offline mode, including: Real-time monitoring and acquisition of the interaction log stream of the target serial port hardware, and recording index information and event information; The acquired interaction log stream is written to the storage medium; the interaction log stream includes at least the serial port data transmitted and received by the target serial port hardware. In the serial port mode, the index information includes one or more of the following: operation identifier, type of serial port access channel, serial port parameters, start and end times of log recording, and byte count; the event information includes one or more of the following: connection establishment and disconnection of session requests, resource lock acquisition and release, and level state changes of the general-purpose input / output hardware. In the offline mode, the index information includes at least one or more of the following: the operation identifier, the start and end times of the log record, the byte count, and the log file storage location; the event information includes one or more of the following: the log record start event, the log record stop event, and the storage medium status event.
[0082] Specifically, the log writing module determines the current operating mode of the serial port control device. The operating mode is determined by the existence of a valid session connection. If a session connection exists (i.e., the resource lock is held and the session connection is active), the current operating mode is determined to be serial port mode. If no session connection exists (i.e., the resource lock is idle), the current operating mode is determined to be offline mode. The log collection strategy and recorded content differ between the two operating modes.
[0083] In serial port mode, the host computer performs operations such as serial port command configuration, firmware download, log capture, parameter reading, device self-test, or production testing on the external device. The serial port control device is interacting with the host computer in real time. The log writing module monitors and captures all data flow on the target serial port hardware in real time. The interaction log stream refers to all transmitted and received serial port data recorded by the target serial port hardware in chronological order during communication, including at least one of the following: raw byte stream, text stream, or data stream with direction markers. That is, it includes downlink service data sent by the host computer to the external device via the target serial port hardware, and uplink service data returned by the external device through the target serial port hardware and uploaded to the host computer via the central scheduling module.
[0084] The log writing module captures the interactive log stream while simultaneously recording index and event information. Index information is used to structure and mark log data for easy retrieval and analysis later. In serial port mode, index information includes one or more of the following: operation ID, communication access channel type (wired or wireless), serial port parameters (baud rate, data bits, parity bits, stop bits, etc. used in the current session connection), log recording start and end times (timestamps accurate to milliseconds), and byte count (total number of bytes sent and received during the recording period). The operation ID is a unique UUID or sequence number that identifies a single log recording operation. Event information records key state changes during communication, including one or more of the following: session connection establishment and termination, resource lock acquisition and release, and general-purpose input / output hardware level changes (such as input / output pins changing from high to low).
[0085] In offline mode, the target serial port hardware may still be autonomously communicating with external devices (e.g., the external device actively reporting data). The log writing module monitors the received data of the target serial port hardware, reads the data stream received by the target serial port hardware in real time, and records it as an interaction log stream. In offline mode, the interaction log stream only contains uplink business data sent from the external device to the target serial port hardware.
[0086] In offline mode, the index information recorded by the log writing module differs from that in serial port mode. The index information in offline mode includes at least one or more of the following: operation identifier, log recording start and end times, byte count, and log file storage location (the physical storage path or filename of the interactive log stream, index information, and event information in the storage medium). Event information includes one or more of the following: log recording start event (timestamp of recording start), log recording stop event (timestamp of recording end), and storage medium status events (such as alarm information like storage space about to be full or write error).
[0087] The log writing module encapsulates and organizes the collected interactive log stream, along with corresponding index and event information, according to a preset data format (such as binary or text format), and writes it to a storage medium. This allows after-sales service, production lines, or R&D personnel to view the stored log files and review failure causes through this storage medium. The storage medium includes one of the following: TF card, microSD, eMMC, USB flash drive, or internal pluggable / exportable non-volatile storage.
[0088] Furthermore, such as Figure 2 and Figure 3 As shown, the serial port control device is equipped with a target-side power supply interface for obtaining operating power from an external device connected to the serial port control device. This addresses the issue of insufficient power supply in the field, such as when there is no host computer, no external power source, or a high-voltage environment. The external device can then safely power the serial port control device, ensuring continued log recording or enabling the host computer to remotely access the external device. Alternatively, when other power sources are available, power can be drawn from them through this target-side power supply interface. By setting up the target-side power supply interface, in a high-voltage environment, the host computer can wirelessly communicate with the serial port control device via a wireless communication channel, reducing the need for direct wired electrical connections between the host computer and external devices.
[0089] Furthermore, the serial port control device also includes a target-side power supply interface for providing operating power to external devices. When the serial port control device is connected to the host computer via a USB interface, it obtains operating power from the USB wired connection interface and outputs the power to the external device through the target-side power supply interface, thus powering the external device and avoiding the need for the external device to be connected to a separate external power source.
[0090] Furthermore, the serial port control device is equipped with a power selection and reverse current prevention module. When the host computer communicates via a wired communication channel, it selects the operating power source between USB power supply and external device power supply, and prevents reverse current flow between the two power domains. When the host computer connects to the serial port control device via USB, USB is used to power the serial port control device first; when USB power is unavailable but the external device can provide power, it switches to power from the target side. This prevents reverse current flow between the USB power domain and the external device power domain, avoiding damage to either power source or load device due to voltage differences.
[0091] Furthermore, in addition to serial data communication, this wired communication channel can also be reused as a maintenance channel for the host computer to configure parameters, upgrade firmware, or export logs for external devices.
[0092] Example 2 like Figure 4As shown, this embodiment 2 presents a schematic diagram of the serial port control device based on the remote serial port control method provided in embodiment 1. Figure 4 As shown, the serial port control device includes target serial port hardware 100 and general-purpose input / output hardware 200. Both the target serial port hardware 100 and the general-purpose input / output hardware 200 are electrically connected to external devices. The serial port control device also includes a receiving module 300, a serial port bridging module 400, and a central scheduling module 500.
[0093] The receiving module is used to receive data packets sent by the host computer through the wireless network; wherein, the data packets are obtained by the virtual serial port driver built into the host computer encapsulating the raw data sent by the application according to the network serial port mapping protocol; The serial port bridging module 300 is used to parse the data packets according to the network serial port mapping protocol and generate the standard serial port data; the standard serial port data includes at least one of downlink service data and virtual logic signals; The central scheduling module 500 is used to transmit the downlink service data through the target serial port hardware to the external device when the standard serial port data contains the downlink service data; and / or receive the uplink service data returned by the target serial port hardware, encapsulate it according to the network serial port mapping protocol, and upload it to the host computer; when the standard serial port data contains the virtual logic signal, convert the virtual logic signal into a hardware execution instruction according to a preset conversion logic, and send it to the general-purpose input / output hardware to output a control level to the external device.
[0094] Furthermore, the virtual logic signal includes at least one of RTS, CTS, DTR, DSR, DCD, RI, and / or includes API control commands.
[0095] When the standard serial port data contains the virtual logic signal, the central scheduling module 500 is further configured to: Based on the pre-stored target configuration file, locate the target input / output pins and target level states corresponding to the virtual logic signals; The driver interface of the general-purpose input / output hardware is invoked to drive the target input / output pin to output the target level state in order to output a control level to the external device; or the input level of the target input / output pin is sampled, the input level is converted into the logic state value of the virtual logic signal, and fed back to the host computer through the serial port access channel.
[0096] The standard serial port data also includes serial port configuration parameters; the central scheduling module 500 is further configured to perform parameter configuration on the target serial port hardware according to the serial port configuration parameters, including: According to the preset conversion logic, the baud rate value, data bit length value, parity mode value, stop bit length value, and flow control strategy value in the serial port configuration parameters are converted into the corresponding configuration words of the target serial port hardware. Write the configuration word into the hardware configuration register corresponding to the target serial port hardware.
[0097] The serial port control device is provided with at least two types of communication access channels for communicating with the host computer: a wired communication channel and a wireless communication channel. The communication access channels are used for: When the data packet is sent to the wired communication channel via a wired communication connection, the wired communication channel generates the standard serial port data from the data packet; wherein, the data packet is encapsulated by the virtual serial port driver according to the USB CDC protocol; When the data packet is sent to the wireless communication channel via the wireless communication connection, the wired communication channel generates the standard serial port data from the data packet; wherein the network serial port mapping protocol is the RFC 2217 protocol.
[0098] Furthermore, before receiving the data packets sent by the host computer via the wireless network, the central scheduling module 500 is also used to: Receive a session request sent by the host computer, identify the channel identifier carried in the session request, and obtain the corresponding communication access channel; Query the status of the resource locks bound to the target serial port hardware and the general input / output hardware; When the resource lock is in an idle state, the target serial port hardware and the general-purpose input / output hardware are connected to the corresponding communication access channel to establish a session connection; When the resource lock is in an occupied state, the session request is rejected and a device busy prompt is returned to the host computer.
[0099] Furthermore, the serial port control device also includes at least one of the following extended communication access channels: Mod TCP communication channel, private TCP communication channel, WebSocket communication channel, and Bluetooth communication channel.
[0100] Furthermore, the serial port control device also includes a storage medium and a log writing module. The log writing module is used to determine the current operating mode of the serial port control device, which includes serial port mode and offline mode. This log writing module is used to: monitor and acquire the interaction log stream of the target serial port hardware in real time, and record index information and event information; write the acquired interaction log stream to the storage medium; the interaction log stream includes at least the serial port data sent and received by the target serial port hardware.
[0101] In the serial port mode, the index information includes one or more of the following: operation identifier, type of serial port access channel, serial port parameters, start and end times of log recording, and byte count; the event information includes one or more of the following: connection establishment and disconnection of session requests, resource lock acquisition and release, and level state changes of the general-purpose input / output hardware.
[0102] In the offline mode, the index information includes at least one or more of the following: the operation identifier, the start and end times of the log record, the byte count, and the log file storage location; the event information includes one or more of the following: the log record start event, the log record stop event, and the storage medium status event.
[0103] Example 3 Based on the serial port control device provided in Embodiment 2 above, this embodiment provides a computer device. This specific embodiment of the invention does not limit the specific implementation of the computer device. The computer device includes: a serial port control device, a host computer communicating with the serial port control device, and an external device electrically connected to the target serial port hardware and control hardware of the serial port control device. The serial port control device performs the operation of any of the remote serial port control methods described in Embodiment 1 above.
[0104] The algorithms or displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used with the teachings based thereon. The required structure for constructing such systems is apparent from the above description. Furthermore, the embodiments of the present invention are not directed to any particular programming language. It should be understood that the content of the invention described herein can be implemented using various programming languages, and the above description of specific languages is for the purpose of disclosing the best mode of implementation of the invention.
[0105] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.
[0106] Similarly, it should be understood that, in order to streamline the invention and aid in understanding one or more of the various aspects of the invention, features of the embodiments of the invention are sometimes grouped together in a single embodiment, figure, or description thereof in the above description of exemplary embodiments of the invention. However, this disclosure should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim.
[0107] Those skilled in the art will understand that modules in the device of the embodiments can be adaptively changed and placed in one or more devices different from that embodiment. Modules, units, or components in the embodiments can be combined into a single module, unit, or component, and can be divided into multiple sub-modules, sub-units, or sub-components. Except where at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or device so disclosed. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature that serves the same, equivalent, or similar purpose.
[0108] It should be noted that the above embodiments are illustrative of the invention and not restrictive, and that those skilled in the art can devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words can be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be construed as limiting the order of execution.
Claims
1. A remote serial port control method, characterized in that, The remote serial port control method is applied to a serial port control device; the serial port control device includes target serial port hardware and general-purpose input / output hardware, both of which are electrically connected to an external device; the method includes: Receive data packets sent by the host computer via a wireless network; wherein, the data packets are obtained by the virtual serial port driver built into the host computer encapsulating the raw data sent by the application according to the network serial port mapping protocol; The data packet is parsed according to the network serial port mapping protocol to generate standard serial port data; the standard serial port data includes at least one of downlink service data and virtual logic signals. When the standard serial port data contains the downlink service data, the downlink service data is transmitted transparently to the external device via the target serial port hardware; and / or the uplink service data transmitted back by the target serial port hardware is received, encapsulated according to the network serial port mapping protocol, and uploaded to the host computer. When the standard serial port data contains the virtual logic signal, the virtual logic signal is converted into a hardware execution instruction according to the preset conversion logic and sent to the general-purpose input / output hardware to output a control level to the external device.
2. The remote serial port control method according to claim 1, characterized in that, The virtual logic signals include at least one of RTS, CTS, DTR, DSR, DCD, and RI, and / or include API control commands.
3. The remote serial port control method according to claim 1, characterized in that, When the standard serial port data contains the virtual logic signal, the virtual logic signal is converted into a hardware execution instruction according to a preset conversion logic and sent to the general-purpose input / output hardware to output a control level to the external device, including: Based on the pre-stored target configuration file, locate the target input / output pins and target level states corresponding to the virtual logic signals; The driver interface of the general-purpose input / output hardware is invoked to drive the target input / output pin to output the target level state in order to output a control level to the external device; or the input level of the target input / output pin is sampled, the input level is converted into the logic state value of the virtual logic signal, and fed back to the host computer through the serial port access channel.
4. The remote serial port control method according to claim 1 or 3, characterized in that, The standard serial port data also includes serial port configuration parameters; the method further includes configuring parameters on the target serial port hardware according to the serial port configuration parameters, including: According to the preset conversion logic, the baud rate value, data bit length value, parity mode value, stop bit length value, and flow control strategy value in the serial port configuration parameters are converted into the corresponding configuration words of the target serial port hardware. Write the configuration word into the hardware configuration register corresponding to the target serial port hardware.
5. The remote serial port control method according to claim 1, characterized in that, The serial port control device is provided with at least two types of communication access channels for communicating with the host computer, namely a wired communication channel and a wireless communication channel. The data packets are parsed according to the network serial port mapping protocol to generate the standard serial port data. The standard serial port data includes at least one of the following: downlink service data and virtual logic signals, including: When the data packet is sent to the wired communication channel via a wired communication connection, the wired communication channel generates the standard serial port data from the data packet; wherein, the data packet is encapsulated by the virtual serial port driver according to the USB CDC protocol; When the data packet is sent to the wireless communication channel via the wireless communication connection, the wired communication channel generates the standard serial port data from the data packet; wherein the network serial port mapping protocol is the RFC 2217 protocol.
6. The remote serial port control method according to claim 5, characterized in that, Before receiving the data packets sent by the host computer via the wireless network, the method further includes: Receive a session request sent by the host computer, identify the channel identifier carried in the session request, and obtain the corresponding communication access channel; Query the status of the resource locks bound to the target serial port hardware and the general input / output hardware; When the resource lock is in an idle state, the target serial port hardware and the general-purpose input / output hardware are connected to the corresponding communication access channel to establish a session connection; When the resource lock is in an occupied state, the session request is rejected and a device busy prompt is returned to the host computer.
7. The remote serial port control method according to claim 1 or 5, characterized in that, The serial port control device further includes at least one of the following extended communication access channels: Mod TCP communication channel, private TCP communication channel, WebSocket communication channel, and Bluetooth communication channel.
8. The remote serial port control method according to claim 1, characterized in that, The serial port control device further includes a storage medium and a log writing module. The method further includes: the log writing module determining the current operating mode of the serial port control device, the operating mode including serial port mode and offline mode, including: Real-time monitoring and acquisition of the interaction log stream of the target serial port hardware, and recording index information and event information; The acquired interaction log stream is written to the storage medium; the interaction log stream includes at least the serial port data transmitted and received by the target serial port hardware. In the serial port mode, the index information includes one or more of the following: operation identifier, type of serial port access channel, serial port parameters, start and end times of log recording, and byte count; the event information includes one or more of the following: connection establishment and disconnection of session requests, resource lock acquisition and release, and level state changes of the general-purpose input / output hardware. In the offline mode, the index information includes at least one or more of the following: the operation identifier, the start and end times of the log record, the byte count, and the log file storage location; the event information includes one or more of the following: the log record start event, the log record stop event, and the storage medium status event.
9. A serial port control device, characterized in that, The serial port control device includes target serial port hardware and general-purpose input / output hardware, both of which are electrically connected to external devices; the serial port control device also includes: The receiving module is used to receive data packets sent by the host computer through a wireless network; wherein, the data packets are obtained by the virtual serial port driver built into the host computer encapsulating the raw data sent by the application according to the network serial port mapping protocol; The serial port bridging module is used to parse the data packets according to the network serial port mapping protocol and generate standard serial port data; the standard serial port data includes at least one of downlink service data and virtual logic signals. The central scheduling module is used to transmit the downlink service data through the target serial port hardware to the external device when the standard serial port data contains the downlink service data; and / or receive the uplink service data returned by the target serial port hardware, encapsulate it according to the network serial port mapping protocol, and upload it to the host computer; when the standard serial port data contains the virtual logic signal, convert the virtual logic signal into a hardware execution instruction according to a preset conversion logic, and send it to the general-purpose input / output hardware to output a control level to the external device.
10. A computer device, characterized in that, The serial port control device as described in claim 9, the host computer communicating with the serial port control device, and the external device electrically connected to the target serial port hardware and control hardware of the serial port control device; The serial port control device performs the operation of the remote serial port control method as described in any one of claims 1-8.
