void DVS128Interface::startReading(){
    CUsbIo dev;
    USB_DEVICE_DESCRIPTOR devDesc;
    DWORD status;
    bool found = false;

    devList = CUsbIo::CreateDeviceList(&usbIoID);
    if (devList == NULL){
        printf("Unable to build a device list!\n");
    }

    // Open and query usb devices to find the right one
    for (int i = 0; i < 127; i++){
        status = dev.Open(i,devList,&usbIoID);
        if ( status != USBIO_ERR_SUCCESS ) {
            if ( status != USBIO_ERR_NO_SUCH_DEVICE_INSTANCE ){
                fprintf(stdout,"UsbDev.Open returned with error 0x%08X\n",status);
            }
            break;
        }
        // Query device descriptor for comparison with PID and VID
        status = dev.GetDeviceDescriptor(&devDesc);
        if ( status == USBIO_ERR_SUCCESS ){
            found = true;
            if ( devDesc.iSerialNumber!=0 ){
                dev.Close();
                if (devDesc.idVendor == VID && devDesc.idProduct == PID){
                    fprintf(stdout,"Device found, starting reader.\n");
                    devIndex = i;
                    startReaderThread(devIndex);
                    break;
                } else {
                    fprintf(stdout,"Device not recognized\n");
                }
            } else {
                fprintf(stdout,"Querying device descriptor failed, status:0x%08X\n",status);
                dev.Close();
            }
        }

        if ( !found ) {
            fprintf(stdout,"There are no USB devices attached to the USBIO driver.\n");
        }
        else
            fprintf(stdout,"Device found...");
        CUsbIo::DestroyDeviceList(devList);
    }
}
Beispiel #2
0
static void GetDeviceDescriptor()
	{
	USB_DEVICE_DESCRIPTOR DeviceDescriptor;

	memset(&DeviceDescriptor, 0, sizeof(USB_DEVICE_DESCRIPTOR));

	// Get device descriptor
	dwRC = g_UsbDev.GetDeviceDescriptor(&DeviceDescriptor);
	PRINT_IF_VERBOSE1("CUsbIo::GetDeviceDescriptor returned <0x%X>\n", dwRC);

	if (VerboseMode && (dwRC == USBIO_ERR_SUCCESS))
		{
		printf("\nDEVICE DESCRIPTOR:\n"
			   "bLength = <%u>\n"
			   "bDescriptorType = <%u>\n"
			   "bcdUSB = <%u>\n"
			   "bDeviceClass = <%u>\n"
			   "bDeviceSubClass = <%u>\n"
			   "bDeviceProtocol = <%u>\n"
			   "bMaxPacketSize0 = <%u>\n"
			   "idVendor = <%u>\n"
			   "idProduct = <%u>\n"
			   "bcdDevice = <%u>\n"
			   "iManufacturer = <%u>\n"
			   "iProduct = <%u>\n"
			   "iSerialNumber = <%u>\n"
			   "bNumConfigurations = <%u>\n\n",
			   DeviceDescriptor.bLength,
			   DeviceDescriptor.bDescriptorType,
			   DeviceDescriptor.bcdUSB,
			   DeviceDescriptor.bDeviceClass,
			   DeviceDescriptor.bDeviceSubClass,
			   DeviceDescriptor.bDeviceProtocol,
			   DeviceDescriptor.bMaxPacketSize0,
			   DeviceDescriptor.idVendor,
			   DeviceDescriptor.idProduct,
			   DeviceDescriptor.bcdDevice,
			   DeviceDescriptor.iManufacturer,
			   DeviceDescriptor.iProduct,
			   DeviceDescriptor.iSerialNumber,
			   DeviceDescriptor.bNumConfigurations);
		}
	}