Method and program for connecting a USB virtual COM device

The connection method and program use vendor and product IDs to identify the correct port number in the OS database, preventing interference and malfunctions in USB virtual COM devices, ensuring smooth communication without updating the application program.

JP7599973B2Active Publication Date: 2024-12-16NIDEC INSTR CORP
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
JP2021012961
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Filing Date
2021-01-29
Publication Date
2024-12-16
Estimated Expiration
2041-01-29

AI Technical Summary

Technical Problem

When multiple USB virtual COM devices are connected to a host device, existing methods for identifying and communicating with a specific device can cause malfunctions and communication interference with other devices due to the need to send commands to unspecified port numbers, leading to incorrect port number assignments.

Method used

A connection method and program that utilize the vendor ID and product ID of the USB device as search keys to find the correct port number in the operating system's configuration database, avoiding direct command sending to other devices, and using a dynamic link library to manage device changes without updating the application program.

Benefits of technology

Enables communication with the desired USB virtual COM device without causing malfunctions or interference in other devices, allowing seamless communication without requiring updates to the application program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007599973000001
    Figure 0007599973000001
  • Figure 0007599973000002
    Figure 0007599973000002
  • Figure 0007599973000003
    Figure 0007599973000003
Patent Text Reader

Abstract

To search for a desired external apparatus, which is a USB virtual COM device, and communicate with the external apparatus in a serial form from an application program side of a higher-level device, without causing malfunctions or communication interference in other virtual COM devices.SOLUTION: A connection method includes: when communication with an external apparatus in a serial form is performed from an application program side of a higher-level device, searching a configuration information database (for example, a registry) of an operating system of the higher-level device using identification information (for example, vendor ID and product ID) as a USB device of the external apparatus as a search key, and acquiring a port number corresponding to the external apparatus (step 102); and using the acquired port number to start communication between the application program and the external apparatus (step 103).SELECTED DRAWING: Figure 1
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] The present invention relates to a connection method and a program for connecting an external device, which is a USB virtual COM device, to a higher-level device, such as a host computer. [Background technology]

[0002] When connecting an external device (such as a modem) that operates through serial communication to a host device such as a computer, the host device was previously provided with individual serial ports (serial interfaces) for different purposes, and the serial ports were connected one-to-one to the external device to be connected. When there were multiple individual serial ports, the ports were distinguished by giving port numbers such as COM1, COM2, .... However, providing ports or physical interfaces with different shapes and standards for different purposes increases the number of ports that must be physically implemented in the information processing device, so the USB (Universal Serial Bus) standard, which is a general-purpose interface standard, was proposed, and it has become mainstream to connect various external devices to the host device through USB ports. There are cases where an application program that assumes access to an external device with an interface standard different from the USB standard needs to access an external device physically connected to a USB port. In such cases, the external device is accessed from the application program through a device driver that absorbs the difference in interface standards. As a device driver for connecting an external device such as a modem that operates through serial communication, a CDC (Communication Device Class) device is provided in a general operating system (OS). In the following description, an external device that is physically connected to a higher-level device via a USB port but is treated by an application program in the higher-level device as being connected via serial communication is called a USB virtual COM device. The USB virtual COM device itself is a type of USB device, since it is a device that is physically connected to a USB port. Patent Document 1 discloses an example of an information processing device that controls a USB device by software that supports an interface standard different from the USB standard. [Prior art documents] [Patent documents]

[0003] [Patent Document 1] JP 2013-156877 A Summary of the Invention [Problem to be solved by the invention]

[0004] A USB virtual COM device connected to a USB port of a higher-level device is identified by a port number from the application program of the higher-level device as if the virtual device was connected to an individual serial port. When multiple USB virtual COM devices of different types are connected to a higher-level device and an application program is trying to communicate with a specific USB virtual COM device, the application program needs to know the port number of the USB virtual COM device. There is a method for checking the port number of a USB virtual COM device to be communicated with, in which the application software sends a command suitable for the target USB virtual COM device while changing the port number in order from COM1, COM2, ..., and recognizes the port number that returns the expected response to the command as the port number for communicating with the target USB virtual COM device. However, with this method, commands are also sent to USB virtual COM devices other than the USB virtual COM device to be searched (i.e., other USB virtual COM devices), which may interfere with communication with the other USB virtual COM devices or cause the other virtual COM devices to malfunction.

