Looking to determing possible causes of error 2 - Can't open SUB device
Posted: Fri Dec 22, 2023 3:26 am
Hi all,
Wondering if anyone can tell me all of the conditions that would trigger the DLL to report an error 2 - Can't open SUB device.
Some background: I'm developing some code that runs two threads - one thread polls connected devices checking to see if a device has been connected/disconnected and the other thread handles requests for operations on a specific device. Thread #1 runs sub_find_devices every 500ms collecting device references and compares that with the previous device references. If a new device is discovered, it's opened and made available to thread #2. If a device has been removed, it's closed & disposed and no longer available to thread #2.
I've seen some interesting behavior when my Windows PC is left alone and begins to enter power save mode. sub_find_devices begins to return new, random device references for device(s) that have remained physically connected. I'm assuming it has something to do with the USB being put into low/no-power mode. Since my code would see that as a "new" device, it would try to open it and of course fail with an error 2 since it's already open under the original device reference. My challenge is the only way I know of to tell that it really IS an already-connected device is to check it's serial number against open devices' serial number, which requires me to open...you can see my Catch-22.
So my latest theory is that if I try to open it and it fails with an error 2, perhaps I can assume that it's already open and can ignore this "new" device reference. But to do that I need to know whether this is the only condition that triggers an error 2. Since I don't know how the DLL is written, I'm wondering if someone who was involved in writing it can tell me.
Advice on alternatives is welcome, but can't be to disable power save mode in settings on the PC or in some other way force power save mode off while the program is running, etc. - I've already considered that but because this software will go to customers that would be a big red flag. I'm looking for a way to gracefully handle the situation.
Thank you!
John
Wondering if anyone can tell me all of the conditions that would trigger the DLL to report an error 2 - Can't open SUB device.
Some background: I'm developing some code that runs two threads - one thread polls connected devices checking to see if a device has been connected/disconnected and the other thread handles requests for operations on a specific device. Thread #1 runs sub_find_devices every 500ms collecting device references and compares that with the previous device references. If a new device is discovered, it's opened and made available to thread #2. If a device has been removed, it's closed & disposed and no longer available to thread #2.
I've seen some interesting behavior when my Windows PC is left alone and begins to enter power save mode. sub_find_devices begins to return new, random device references for device(s) that have remained physically connected. I'm assuming it has something to do with the USB being put into low/no-power mode. Since my code would see that as a "new" device, it would try to open it and of course fail with an error 2 since it's already open under the original device reference. My challenge is the only way I know of to tell that it really IS an already-connected device is to check it's serial number against open devices' serial number, which requires me to open...you can see my Catch-22.
So my latest theory is that if I try to open it and it fails with an error 2, perhaps I can assume that it's already open and can ignore this "new" device reference. But to do that I need to know whether this is the only condition that triggers an error 2. Since I don't know how the DLL is written, I'm wondering if someone who was involved in writing it can tell me.
Advice on alternatives is welcome, but can't be to disable power save mode in settings on the PC or in some other way force power save mode off while the program is running, etc. - I've already considered that but because this software will go to customers that would be a big red flag. I'm looking for a way to gracefully handle the situation.
Thank you!
John