Method, device, terminal device and storage medium for obtaining serial port number of application device

By establishing a USB connection with the application device and obtaining its VID value and PID value, it quickly finds the target device information in the terminal device, thereby obtaining the serial port number of the application device, solving the problem of low efficiency in obtaining the serial port number in the prior art.

CN113886302BActive Publication Date: 2025-03-25LAUNCH TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111214587.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-19
Publication Date
2025-03-25
Estimated Expiration
2041-10-19

AI Technical Summary

Technical Problem

The prior art is less efficient when obtaining the serial port number of the application device and requires communication testing one by one.

Method used

By establishing a USB connection with the application device, obtain its VID value and PID value, and based on these values, find the target device information from all device information of the terminal device, thereby obtaining the serial port number.

Benefits of technology

It improves the efficiency of obtaining serial port numbers of the application equipment and reduces the number of communication tests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113886302B_ABST
    Figure CN113886302B_ABST
Patent Text Reader

Abstract

The present application is applicable to the field of computer technology, and provides a method, device, terminal device and storage medium for obtaining the serial port number of an application device. The method is applied to a terminal device, and the method includes: establishing a USB connection with the application device; obtaining the VID value and PID value of the application device; searching for the target device information corresponding to the application device from all device information currently used by the terminal device according to the VID value and PID value of the application device; and obtaining the serial port number of the application device from the target device information. The present application can quickly obtain the serial port number of the application device, thereby improving the efficiency of obtaining the serial port number of the application device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of computer technology, and in particular, relates to a method, device, terminal device and storage medium for obtaining a serial port number of an application device. Background Art

[0002] Serial interface is abbreviated as serial port, also known as serial communication interface or serial communication interface (usually refers to COM interface), which is an expansion interface using serial communication. In the prior art, when obtaining the serial port number of an application device, it is necessary to first obtain all the serial port numbers in the terminal device, and then perform communication tests with the terminal device in turn to find the application device and obtain the serial port number of the application device, resulting in low efficiency in obtaining the serial port number. Summary of the invention

[0003] The embodiments of the present application provide a method, an apparatus, a terminal device and a storage medium for obtaining the serial port number of an application device, so as to quickly obtain the serial port number of the application device and improve the efficiency of obtaining the serial port number of the application device.

[0004] A first aspect of an embodiment of the present application provides a method for obtaining a serial port number of an application device, which is applied to a terminal device, and the method includes:

[0005] Establishing a USB connection with the application device;

[0006] Obtaining the VID value and PID value of the application device;

[0007] According to the VID value and PID value of the application device, searching for the target device information corresponding to the application device from all the device information currently used by the terminal device;

[0008] The serial port number of the application device is obtained from the target device information.

[0009] Optionally, searching, according to the VID value and the PID value of the application device, the target device information corresponding to the application device from all device information currently used by the terminal device includes:

[0010] Select a piece of device information that has not been selected from all the device information, and obtain instance ID information of the device information;

[0011] Determine whether the instance ID information includes a VID character string and a PID character string;

[0012] If the instance ID information includes a VID character string and a PID character string, obtaining the hardware ID information of the currently selected device information;

[0013] Obtaining a target VID value and a target PID value in the hardware ID information;

[0014] Determine whether the target VID value and the target PID value are the same as the VID value and the PID value of the application device;

[0015] If they are the same, determining that the currently selected device information is the target device information corresponding to the application device;

[0016] If the instance ID information does not include a VID string or a PID string, or the target VID value is different from the VID value of the application device, or the target PID value is different from the PID value of the application device, the process returns to the step of selecting a device information that has not been selected from all device information and subsequent steps until the target device information is determined.

[0017] Optionally, before selecting a piece of unselected device information from all the device information and obtaining the instance ID information of the device information, the method further includes:

[0018] Creating a device information block list of the terminal device;

[0019] Add the device information corresponding to the currently used device into the device information block list;

[0020] Convert each of the device information into a corresponding specified data structure;

[0021] Correspondingly, the instance ID information of the device information is obtained, including:

[0022] The instance ID information is obtained from a target location in a specified data structure corresponding to the device information.

[0023] Optionally, acquiring the serial port number of the application device from the target device information includes:

[0024] Obtain the friendly name in the target device information;

[0025] The serial port number of the application device is found from the friendly name of the application device.