[0005] The object of the present invention is to provide a connection method and program that enables searching for a desired external device that is a USB virtual COM device without causing malfunction or communication interference in other virtual COM devices, and enables communication with the external device in serial form from the application program of the higher-level device. [Means for solving the problem]

[0006] The connection method of the present invention is a connection method for connecting an external device that is a USB virtual COM device to a host device that executes an application program, and when the application program is to communicate with the external device in a serial format, the connection method searches the setting information database of the operating system of the host device using the identification information of the external device as a USB device as a search key to obtain a port number corresponding to the external device, and starts communication between the application program and the external device using the obtained port number. When external devices having the same identification information are registered in the setting information database in duplicate, the port numbers of the duplicate external devices are obtained, and then, after sequentially checking the connection using each of the obtained port numbers, communication between the application program and the external devices is started. do.

[0007] In the connection method of the present invention, the identification information of the external device as a USB device is used as a search key to search the operating system's setting information database (e.g., registry) to obtain a port number, so no command is sent to other USB virtual COM devices connected to the higher-level device, and therefore no malfunction or communication interference is caused in the other USB virtual COM devices. Once the port number is obtained, the application program can communicate with the external device in a serial format.

[0008] In the connection method of the present invention, it is preferable to use the vendor ID and product ID of the USB device as the identification information. By using the vendor ID and product ID as the identification information, it becomes unnecessary to be aware of different external devices of the same model, and the operation of the application program does not need to be complicated.

[0009] In the connection method of the present invention, when a dynamic link library is interposed between an application program and an operating system, it is preferable that when a connection request to an external device is received from the application program, the dynamic link library searches the setting information database and executes a process to obtain a port number corresponding to the external device. By configuring in this way, when the model of the external device is changed, the effect of this can be absorbed by the dynamic link library, eliminating the need to update the application program.

[0010] same When an external device of the same model is replaced and connected, or when an external device is connected to a different USB port, external devices having the same identification information may be stored in the setting information database in duplicate. In the connection method of the present invention, In such a case, by sequentially checking the connection using each of the acquired port numbers, it is possible to know the port numbers that can actually be used for communication with the external device. In this case, USB virtual COM devices other than the target external device are not subject to connection checks, so malfunctions or communication interference will not occur in the other USB virtual COM devices.

[0011] The program of the present invention is a program for a computer having a USB port to which an external device, which is a USB virtual COM device, is connected and for executing an application program, which performs serial communication with the external device by using identification information of the external device as a search key. computer a process of searching a setting information database of the operating system to obtain a port number corresponding to the external device, and a process of starting communication between the application program and the external device using the obtained port number; When external devices having the same identification information are registered in the setting information database in duplicate, the computer is caused to execute a process of acquiring a port number for each of the duplicate external devices, and a process of sequentially performing a connection check using each of the acquired port numbers. do.

[0012] According to the program of the present invention, the port number is obtained by searching the operating system's setting information database (e.g., registry) using the identification information of the external device as a USB device as a search key, so that the port number can be obtained without sending a command to another USB virtual COM device connected to the upper device, which is a computer, and the port number can be obtained without causing malfunction or communication interference in the other USB virtual COM device. Once the port number is obtained, the application program can communicate with the external device in a serial format.

[0013] In the program of the present invention, it is preferable to use the vendor ID and product ID of the USB device as the identification information. By using the vendor ID and product ID as the identification information, it becomes unnecessary to be aware of different external devices of the same model, and the operation of the application program does not need to be complicated.

