Both CyAPI and CyUSB.dll open handle in a similar manner so the device handle numbering should be the same. You'll have to keep in mind the scenario of device removal while you're triggering the C++ app. The numbering might change based on the device removed so having a way of distinguishing from the firmware (like unique serial number) is a good idea.
USBAddress should come in handy since it is the bus address (will be same in both CyAPI and CyUSB) and is not bound to change based on device removal. There might a issue if the device you're addressing is removed and a new device plugged in at very quick succession and the host sets the bus address to the new device.
So the C++ application will need to iterate over all devices to find the relevant device. Are there any issues with calling Open on a device that might be in use by another process?
e.g. My C++ code would be something like:
UCHAR FindCyDevice(UCHAR usbAddress, bool& deviceFound)
CCyUSBDevice* usbDevice = new CCyUSBDevice(NULL);
// iterate over all devices to find the matching USB address
deviceFound = false;
UCHAR deviceCount = usbDevice->DeviceCount();
for (UCHAR deviceNum = 0; deviceNum < deviceCount; ++deviceNum)
if (usbDevice->Open(deviceNum) && usbDevice->USBAddress == usbAddress)
deviceFound = true;
So will Open() return false if the device is open in another process? This isn't clear to me from reading the documentation.
Nope. It will open a handle.
In the same application you should be able to check whether a handle is already open using the function IsOpen().
Opening a handle enumerates the device again to get the descriptors and build the descriptor structure. So as long as you don't interrupt the other process working by sending a transfer or doing other operations (since the other process won't know the things triggered by this process) that could affect the working of the other process, it should be fine.
So from your description as long as the processes don't modify a shared data structure or initiate any USB transfer then I should be fine.
This means that querying the USB address or serial number (if it can be unique) from multiple processes should be fine. I just need to be more careful with closing handles in the C++ version of the code.
I'll give this a go and let you know if I have any issues.