[0026] Optionally, searching for the serial port number of the application device from the friendly name of the application device includes:

[0027] Searching for a reference string from the friendly name of the application device, wherein the reference string represents a virtual serial port of a USB device;

[0028] When the reference string is found, the target string following the reference string in the friendly name of the application device is determined to be the serial port number of the application device, where the target string refers to a string containing COM and a number.

[0029] Optionally, after obtaining the serial port number of the application device, the method further includes:

[0030] Obtaining a device identification of the application device;

[0031] The serial port number of the application device and the device identifier are bound and saved in a configuration file.

[0032] Optionally, after binding the serial port number of the application device with the device identifier and saving them to the configuration file, the method further includes:

[0033] Searching for a corresponding serial port number from the configuration file according to the device identifier;

[0034] Communicate with the application device according to the serial port number;

[0035] If the communication fails, re-execute the steps described in the first aspect to re-acquire the latest serial port number of the application device;

[0036] The serial port number is updated to the latest serial port number in the configuration file.

[0037] A second aspect of an embodiment of the present application provides a device for obtaining a serial port number of an application device, the device comprising:

[0038] A connection module, used to establish a USB connection with the application device;

[0039] A first acquisition module, used to acquire the VID value and PID value of the application device;

[0040] A first search module, used to search for target device information corresponding to the application device from all device information currently used by the terminal device according to the VID value and PID value of the application device;

[0041] The second acquisition module is used to acquire the serial port number of the application device from the target device information.

[0042] Optionally, the first search module includes:

[0043] An instance acquisition unit, used to select a piece of device information that has not been selected from all the device information, and obtain instance ID information of the device information;

[0044] An instance determination unit, used to determine whether the instance ID information includes a VID character string and a PID character string;

[0045] A hardware acquisition unit, configured to acquire hardware ID information of the currently selected device information if the instance ID information includes a VID character string and a PID character string;

[0046] A target acquisition unit, used to acquire a target VID value and a target PID value in the hardware ID information;

[0047] A target determination unit, used to determine whether the target VID value and the target PID value are the same as the VID value and the PID value of the application device;

[0048] an information determining unit, configured to determine, if the information is the same, the currently selected device information as the target device information corresponding to the application device;

[0049] An operation return unit is used to return to the instance acquisition unit and subsequent units until the target device information is determined if the instance ID information does not include a VID string or a PID string, or the target VID value is different from the VID value of the application device, or the target PID value is different from the PID value of the application device.

[0050] Optionally, the first search module further includes:

[0051] A list creation unit, used to create a device information block list of the terminal device;

[0052] An information adding unit, used to add device information corresponding to the currently used device into the device information block list;

[0053] An information conversion unit, used to convert each of the device information into a corresponding specified data structure;

[0054] Correspondingly, the instance acquisition unit is specifically used for:

[0055] The instance ID information is obtained from a target location in a specified data structure corresponding to the device information.

[0056] Optionally, the second acquisition module includes:

[0057] A name acquisition unit, used to acquire a friendly name in the target device information;

[0058] The serial port search unit is used to search the serial port number of the application device from the friendly name.

[0059] Optionally, the serial port search unit is specifically used for:

[0060] Searching for a reference string from the friendly name, the reference string representing a USB device virtual serial port;

[0061] When the reference string is found, the target string following the reference string in the friendly name of the application device is determined to be the serial port number of the application device, where the target string refers to a string containing COM and a number.

[0062] Optionally, the device further comprises:

[0063] An identification acquisition module, used to acquire a device identification of the application device;

[0064] The serial port binding module is used to bind the serial port number of the application device with the device identifier and save them to a configuration file.

[0065] Optionally, the device further comprises:

[0066] A second search module, used to search the corresponding serial port number from the configuration file according to the device identification;

[0067] A communication module, used for communicating with the application device according to the serial port number;

[0068] A re-execution module, used for re-executing the module as described in the second aspect to re-acquire the latest serial port number of the application device if the communication fails;

[0069] An updating module is used to update the serial port number in the configuration file to the latest serial port number.

[0070] A third aspect of an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the method for obtaining the serial port number of the application device as described in the first aspect above are implemented.

[0071] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the method for obtaining the serial port number of an application device as described in the first aspect above are implemented.