[0014] The program of the present invention is preferably a dynamic link library program that exists between an application program and an operating system, and when a connection request to an external device is received from the application program, causes the computer to execute a process of searching a setting information database to obtain a port number corresponding to the external device. By configuring in this way, when the model of the external device is changed, the effect of this can be absorbed by the dynamic link library, eliminating the need to update the application program.

[0015] Also Program of the present invention According toIf external devices with the same identification information are stored in the setting information database, the port numbers that can actually be used for communication can be found by sequentially checking the connection using each of the acquired port numbers. In this case, USB virtual COM devices other than the target external device are not subject to connection checks, so malfunctions or communication interference with the other USB virtual COM devices do not occur. Effect of the Invention

[0016] According to the present invention, it is possible to search for an external device that is a desired USB virtual COM device without causing malfunction or communication interference in other USB virtual COM devices, and to allow an application program in a higher-level device to communicate in serial form with the external device. [Brief description of the drawings]

[0017] [Figure 1] FIG. 2 is a block diagram illustrating a connection between a host computer, which is a higher-level device, and an external device, which is a USB virtual COM device. [Diagram 2] FIG. 11 is a diagram showing an example of the contents of a setting information file. [Diagram 3] 4 is a flowchart illustrating a connection method according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0018] Next, an embodiment of the present invention will be described with reference to the drawings. The present invention relates to connecting a USB virtual COM device to a higher-level device, and Fig. 1 shows a connection between a host computer 1, which is a higher-level device, and an external device 2, which is a USB virtual COM device.

[0019] The host computer 1 is, for example, a general-purpose personal computer, and is capable of executing any application program 11. In particular, the host computer 1 is provided with a USB port 3 as a hardware interface. The host computer 1 is controlled by an operating system (OS) 20 that provides various services to the application program 11. In this host computer 1, the application program 11 is configured to make a service request to the OS 20 via a dynamic link library (DLL) and receive a processing result from the OS 20. The OS 20 incorporates the USB CDC protocol, and therefore includes a CDC driver 21 that is a device driver for a device that operates in serial communication, and a USB driver 22 that is between the CDC driver 21 and the USB port 3 and executes processing related to the USB protocol. Furthermore, the OS 20 includes a setting information database 23 that collectively stores setting information related to the system of the host computer 1, setting information related to the application program 11, setting information related to the DLL 12, setting information related to the OS 20, and the like. The OS 20 is, for example, Microsoft (registered trademark) Windows (registered trademark), and in this case, the setting information database 23 is a registry.

[0020] The external device 2, which is a USB virtual COM device, operates according to serial data from the application program 11, and is physically connected to the USB port 3 of the higher-level device 1 in a removable manner via a USB cable. The external device 2 has a USB port 4 for connection to the host computer 1, and has an interface for receiving command data (instruction statement) from the host computer 1 via the USB port 4 and transmitting a response to the command data to the host computer 1. The external device 2 operates according to the received command data and includes a CPU (Central Processing Unit), a ROM (Read Only Memory), a RAM (Random Access Memory), and the like (not shown) for machine control. As an example, the external device 2 may be an IC card reader that reads and writes data from an IC card. The external device 2, which is a USB device, is assigned a vendor (manufacturer) ID, a product (product) ID, and a serial number (individual number). The vendor ID, product ID, and serial number are identification information that enable a USB device to be uniquely identified. The type and specifications of the external device 2 can be identified by the vendor ID and product ID, and by using the serial number in addition to these, the external device 2 can be uniquely identified.

[0021] Based on the USB standard and the specifications of the OS 20, when the external device 2 is connected to the USB port 3 for the first time, the vendor ID, product ID, and serial number are read from the external device 2 and registered in the setting information database 23. Since the external device 2 is a USB virtual COM device, a port number "COMn" (n is a natural number between 1 and 256, for example) is also assigned, and this is also associated with the vendor ID, product ID, and serial number and registered in the setting information database 23. Information regarding the external device 2 once registered in the setting information database 23 is stored in the setting information database 23 even after the external device 2 is removed from the host computer 1. When the OS 20 is Microsoft (registered trademark) Windows (registered trademark), information regarding the external device 2, which is a USB virtual COM device, is stored in the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB in the registry, which is the setting information database 23. FIG. 2 shows an example of information stored in the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB of the registry.

