| 943 | } |
| 944 | |
| 945 | hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number) |
| 946 | { |
| 947 | struct hid_device_info *devs, *cur_dev; |
| 948 | const char *path_to_open = NULL; |
| 949 | hid_device *handle = NULL; |
| 950 | |
| 951 | /* register_global_error: global error is reset by hid_enumerate/hid_init */ |
| 952 | devs = hid_enumerate(vendor_id, product_id); |
| 953 | if (devs == NULL) { |
| 954 | /* register_global_error: global error is already set by hid_enumerate */ |
| 955 | return NULL; |
| 956 | } |
| 957 | |
| 958 | cur_dev = devs; |
| 959 | while (cur_dev) { |
| 960 | if (cur_dev->vendor_id == vendor_id && |
| 961 | cur_dev->product_id == product_id) { |
| 962 | if (serial_number) { |
| 963 | if (wcscmp(serial_number, cur_dev->serial_number) == 0) { |
| 964 | path_to_open = cur_dev->path; |
| 965 | break; |
| 966 | } |
| 967 | } |
| 968 | else { |
| 969 | path_to_open = cur_dev->path; |
| 970 | break; |
| 971 | } |
| 972 | } |
| 973 | cur_dev = cur_dev->next; |
| 974 | } |
| 975 | |
| 976 | if (path_to_open) { |
| 977 | /* Open the device */ |
| 978 | handle = hid_open_path(path_to_open); |
| 979 | } else { |
| 980 | register_global_error("Device with requested VID/PID/(SerialNumber) not found"); |
| 981 | } |
| 982 | |
| 983 | hid_free_enumeration(devs); |
| 984 | |
| 985 | return handle; |
| 986 | } |
| 987 | |
| 988 | hid_device * HID_API_EXPORT hid_open_path(const char *path) |
| 989 | { |