[0072] A fifth aspect of the present application provides a computer program product, which includes a computer program. When the computer program is executed by one or more processors, the steps of the method for obtaining the serial port number of an application device as described in the first aspect are implemented.

[0073] As can be seen from the above, the present application scheme establishes a Universal Serial Bus (USB) connection with the application device and obtains the vendor identification code (Vendor ID, VID) value and product identification code (Product ID, PID) value of the application device. According to the VID value and PID value of the application device, the target device information corresponding to the application device can be quickly found from all device information currently used by the terminal device, thereby quickly obtaining the serial port number of the application device from the target device information, thereby improving the efficiency of obtaining the serial port number of the application device. BRIEF DESCRIPTION OF THE DRAWINGS

[0074] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.

[0075] Figure 1 It is a structural diagram of a system for obtaining a serial port number of an application device provided in Example 1 of the present application;

[0076] Figure 2 This is a schematic diagram of the implementation flow of the method for obtaining the serial port number of an application device provided in Example 2 of the present application;

[0077] Figure 3 This is a schematic diagram of the implementation flow of the method for obtaining the serial port number of an application device provided in Example 3 of the present application;

[0078] Figure 4 It is a structural diagram of a device for obtaining a serial port number of an application device provided in Embodiment 4 of the present application;

[0079] Figure 5 It is a structural diagram of the terminal device provided in Example 5 of the present application. DETAILED DESCRIPTION

[0080] In the following description, specific details such as specific system structures and technologies are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obstructing the description of the present application with unnecessary details.

[0081] It should be understood that when used in this specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.

[0082] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0083] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0084] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0085] It should be understood that the size of the serial numbers of the steps in this embodiment does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.

[0086] In order to illustrate the technical solution described in this application, a specific embodiment is provided below for illustration.

[0087] See also Figure 1 , is a structural diagram of a system for obtaining a serial port number of an application device provided in Example 1 of the present application.

[0088] like Figure 1As shown, the serial port number acquisition system of the application device includes a terminal device 11 and at least one using device 12. Among them, the using device 12 can refer to a device that establishes communication with the terminal device 11 through a serial port, such as a plug and play (PNP) device, a small computer system interface (SCSI) device, a USB device, a Bluetooth device, etc. The using device 12 includes at least an application device, which is a USB to serial port device and can establish a USB connection with the terminal device 11. For example, the application device is a vehicle communication interface (VCI) box that can perform fault diagnosis on a vehicle.

[0089] The terminal device 11 can be a mobile phone, a tablet computer, a personal digital assistant (PDA), a smart wearable device (such as a smart watch, a smart bracelet), a vehicle-mounted terminal, or other devices, which is not limited in this embodiment.

[0090] In this embodiment, the terminal device 11 establishes a USB connection with the application device and obtains the VID value and PID value of the application device. Based on the VID value and PID value of the application device, the terminal device 11 can quickly find the target device information corresponding to the application device from all device information currently used by the terminal device 11, thereby obtaining the serial port number of the application device from the target device information, thereby improving the efficiency of obtaining the serial port number of the application device.

[0091] See also Figure 2 , is a schematic diagram of the implementation flow of the method for obtaining the serial port number of an application device provided in the second embodiment of the present application, and the method for obtaining the serial port number is applied to a terminal device. Figure 2 As shown, the serial port number obtaining method may include the following steps:

[0092] Step 201: Establish a USB connection with an application device.

[0093] The application device is a USB to serial port device, that is, a USB device.

[0094] The terminal device can access the application device by establishing a USB connection with the application device.

[0095] Step 202: Acquire the VID value and PID value of the application device.

[0096] USB devices all have VID and PID. The VID is applied for by the supplier from the USB Implementers Forum, and each supplier's VID is unique. The PID is determined by the supplier.

[0097] In one embodiment, the VID value and PID value of the application device can be obtained through a variety of methods such as user input, designated device sending, or pre-storage. For example, for the user input method, a first input box and a second input box can be displayed on the terminal device, and the user can enter the VID value of the application device in the first input box and the PID value of the application device in the second input box. For the designated device sending method, the designated device at least stores the VID value and PID value of the application device, and the designated device can send the stored VID value and PID value of the application device to the terminal device by establishing a communication connection with the terminal device. For the pre-storage method, the VID value and PID value of the application device can be pre-stored in the terminal device, and when the terminal device obtains the serial port number of the application device, the pre-stored VID value and PID value of the application device can be directly used to obtain the serial port number of the application device.

