Timeouts in a thread?
Timeouts in a thread?
(OP)
Hi All,
I have a borland c++ builder application where I am lauching a thread to manage USB HID communications with an external device. I want to wait a specified amount of time at a point within this thread for the device to be attached. Is there an easy way of setting up a timeout to do this? I could have a for loop with a counter and use Sleep() routine but not sure if this is the best way of doing it.
I apologize in advance for the lack of information but not really sure what extra info to provide. Please ask if neccessary.
I have a borland c++ builder application where I am lauching a thread to manage USB HID communications with an external device. I want to wait a specified amount of time at a point within this thread for the device to be attached. Is there an easy way of setting up a timeout to do this? I could have a for loop with a counter and use Sleep() routine but not sure if this is the best way of doing it.
I apologize in advance for the lack of information but not really sure what extra info to provide. Please ask if neccessary.
RE: Timeouts in a thread?
For more advanced HID programming stuff look at
http://www.lvr.com/hidpage.htm
RE: Timeouts in a thread?
RE: Timeouts in a thread?
The particular part in the code is attempting to put the USB HID device into a boot loader mode by sending a USB command. Once the device receives this command I know it will disconnect and reconnect from the USB as it enters the bootloader mode. I have a rough idea of how long this will take (something in the order of 300ms). I have registered for device events in my application so I know when a USB device is attached/detached so what I want is a loop that continuously poles a flag for the device to be attached for a maximum time of (say 500ms).
I think the easiest way would be to do something like this:
CODE --> c++
Not sure how long do get the thread to sleep for between checking the DeviceAttached flag though. I think 10ms should be fine.