marting@thinklogical.com
Member

Posts: 9
|
 |
« on: November 07, 2011, 05:08:25 pm » |
|
Hi, I have the following code - What I want it to do is wait for a usb in packet, and use it. that is pretty clear. I want it to timeout if no data shows up. This wont work because the WaitForSingleObject is called after the clocking ReadFile. Is there a better wqay to do this? Maybe not read file? Of a simpler timeout? I cannot use doevents to run my own time out because the ReadFile is blocking. Thanks, Martin
Security.lpSecurityDescriptor = 0 Security.bInheritHandle = CInt(True) Security.nLength = Len(Security) EventObject = CreateEvent(Security, CInt(False), CInt(True), "rdUsb") HIDOverlapped.Offset = 0 HIDOverlapped.OffsetHigh = 0 HIDOverlapped.hEvent = EventObject 'Do DoEvents RecBuffer(4) = 0 RecBuffer(5) = 0 Result = ReadFile _ (HIDHandle, _ RecBuffer(0), _ CLng(Capabilities.InputReportByteLength), _ rdNum, _ HIDOverlapped)
Result = WaitForSingleObject(EventObject, 500)
Select Case Result Case WAIT_OBJECT_0 ' Success ' Use the report data. rdNum = (RecBuffer(4) + 5) ... .. .
|
|
|
|
|
Logged
|
|
|
|
|
Jan Axelson
|
 |
« Reply #1 on: November 07, 2011, 05:33:19 pm » |
|
Here is the description of WaitForSingleObject:
Waits until the specified object is in the signaled state or the time-out interval elapses.
How is this different from:
I want it to timeout if no data shows up.
Jan
|
|
|
|
|
Logged
|
|
|
|
marting@thinklogical.com
Member

Posts: 9
|
 |
« Reply #2 on: November 08, 2011, 08:04:06 am » |
|
Hi, The readfile is blocking, if no data comes in then the process never gets to WaitForSingleObject
|
|
|
|
|
Logged
|
|
|
|
|
|
marting@thinklogical.com
Member

Posts: 9
|
 |
« Reply #4 on: November 08, 2011, 12:54:12 pm » |
|
I'm sorry, but I am looking in usbhid20.zip I do not see where you set the timeout. I hate to bug you with this, can you please tell me where the timeout is specified? Thanks
|
|
|
|
|
Logged
|
|
|
|
|
|
marting@thinklogical.com
Member

Posts: 9
|
 |
« Reply #6 on: November 09, 2011, 03:07:13 pm » |
|
The readfile was not returning immediately becaue I did a createfile with file_flag_normal instead of fil_flag_overlapped. When you do this the readfile is blocking Because of this the code is never getting to the waitforsingleobject
Such a trivial change causes such a non-trvial outcome
|
|
|
|
|
Logged
|
|
|
|
|
Jan Axelson
|
 |
« Reply #7 on: November 09, 2011, 03:09:53 pm » |
|
Yes, you need to use overlapped IO. I'm glad you got it working.
Jan
|
|
|
|
|
Logged
|
|
|
|
|