[0098] In another embodiment, the VID information and PID information of the application device may be obtained first, and then the VID value of the application device may be extracted from the VID information of the application device, and the PID value of the application device may be extracted from the PID information of the application device. For example, if the VID information of the VCI box is VID_0404 and the PID information is PID_6006, then the VID value of the VCI box is 0404 and the PID value is 6006. The VID information and PID information of the application device may also be obtained through a variety of methods such as user input, sending by a designated device, or pre-storage, which are not limited here.

[0099] Step 203: According to the VID value and PID value of the application device, the target device information corresponding to the application device is searched from all the device information currently used by the terminal device.

[0100] Among them, all device information used by the terminal device at the current moment may refer to device information of all devices used that the terminal device is connected to at the current moment.

[0101] It should be noted that the terminal device may be connected to multiple usage devices (such as application devices, mice, printers, keyboards, etc.) at the current moment. In order to distinguish the device information of the application device from the device information of other devices, the device information of the application device may be referred to as target device information in this embodiment. The other devices refer to the devices other than the application devices among the multiple usage devices.

[0102] The device information of the device used may refer to information related to the device used, for example, the device information of the device used includes but is not limited to attribute information such as hardware ID information, instance ID information, friendly name, location information, and class description of the device used.

[0103] The hardware ID information may refer to the specific content of the hardware ID. For example, the hardware ID information of a device is COMPORT&VID_0404&PID_6006&MI_02.

[0104] The instance ID information may refer to the specific content of the instance ID. For example, the instance ID information of a device is COMPORT&VID_0404&PID_6006&MI_02\6&3B498E3C&0&0002. The instance ID is a device identification string provided by the terminal device, which is used to uniquely identify the device in the terminal device. The instance ID can be understood as the device instance path.

[0105] The friendly name may refer to a device name with some descriptive characters added, which can be understood as an alias of the device.

[0106] The terminal device is usually connected to a large number of devices. This embodiment can quickly find the target device information corresponding to the application device from the device information of more devices based on the VID value and PID value of the application device, without the need to perform communication tests on all devices, thereby improving the search speed of the target device information corresponding to the application device.

[0107] Step 204: Obtain the serial port number of the application device from the target device information.

[0108] After the terminal device establishes a USB connection with the application device, it randomly assigns a serial port number to the application device.

[0109] When the target device information corresponding to the application device is found from the device information of more user devices, it indicates that which user device is the application device, and the serial port number of the application device can be directly obtained from the target device information, which improves the efficiency of obtaining the serial port number. For example, the terminal device is currently connected to five user devices, namely the first user device, the second user device, the third user device, the fourth user device and the fifth user device. According to the VID value and PID value of the application device, the fourth user device is found to be the application device from the above five user devices, so it can be determined that the serial port number of the fourth user device is the serial port number of the application device.

[0110] As an optional embodiment, after obtaining the serial port number of the application device, the method further includes:

[0111] Get the device ID of the application device;

[0112] Bind the serial port number of the application device to the device ID and save them to the configuration file.

[0113] The device identifier of the application device represents the uniqueness of the application device, and different devices have different device identifiers.

[0114] Binding the serial port number of the application device with the device identification may refer to associating the serial port number of the application device with the device identification, that is, establishing a mapping relationship between the serial port number and the device identification. When the terminal device diagnoses the vehicle through the application device, it can directly obtain the serial port number of the application device from the configuration file according to the device identification of the application device, thereby saving the time of calling the serial port of the application device and quickly starting the diagnostic program.

[0115] As an optional embodiment, after the serial port number of the application device is bound to the device identifier and saved in the configuration file, the method further includes:

[0116] Find the corresponding serial port number from the configuration file according to the device ID;

[0117] Communicate with the application device according to the serial port number;

[0118] If the communication fails, re-execute steps 201 to 204 to re-acquire the latest serial port number of the application device;

[0119] Update the serial port number to the latest one in the configuration file.