[0022] 2 shows that an entry is provided for each combination of vendor ID (VID) and product ID (PID), and many such entries are recorded in the registry. Each of these entries indicates a USB device that has been connected to the host computer 1. The contents of "Device Parameters" in an entry with a vendor ID (VID) of 1089 and a product ID (PID) of 0021 (i.e., the entry with the illustrated "VID_1089&PID_0021") are shown in the right area of ​​FIG. 2. Here, "COM13", which is the data recorded for the parameter with the name "PortName", indicates the port number assigned to the external device 2, which is a USB virtual COM device with a vendor ID of 1069 and a product ID of 0021.

[0023] As described above, when the external device 2, which is a USB virtual CDC device, is connected to the host computer 1, a port number is assigned to the external device 2 and stored in the setting information database 23. However, the assigned port number is not automatically notified to the application program 11, and the application program 11 cannot know the port number assigned to the external device 2. Since the external device 2 is a USB virtual CDC device, the application program 11 needs to use the port number assigned to the external device 2 in order to send and receive data and commands to the external device 2. As a method for knowing the port number of the desired external device 2 from the application program 11 side, there is a method in which the application program 11 sends a command suitable for the target external device 2 while changing the port number in order from COM1, COM2, ..., and recognizes the port number that has responded to the command transmission as the port number for communicating with the target external device 2. However, with this method, commands are also sent to USB virtual COM devices other than the external device 2 to be searched (i.e., other USB virtual COM devices), so there is a risk of interfering with communication with the other USB virtual COM devices or causing malfunctions of the other virtual COM devices.

[0024] Therefore, in the connection method of this embodiment, when the application program 2 attempts to perform serial communication with a desired external device 2, it searches for the port number of the desired external device 2 without sending a command or the like to the device connected to the USB port 3, and starts communication using the port number found by the search. Figure 3 is a flowchart explaining the connection method of this embodiment.

[0025] Even if the port number of the desired external device 2 is unknown, as long as communication with a specific external device 2 is to be performed, at least the vendor ID and product ID of the external device 2 are known. In step 101, the DLL 12 waits for a connection request from the application program 11 to the external device 2. When the DLL 12 receives the connection request from the application program 11 to the external device 2, in step 102, the DLL 12 searches the setting information database 23 in the OS 20 using the vendor ID and product ID of the external device 2 as search keys to obtain the port number. Thereafter, in step 103, the application program 11 or the DLL 12 uses the obtained port number to start communication between the application program 11 and the external device 2 in a serial form. The vendor ID and product ID of the external device 2 may be included in the connection request from the application program 11 to the DLL 12, or the DLL 12 that receives the connection request may determine them according to the contents of the connection request, for example, by referring to a table provided in the DLL 12. When the vendor ID and product ID are determined in the DLL 12, there is an advantage that it is only necessary to update the DLL 12 in order to accommodate a new model of external device 2 having at least a different product ID, and there is no need to update the application program 11.

[0026] As described above, according to this embodiment, when the application program 11 installed in the host computer 1 attempts to communicate in serial form with the external device 2, which is a USB virtual COM device connected to the USB port 3 of the host computer 1, it can obtain the port number assigned to the external device 2 without sending actual command data. As a result, the application program 11 can start communication with the desired external device 2 without causing malfunctions or communication interference in other USB virtual COM devices connected to the host computer 1.

