Skip to content

Commit

Permalink
USB handle bug fix for CyAPI.
Browse files Browse the repository at this point in the history
The handle parameter does not take the device handle, but the application's main window (should pass NULL for correct handling).
  • Loading branch information
suramyag1 committed Jun 20, 2017
1 parent daf6e0e commit a23d4b4
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions Voxel/USBIO.cpp
Expand Up @@ -107,24 +107,34 @@ USBIO::USBIOPrivate::USBIOPrivate(DevicePtr device): device(device), handle(0),
return;
}
#elif defined(WINDOWS)
String devicePath = sys.getDeviceNode(d);

if (!devicePath.size())
handle = new CCyUSBDevice();
int numDevices = handle->DeviceCount();
int vid, pid;
wchar_t *serialNumber; //Return type of CCyUSB.SerialNumber is wchar, need to compare it with String
String serialNo, deviceSerialNumber;
int dev = 0;
do
{
logger(LOG_ERROR) << "USBIO: Could not get device path for '" << d.id() << "'" << std::endl;
return;
}

deviceHandle = CreateFile(devicePath.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);

if (deviceHandle == INVALID_HANDLE_VALUE)
handle->Open(dev);
vid = handle->VendorID;
pid = handle->ProductID;
serialNumber = handle->SerialNumber;
std::wstring sno(serialNumber);
String s(sno.begin(), sno.end()); //Converting wide string to string
serialNo = s;
deviceSerialNumber = d.serialNumber();
dev++;
} while((dev<numDevices) && ((vid != d.vendorID()) || (pid != d.productID()) || (serialNo != deviceSerialNumber)));

if (dev > numDevices || (vid != d.vendorID()) || (pid != d.productID()) || (serialNo != deviceSerialNumber))
{
logger(LOG_ERROR) << "USBIO: Failed to open device path '" << devicePath << "' for device '" << d.id() << "'" << std::endl;
return;
logger(LOG_ERROR) << "USBIO: Failed to open device with ID'" << d.id() << "'" << std::endl;
handle->Close();
return;
}

handle = Ptr<CCyUSBDevice>(new CCyUSBDevice(deviceHandle));



if(handle->IsOpen())
{
_initialized = true;
Expand Down Expand Up @@ -300,4 +310,4 @@ USBSystem &USBIO::getUSBSystem()



}
}

0 comments on commit a23d4b4

Please sign in to comment.