[0120] In order to improve the accuracy of the serial port number of the application device, the serial port number of the application device can also be verified. During the verification, the device identification of the application device can be obtained, and the corresponding serial port number can be found from the configuration file according to the device identification of the application device. The terminal device communicates with the application device through the serial port number; if the communication is successful, it is determined that the serial port number of the application device stored in the configuration file is correct; if the communication fails, it is determined that the serial port number of the application device stored in the configuration file is incorrect, and the serial port number of the application device (i.e., the latest serial port number) can be re-obtained by re-executing steps 201 to 204 until the communication is successful.

[0121] The embodiment of the present application establishes a USB device with the application device to obtain the VID value and PID value of the application device. According to the VID value and PID value of the application device, the target device information corresponding to the application device can be quickly found from all device information currently used by the terminal device, thereby quickly obtaining the serial port number of the application device from the target device information, thereby improving the efficiency of obtaining the serial port number of the application device.

[0122] See also Figure 3 , is a schematic diagram of the implementation flow of the method for obtaining the serial port number of an application device provided in the third embodiment of the present application, and the method for obtaining the serial port number is applied to a terminal device. Figure 3 As shown, the serial port number obtaining method may include the following steps:

[0123] Step 301: Establish a USB connection with an application device.

[0124] This step is the same as step 201. For details, please refer to the relevant description of step 201, which will not be repeated here.

[0125] Step 302: Acquire the VID value and PID value of the application device.

[0126] This step is the same as step 202. For details, please refer to the relevant description of step 202, which will not be repeated here.

[0127] Step 303: Select a piece of device information that has not been selected from all the device information, and obtain the instance ID information of the device information.

[0128] In this embodiment, all device information may be traversed to find target device information from all device information.

[0129] As an optional embodiment, before selecting a piece of device information that has not been selected from all the device information and obtaining the instance ID information of the device information, the method further includes:

[0130] Create a list of device information blocks for terminal devices;

[0131] Add the device information corresponding to the currently used device into the device information block list;

[0132] Convert each device information into a corresponding specified data structure;

[0133] Correspondingly, the instance ID information of the device information is obtained, including:

[0134] The instance ID information is obtained from a target location in a specified data structure corresponding to the device information.

[0135] The terminal device may create a device information block list through a Microsoft Personal Computer (PC) driver function: SetupDiCreateDeviceInfoList.

[0136] The terminal device can add the device information corresponding to the currently used device into the device information block list through the Microsoft PC driver function: SetupDiGetClassDevsEx.

[0137] Converting each device information into a corresponding designated data structure means converting each device information in the device information block list into a corresponding designated data structure, so that the terminal device can quickly obtain the instance ID information from the device information. The designated data structure refers to a pre-set data structure. The target position refers to the position of the instance ID information in the designated data structure corresponding to the device information.

[0138] The terminal device can use the Microsoft PC driver function: SetupDiEnumDeviceInfo to enumerate each device information in the device information block list.

[0139] The terminal device can obtain the instance ID information through the Microsoft PC driver function: SetupDiGetDeviceInstanceId.

[0140] Step 304: determine whether the instance ID information includes a VID character string and a PID character string.

[0141] The VID string is a string of characters consisting of three characters: V, I, and D. The PID string is a string of characters consisting of three characters: P, I, and D. For example, for the instance ID information: COMPORT&VID_0404&PID_6006&MI_02\6&3B498E3C&0&0002, the instance ID information contains the VID string and the PID string. For the hardware ID information: COMPORT&VID_0404&PID_6006&MI_02, the hardware ID information contains the VID value (i.e., 0404) and the PID value (i.e., 6006) of the application device.

[0142] If the instance ID information in step 303 includes a VID string and a PID string, step 305 and subsequent steps are executed; if the instance ID information in step 303 does not include a VID string or a PID string, the process returns to step 303 and subsequent steps until the target device information is determined.

[0143] Step 305: Obtain the hardware ID information of the currently selected device information.

[0144] The terminal device can obtain the hardware ID information through the Microsoft PC driver function: SetupDiGetDeviceRegistryProperty, setting the parameter of SetupDiGetDeviceRegistryProperty to SPDRP_HARDWAREID.

[0145] Step 306: Obtain the target VID value and the target PID value in the hardware ID information.

[0146] The target VID value refers to the VID value in the hardware ID information, and the target PID value refers to the PID value in the hardware ID information.

[0147] Step 307: determine whether the target VID value and the target PID value are the same as the VID value and the PID value of the application device.