[0027] However, in the setting information database 23, there are cases where a plurality of entries having the same vendor ID and the same product ID are registered, that is, external devices 2 of the same model are registered in duplicate. In such cases of duplicate registration, in reality, a plurality of external devices 2 of the same model may be connected to the host computer 1 at the same time, but as described above, information registered in the setting information database 23 is not deleted in principle, so this includes cases where an existing external device 2 is replaced with a different external device 2 of the same model (i.e., an external device 2 with a different serial number) or where an external device 2 is reconnected to a different USB port 3 of the host computer 1. When external devices 2 of the same model are registered in the setting information database 23 in duplicate, when a search is performed in the same manner as described above using the vendor ID and product ID, in many cases, multiple port numbers are obtained due to the duplicate registration. Then, when multiple port numbers are obtained, connection confirmation is performed sequentially by a method such as transmitting a command using each of the obtained port numbers, and the port number that has responded to the command transmission is set as the port number to be used for communication. In this case, when the setting information database 23 is searched using the vendor ID and product ID as search keys, the port number used by other USB virtual COM devices than the target external device 2 is not obtained as a search result, so even if a connection check is performed by sending a command, malfunction or communication interference will not be caused in the other USB virtual COM devices connected to the host computer 1.

[0028] In the above explanation, the DLL 12 is interposed between the application program 11 and the OS 20, and the DLL 12 searches the setting information database 23, but the application program 11 itself may search the setting information database 23 using the vendor ID and product ID as search keys, without interposing the DLL 12 between the application program 11 and the OS 20. However, by providing the DLL 12, it becomes possible to flexibly respond to situations such as changing the external device 2 to a new model without updating the application program 11, and also to reduce the communication processing load on the application program 11.

[0029] 1, the application program 11, the DLL 12, and the OS 20 are all realized by software programs. Therefore, the present invention also includes a computer program that causes the host computer 1 to execute the above-mentioned processes. Such a program is loaded into the host computer 1 via an appropriate recording medium such as a CD-ROM, or via a network. [Explanation of symbols]

[0030] 1...host computer; 2...external device; 3, 4...USB port; 11...application program; 12...DLL (dynamic link library); 20...OS (operating system); 21...CDC driver; 22...USB driver; 23...setting information database.

Claims

1. A method for connecting an external device that is a USB virtual COM device to a host device that executes an application program, comprising the steps of: When the application program is to communicate with the external device in a serial format, a setting information database of an operating system of the host device is searched using identification information of the external device as a USB device as a search key to obtain a port number corresponding to the external device; Using the acquired port number, start communication between the application program and the external device; A connection method, when duplicate external devices having the same identification information are registered in the setting information database, obtaining the port number of each of the duplicate external devices, and then sequentially performing connection confirmation using each of the obtained port numbers before starting the communication between the application program and the external device.

2. 2. The connection method according to claim 1, wherein the identification information is a vendor ID and a product ID.

3. A dynamic link library is interposed between the application program and the operating system, 3. The connection method according to claim 1, wherein the dynamic link library executes a process of searching the setting information database to obtain a port number corresponding to the external device when the dynamic link library receives a connection request to the external device from the application program.

4. A computer having a USB port to which an external device, which is a USB virtual COM device, is connected and which executes an application program, a process for searching a setting information database of an operating system of the computer using identification information of the external device as a USB device as a search key to obtain a port number corresponding to the external device when the application program is to communicate with the external device in a serial format; A process of starting communication between the application program and the external device using the acquired port number; Run the command, When duplicate external devices having the same identification information are registered in the setting information database, the program causes the computer to execute a process of acquiring the port number for each of the duplicate external devices, and a process of sequentially performing connection confirmation using each of the acquired port numbers.

5. 5. The program according to claim 4, wherein the identification information is a vendor ID and a product ID.

6. The program is a dynamic link library program interposed between the application program and the operating system, 6. The program according to claim 4, further comprising: a program for causing the computer to execute a process of searching the setting information database to obtain a port number corresponding to the external device when a connection request to the external device is received from the application program.

Citation Information

Patent Citations

  • USB device and USB system

    JP2006134093A

  • Information processor, program, and recording medium

    JP2007034524A

  • Information processor, and use limitation method, and program

    JP2010015372A

  • Program for operating computer capable of communicating with mobile terminal

    JP2012014356A

  • Information processing device, information processing system, information processing method, program, and recording medium

    JP2013156877A