Summary of the invention
In view of above-mentioned the deficiencies in the prior art, the object of the present invention is to provide recognition methods and the system of a kind of USB device connectivity port, be intended to solve in prior art USB port recognition methods efficiency low, inquire about inconvenient problem.
Technical scheme of the present invention is as follows:
A recognition methods for USB device connectivity port, wherein, comprises step:
A, in system, register a message that changes message for capture device and catch window, when target USB device is connected in system, by described message, catches window capture device and change message;
B, by the equipment that captures, change the device id information of the target USB device that the parameter acquiring in message connects;
C, create all USB device in a query handler cyclic query system, from all USB device, find and the corresponding identical USB device of described device id, and be labeled as described target USB device, obtain the port information of this target USB device.
The recognition methods of described USB device connectivity port, wherein, described steps A specifically comprises:
A1, call a device registration notification function;
A2, a window handle is passed to first parameter of described device registration notification function;
A3, when target USB device is connected in system, system changes message to described window handle transmitting apparatus, thereby realize capture device, changes message.
The recognition methods of described USB device connectivity port, wherein, in described step B, also comprises: the device type information and the plug information that by the equipment capturing, change the target USB device of the parameter acquiring connection in message.
The recognition methods of described USB device connectivity port, wherein, described step C specifically comprises:
C1, create a query handler, call an inquiry designated equipment information function, described query handler is passed to first parameter of described inquiry designated equipment information function, the index that the second parameter of described inquiry designated equipment information function is query facility, the 3rd parameter of described inquiry designated equipment information function is the facility information data of returning while calling successfully;
Whether C2, judgement are called described inquiry designated equipment information function and are returned very;
C3, when calling described inquiry designated equipment information function, return to true time, by a query facility ID function, obtain the device id of current indexing apparatus, and proceed to step C4; When calling described inquiry designated equipment information function, return to non-true time, flow process finishes;
Whether the device id of current indexing apparatus that C4, judgement are obtained is identical with the device id of described target USB device, when being, proceeds to step C5;
C5, when the device id of the current indexing apparatus obtaining is identical with the device id of described target USB device, the connectivity port that obtains target USB device the facility information data of returning from the 3rd parameter of described inquiry designated equipment information function.
The recognition methods of described USB device connectivity port, wherein, described step C4 also comprises:
When the device id of the current indexing apparatus obtaining is not identical with the device id of described target USB device, the index of described inquiry designated equipment information function is added to 1, continue to call described inquiry designated equipment information function, and return to step C2.
A recognition system for USB device connectivity port, wherein, comprising:
Equipment changes message trapping module, for register one in system, for the message of capture device change message, catches window, when target USB device is connected in system, catches window capture device change message by described message;
Device id acquisition of information module, changes the device id information of the target USB device that the parameter acquiring of message connects for equipment by capturing;
Port information acquisition module, for creating all USB device of a query handler cyclic query system, from all USB device, find with the corresponding identical USB device of described device id and be labeled as described target USB device, obtain the port information of this target USB device.
The recognition system of described USB device connectivity port, wherein, described equipment changes message trapping module and specifically comprises:
Device registration notification function call unit, for calling a device registration notification function;
Window handle call unit, for passing to a window handle first parameter of described device registration notification function;
Equipment changes message acquiring unit, and for when target USB device is connected to system, system changes message to described window handle transmitting apparatus, thereby realize capture device, changes message.
The recognition system of described USB device connectivity port, wherein, described port information acquisition module comprises:
Inquiry designated equipment information function call unit, be used for creating a query handler, call an inquiry designated equipment information function, described query handler is passed to first parameter of described inquiry designated equipment information function, the index that the second parameter of described inquiry designated equipment information function is query facility, the 3rd parameter of described inquiry designated equipment information function is the facility information data of returning while calling successfully;
Return to true judging unit, for judgement, call described inquiry designated equipment information function and whether return very;
Device id acquiring unit, for returning to true time when calling described inquiry designated equipment information function, obtains the device id of current indexing apparatus by a query facility ID function;
ID judging unit, for judging that whether the device id of the current indexing apparatus obtaining is identical with the device id of described target USB device;
Connectivity port acquiring unit, for when the device id of the current indexing apparatus obtaining is identical with the device id of described target USB device, the facility information data of returning from the 3rd parameter of described inquiry designated equipment information function, obtain the device id of target USB device.
The present invention registers a message and catches window in system, to catch the equipment of USB device while inserting, change message, then from this equipment, change message and obtained device id information, finally by creating a query handler, find facility information data corresponding to USB device, thereby obtained the port information of USB device, method of the present invention is owing to only need calling SDK function, and without calling DDK function, so implementation procedure is simple, reduced technical difficulty, and port identification efficiency of the present invention is high, port is searched conveniently, has stronger practicality.
Embodiment
The invention provides recognition methods and the system of a kind of USB device connectivity port, for making object of the present invention, technical scheme and effect clearer, clear and definite, below the present invention is described in more detail.Should be appreciated that specific embodiment described herein, only in order to explain the present invention, is not intended to limit the present invention.
Refer to Fig. 1, Fig. 1 is the process flow diagram of the recognition methods preferred embodiment of USB device of the present invention connectivity port, and as shown in the figure, it comprises step:
S101, in system, register a message that changes message for capture device and catch window, when target USB device is connected in system, by described message, catches window capture device and change message;
S102, by the equipment that captures, change the device id information of the target USB device that the parameter acquiring in message connects;
S103, create all USB device in a query handler cyclic query system, from all USB device, find and the corresponding identical USB device of described device id, and be labeled as described target USB device, obtain the port information of this target USB device.
In step S101, first need in system (system in the present invention refers to Windows system), a message of registration catch window, while inserting with convenient USB device, real-time capture device changes message (WM_DEVICECHANGE message).
Specifically, as shown in Figure 2, described step S101 can specifically be refined as following steps:
S201, call a device registration notification function;
S202, a window handle is passed to first parameter of described device registration notification function;
S203, when target USB device is connected in system, system changes message to described window handle transmitting apparatus, thereby realize capture device, changes message.
A window handle is passed to first parameter of this device registration notification function (Register Device Notification), when having USB device insert or extract, Windows system will be that first parameter transmitting apparatus changes message to this window handle like this.In addition, also need in the message processing function of Windows system, increase the processing that this equipment is changed to message, make this message catch window and can obtain in time equipment change message.
In step S102, from the equipment getting, change the facility information that can obtain target USB device message, for example device id, device type or insertion or plug state etc., particularly, can change from equipment device id information and the device type information of the LParam parameter acquiring target USB device of message, the WParam parameter judgement target USB device that can change message from equipment is insert or extract.
In step S103, obtained after the device id of target USB device, need in all USB device in system, find target USB device, thereby obtain its port information.
Particularly, as shown in Figure 3, step S103 specifically comprises:
S301, create a query handler, call an inquiry designated equipment information function, described query handler is passed to first parameter of described inquiry designated equipment information function, the index that the second parameter of described inquiry designated equipment information function is query facility, the 3rd parameter of described inquiry designated equipment information function is the facility information data of returning while calling successfully; First by calling SetupDiGetClassDevs function (existing function in Windows system), create a query handler, then call SetupDiEnumDeviceInfo function (inquiry designated equipment information function), described query handler is passed to first parameter of inquiry designated equipment information function, the index that this function second parameter is query facility, inquire about the equipment that this index is corresponding, the 3rd parameter is the facility information data of returning while calling successfully, wherein comprised the port information of required inquiry.
Whether S302, judgement are called described inquiry designated equipment information function and are returned very; Whether equipment corresponding to judgement this index of inquiry exists.If the equipment that index is corresponding does not exist and directly proceeds to step S307, if existed, enter into step S303.
S303, when calling described inquiry designated equipment information function, return to true time, by a query facility ID function, obtain the device id of current indexing apparatus; This query facility ID function (SetupDiGetDeviceInstanceId) can obtain the device id of current indexing apparatus.
Whether the device id of current indexing apparatus that S304, judgement are obtained is identical with the device id of described target USB device; This step is to judge whether the device id of current indexing apparatus is the device id of the target USB device of desired seek, when being, proceeds to step S305, otherwise proceeds to step S306.
S305, when the device id of the current indexing apparatus obtaining is identical with the device id of described target USB device, the connectivity port that obtains target USB device the facility information data of returning from the 3rd parameter of described inquiry designated equipment information function.If current indexing apparatus is exactly target USB device, the 3rd parameter of returning so, just can obtain facility information data when inquiry designated equipment information function calls successfully, invocation facility registration function (SetupDiGetDeviceRegistryProperty) is obtained the facility information data in described inquiry designated equipment information function again, the second parameter of this facility registration function is facility information data, then from these facility information data, can find the device id of target USB device.
S306, when the device id of the current indexing apparatus obtaining is not identical with the device id of described target USB device, the index of described inquiry designated equipment information function is added to 1, continue to call described inquiry designated equipment information function, and return to step S302.
If can find the USB device identical with the device id of target USB device by above-mentioned steps from indexing apparatus, return to corresponding facility information data, thereby obtain the port information of target USB device, if and do not find the USB device identical with the device id of target USB device, be judged to be the port information that does not find target USB device, and return to user.
Because recognition methods of the present invention is the SDK(Software tool kit that calls Windows system, be used to specific software package, software frame, hardware platform, operating system etc. create the set of the developing instrument of application software, can simply for certain programming language, provide some files of application programming interfaces API), the method applied in the present invention only needs api function (aforesaid device registration notification function for example, inquiry designated equipment information function etc.), and drive kit without the DDK(that calls Windows), so development efficiency is high, and identifying is quick, accurately, the present invention can carry out port identification to reaching 20 USB device simultaneously after tested.
Based on said method, the present invention also provides the recognition system of a kind of USB device connectivity port, and as shown in Figure 4, described recognition system comprises:
Equipment changes message trapping module 100, for register one in system, for the message of capture device change message, catches window, when target USB device is connected in system, catches window capture device change message by described message;
Device id acquisition of information module 200, changes the device id information of the target USB device that the parameter acquiring of message connects for equipment by capturing;
Port information acquisition module 300, for creating all USB device of a query handler cyclic query system, from all USB device, find with the corresponding identical USB device of described device id and be labeled as described target USB device, obtain the port information of this target USB device.
Further, as shown in Figure 5, described equipment changes message trapping module 100 and specifically comprises:
Device registration notification function call unit 110, for calling a device registration notification function;
Window handle call unit 120, for passing to a window handle first parameter of described device registration notification function;
Equipment changes message acquiring unit 130, and for when target USB device is connected to system, system changes message to described window handle transmitting apparatus, thereby realize capture device, changes message.
Further, as shown in Figure 6, described port information acquisition module 300 comprises:
Inquiry designated equipment information function call unit 310, be used for creating a query handler, call an inquiry designated equipment information function, described query handler is passed to first parameter of described inquiry designated equipment information function, the index that the second parameter of described inquiry designated equipment information function is query facility, the 3rd parameter of described inquiry designated equipment information function is the facility information data of returning while calling successfully;
Return to true judging unit 320, for judgement, call described inquiry designated equipment information function and whether return very;
Device id acquiring unit 330, for returning to true time when calling described inquiry designated equipment information function, obtains the device id of current indexing apparatus by a query facility ID function;
ID judging unit 340, for judging that whether the device id of the current indexing apparatus obtaining is identical with the device id of described target USB device;
Connectivity port acquiring unit 350, for when the device id of the current indexing apparatus obtaining is identical with the device id of described target USB device, the facility information data of returning from the 3rd parameter of described inquiry designated equipment information function, obtain the device id of target USB device.
In sum, the present invention registers a message and catches window in system, to catch the equipment of USB device while inserting, change message, then from this equipment, change message and obtained device id information, finally by creating a query handler, find facility information data corresponding to USB device, thereby obtained the port information of USB device, method of the present invention is owing to only need calling SDK function, and without calling DDK function, so implementation procedure is simple, reduced technical difficulty, and port identification efficiency of the present invention is high, port is searched conveniently, has stronger practicality.
Should be understood that, application of the present invention is not limited to above-mentioned giving an example, and for those of ordinary skills, can be improved according to the above description or convert, and all these improvement and conversion all should belong to the protection domain of claims of the present invention.