[0148] Specifically, determine whether the target VID value is the same as the VID value of the application device, and determine whether the target PID value is the same as the PID value of the application device; if the target VID value is the same as the VID value of the application device and the target PID value is the same as the PID value of the application device, execute step 308; if the target VID value is not the same as the VID value of the application device, or the target PID value is not the same as the PID value of the application device, return to execute step 303 until the target device information is determined.

[0149] Step 308: determine that the currently selected device information is the target device information corresponding to the application device.

[0150] Since the application device is a USB device, for each of all the usage devices, it is possible to first determine whether the usage device is a USB device based on whether the instance ID information of the usage device includes a VID string and a PID string. If it is a USB device, it is then possible to determine whether the USB device is an application device based on the target VID value and target PID value in the hardware ID information of the USB device, as well as the VID value and PID value of the application device.

[0151] In one embodiment, for the i-th device information in the device information block list, the i-th device information is any device information in the device information block list, it can be determined whether the instance ID information of the i-th device information includes the VID string and the PID string; if the instance ID information of the i-th device information includes the VID string and the PID string, it is determined that the use device corresponding to the i-th device information is a USB device, and then it is determined whether the target VID value and PID value of the hardware ID information of the i-th device information are the same as the VID value and PID value of the application device; if the VID value and PID value of the hardware ID information of the i-th device information are the same as the VID value and PID value of the application device, it is determined that the use device corresponding to the i-th device information is the application device, and the serial port number of the use device corresponding to the i-th device information is the serial port number of the application device. At this time, the serial port number of the application device can be obtained from the i-th device information. Serial port number, no need to traverse other device information in the device information block list (i.e., device information that has not been traversed); if the instance ID information of the ith device information does not include a VID string or a PID string, it is determined that the device corresponding to the ith device information is not a USB device, let alone an application device, so it is necessary to continue to traverse other device information in the device information block list to determine whether the device corresponding to other device information is an application device; if the target VID value in the hardware ID information of the ith device information is different from the VID value of the application device or the target PID value in the hardware ID information is different from the PID value of the application device, it is determined that the device corresponding to the ith device information is not an application device, and it is necessary to continue to traverse other device information in the device information block list to determine whether the device corresponding to other device information is an application device; the traversal is stopped until the application device is found or the device information block list is traversed.

[0152] Step 309: Obtain the serial port number of the application device from the target device information.

[0153] This step is the same as step 204. For details, please refer to the relevant description of step 204, which will not be repeated here.

[0154] As an optional embodiment, obtaining the serial port number of the application device from the target device information includes:

[0155] Get the friendly name in the target device information;

[0156] Find the serial port number of the application device from the friendly name.

[0157] Since the friendly name usually includes the serial port number, after obtaining the target device information corresponding to the application device, the serial port number of the application device can be found from the friendly name in the target device information.

[0158] As an optional embodiment, searching the serial port number of the application device from the friendly name includes:

[0159] Find a reference string from the friendly name of the application device, where the reference string represents a virtual serial port of the USB device;

[0160] When the reference string is found, the target string located after the reference string in the friendly name of the application device is determined to be the serial port number of the application device, and the target string refers to a string containing COM and a number.

[0161] Since the serial port number is usually located after the reference string of the friendly name, after finding the application device, you can first find the reference string from the friendly name of the application device, and then find the serial port number of the application device based on the reference string. For example, the friendly name of the application device is: XXX Virtual COM Port (COM12), the reference string is XXX Virtual COM Port, and the target string is COM12, that is, the serial port number of the application device is COM12.

[0162] The embodiment of the present application traverses all device information used by the terminal device at the current moment, and can quickly find the target device information corresponding to the application device from all device information based on the instance ID information and hardware ID information in the device information, as well as the VID value and PID value of the application device, thereby obtaining the serial port number of the application device from the friendly name in the target device information, thereby improving the efficiency of obtaining the serial port number of the application device.

[0163] See also Figure 4 , is a schematic diagram of a serial port number acquisition device for an application device provided in Example 4 of the present application. For ease of explanation, only the parts related to the example of the present application are shown.

[0164] The serial port number obtaining device of the above application equipment includes:

[0165] A connection module 41, used to establish a USB connection with the application device;

[0166] A first acquisition module 42, used to acquire the VID value and PID value of the application device;

