[C++] How can I predict the order of CCyUSBDevice list?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
GiVa_292201
Level 1
Level 1

Dear all,

I have more FX3 conncted to the same machine and I need to connect to a specific one.

Normally, to look for a specific device by its serial number, I would do something like this:

CCyUSBDevice device;

const unsigned char num_of_devices = device.DeviceCount();

for (unsigned char i = 0; i < num_of_devices; i++)

{

    device.Open(i);

    if (check(device.SerialNumber))

        break;

    device.Close();

}

// Do something with the device

device.Close()

However, in my case I cannot sequentially open all the connected devices. I need to query WMI database, get a list of all CYUSB3 connected devices and then open a specific one. My problem is that the order of the CYUSB3 devices that I get from WMI database is different from the Cypress driver order.

Is there a way to predict how the Cypress driver (or library) will enumerate my devices (e.g. order by serial, PID, description...) in order to avoid a sequential device scan?

Thank you,
Gianni

0 Likes
1 Solution
YatheeshD_36
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hello Gianni,

Please use the function defined in this KBA: Accessing Multiple USB-Serial Devices using the Device Instance Path – KBA228257

1. You can assign a serial number to each FX3 Device as mentioned in this KBA: Distinguishing Different FX3 Devices with Same VID/PID on Host Application – KBA225775

2. Get the number of FX3 devices connected using the  DeviceCount( ) API.

3. Iterate through the all of the connected FX3 devices and retrieve the instance path using the function GetDevicePath(int deviceNumber) mentioned in this KBA: Accessing Multiple USB-Serial Devices using the Device Instance Path – KBA228257

4. Extract the serial number part from the instance path string.

5. if the serial number matches, you can use the device number to open the respective device using the Open() function.

Please let me know if you have any queries regarding implementing the above?

Thanks,

Yatheesh

View solution in original post

2 Replies
YatheeshD_36
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hello Gianni,

Please use the function defined in this KBA: Accessing Multiple USB-Serial Devices using the Device Instance Path – KBA228257

1. You can assign a serial number to each FX3 Device as mentioned in this KBA: Distinguishing Different FX3 Devices with Same VID/PID on Host Application – KBA225775

2. Get the number of FX3 devices connected using the  DeviceCount( ) API.

3. Iterate through the all of the connected FX3 devices and retrieve the instance path using the function GetDevicePath(int deviceNumber) mentioned in this KBA: Accessing Multiple USB-Serial Devices using the Device Instance Path – KBA228257

4. Extract the serial number part from the instance path string.

5. if the serial number matches, you can use the device number to open the respective device using the Open() function.

Please let me know if you have any queries regarding implementing the above?

Thanks,

Yatheesh

Hello YatheeshK_36​,

Thank you very much for your reply, it was very useful. I was able to retrieve all the device information using the functions of the setupapi library that I found in the first link.

Regards,
Gianni

0 Likes