[0167] A first search module 43 is used to search for target device information corresponding to the application device from all device information currently used by the terminal device according to the VID value and PID value of the application device;

[0168] The second acquisition module 44 is used to acquire the serial port number of the application device from the target device information.

[0169] Optionally, the first search module 43 includes:

[0170] An instance acquisition unit, used to select a piece of device information that has not been selected from all the device information, and obtain instance ID information of the device information;

[0171] An instance determination unit, used to determine whether the instance ID information includes a VID character string and a PID character string;

[0172] A hardware acquisition unit, configured to acquire hardware ID information of the currently selected device information if the instance ID information includes a VID character string and a PID character string;

[0173] A target acquisition unit, used to acquire a target VID value and a target PID value in the hardware ID information;

[0174] A target determination unit, used to determine whether the target VID value and the target PID value are the same as the VID value and the PID value of the application device;

[0175] an information determining unit, configured to determine, if the information is the same, the currently selected device information as the target device information corresponding to the application device;

[0176] An operation return unit is used to return to the instance acquisition unit and subsequent units until the target device information is determined if the instance ID information does not include a VID string or a PID string, or the target VID value is different from the VID value of the application device, or the target PID value is different from the PID value of the application device.

[0177] Optionally, the first search module 43 further includes:

[0178] A list creation unit, used to create a device information block list of the terminal device;

[0179] An information adding unit, used to add device information corresponding to the currently used device into the device information block list;

[0180] An information conversion unit, used to convert each of the device information into a corresponding specified data structure;

[0181] Correspondingly, the instance acquisition unit is specifically used for:

[0182] The instance ID information is obtained from a target location in a specified data structure corresponding to the device information.

[0183] Optionally, the second acquisition module 44 includes:

[0184] A name acquisition unit, used to acquire a friendly name in the target device information;

[0185] The serial port search unit is used to search the serial port number of the application device from the friendly name.

[0186] Optionally, the serial port search unit is specifically used for:

[0187] Searching for a reference string from the friendly name, the reference string representing a USB device virtual serial port;

[0188] When the reference string is found, the target string following the reference string in the friendly name of the application device is determined to be the serial port number of the application device, where the target string refers to a string containing COM and a number.

[0189] Optionally, the device further comprises:

[0190] An identification acquisition module, used to acquire a device identification of the application device;

[0191] The serial port binding module is used to bind the serial port number of the application device with the device identifier and save them to a configuration file.

[0192] Optionally, the device further comprises:

[0193] A second search module, used to search the corresponding serial port number from the configuration file according to the device identification;

[0194] A communication module, used for communicating with the application device according to the serial port number;

[0195] A re-execution module, used for re-executing the module as described in the second aspect to re-acquire the latest serial port number of the application device if the communication fails;

[0196] An updating module is used to update the serial port number in the configuration file to the latest serial port number.

[0197] The serial port number acquisition device of the application device provided in the embodiment of the present application can be applied in the aforementioned method embodiments 2 and 3. For details, please refer to the description of the aforementioned method embodiments 2 and 3, which will not be repeated here.

[0198] Figure 5 Schematic diagram of the terminal device provided in Embodiment 5 of the present application. Figure 5 As shown, the terminal device 5 of this embodiment includes: a processor 50, a memory 51, and a computer program 52 stored in the memory 51 and executable on the processor 50. When the processor 50 executes the computer program 52, the steps in the above-mentioned method for obtaining the serial port number of each application device are implemented, for example Figure 2Alternatively, when the processor 50 executes the computer program 52, the functions of each module / unit in the embodiment of the device for obtaining the serial port number of the application device are realized, for example Figure 4 The functions of the modules 41 to 44 are shown.

[0199] Specifically, the processor 50 implements the method steps of the above-mentioned embodiment 2 and embodiment 3 by running the computer program 52 stored in the memory 51. The terminal device 5 may include, but is not limited to, a processor 50 and a memory 51. Those skilled in the art will understand that Figure 5 It is only an example of the terminal device 5 and does not constitute a limitation of the terminal device 5. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.

[0200] The processor 50 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0201] The memory 51 may be an internal storage unit of the terminal device 5, such as a hard disk or memory of the terminal device 5. The memory 51 may also be an external storage device of the terminal device 5, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 5. Further, the memory 51 may also include both an internal storage unit and an external storage device of the terminal device 5. The memory 51 is used to store the computer program and other programs and data required by the terminal device. The memory 51 may also be used to temporarily store data that has been output or is to be output.

[0202] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0203] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0204] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0205] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0206] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0207] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0208] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0209] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A method for obtaining a serial port number of an application device, characterized in that: Applied to a terminal device, the method comprises: Establishing a USB connection with the application device; Obtaining the VID value and PID value of the application device; According to the VID value and PID value of the application device, searching for the target device information corresponding to the application device from all the device information currently used by the terminal device; Obtaining the serial port number of the application device from the target device information; The step of searching, according to the VID value and the PID value of the application device, the target device information corresponding to the application device from all the device information currently used by the terminal device comprises: Select a piece of device information that has not been selected from all the device information, and obtain instance ID information of the device information; Determine whether the instance ID information includes a VID character string and a PID character string; If the instance ID information includes a VID character string and a PID character string, obtaining the hardware ID information of the currently selected device information; Obtaining a target VID value and a target PID value in the hardware ID information; Determine whether the target VID value and the target PID value are the same as the VID value and the PID value of the application device; If they are the same, determining that the currently selected device information is the target device information corresponding to the application device; If the instance ID information does not include a VID string or a PID string, or the target VID value is different from the VID value of the application device, or the target PID value is different from the PID value of the application device, the process returns to the step of selecting a device information that has not been selected from all the device information and subsequent steps until the target device information is determined.

2. The method according to claim 1, characterized in that Before selecting a piece of unselected device information from all the device information and obtaining the instance ID information of the device information, the method further includes: Creating a device information block list of the terminal device; Add the device information corresponding to the currently used device into the device information block list; Convert each of the device information into a corresponding specified data structure; Correspondingly, the instance ID information of the device information is obtained, including: The instance ID information is obtained from a target location in a specified data structure corresponding to the device information.

3. The method according to claim 1, characterized in that The obtaining the serial port number of the application device from the target device information includes: Obtain the friendly name in the target device information; The serial port number of the application device is found from the friendly name.

4. The method according to claim 3, characterized in that The step of searching the serial port number of the application device from the friendly name includes: Searching for a reference string from the friendly name, the reference string representing a USB device virtual serial port; When the reference string is found, the target string following the reference string in the friendly name of the application device is determined to be the serial port number of the application device, where the target string refers to a string containing COM and a number.

5. The method according to any one of claims 1 to 4, characterized in that: After obtaining the serial port number of the application device, the method further includes: Obtaining a device identification of the application device; The serial port number of the application device is bound to the device identifier and saved in a configuration file.

6. The method according to claim 5, characterized in that After binding the serial port number of the application device with the device identifier and saving them to the configuration file, the method further includes: Searching for a corresponding serial port number from the configuration file according to the device identifier; Communicate with the application device according to the serial port number; If the communication fails, re-execute the steps as claimed in claim 1 to re-acquire the latest serial port number of the application device; The serial port number is updated to the latest serial port number in the configuration file.

7. A device for obtaining a serial port number of an application device, characterized in that: The device comprises: A connection module, used to establish a USB connection with the application device; A first acquisition module, used to acquire the VID value and PID value of the application device; A first search module, used to search for target device information corresponding to the application device from all device information currently used by the terminal device according to the VID value and PID value of the application device; A second acquisition module, used to acquire the serial port number of the application device from the target device information; The first search module includes: An instance acquisition unit, used to select a piece of device information that has not been selected from all the device information, and obtain instance ID information of the device information; An instance determination unit, used to determine whether the instance ID information includes a VID character string and a PID character string; A hardware acquisition unit, configured to acquire hardware ID information of the currently selected device information if the instance ID information includes a VID character string and a PID character string; A target acquisition unit, used to acquire a target VID value and a target PID value in the hardware ID information; A target determination unit, used to determine whether the target VID value and the target PID value are the same as the VID value and the PID value of the application device; an information determining unit, configured to determine, if the information is the same, the currently selected device information as the target device information corresponding to the application device; An operation return unit is used to return to the instance acquisition unit and subsequent units until the target device information is determined if the instance ID information does not include a VID string or a PID string, or the target VID value is different from the VID value of the application device, or the target PID value is different from the PID value of the application device.

8. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Communication method and device of diagnosis equipment, electronic equipment and storage medium

    CN112104708A