|
-
December 27th, 2003, 11:30 AM
#1
Exit ReadCom after 5 sec.
In my application the program writes to a device through RS232 and then waits for an answer. If a correct answer has not arrived after 5 seconds the application should do a new write. Non overlapped communication is used. The function that does the reading is named ReadCom. WaitForSingleObject wants a handle as first argument. How can I create a handle that is related to the ReadCom function?
Or is there any other solution than using WaitForSingleObject?
-
December 29th, 2003, 09:31 AM
#2
I am not sure you can use WaitForSingleObject if you are using non overlapped serial communication.
If you use Overlapped communication, you can do something like,
Code:
OVERLAPPED osEvent= {0};
osEvent.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
SetCommMask (commhandle, EV_RXFLAG);
WaitCommEvent (commhandle, &dwCommEvent, &osStatus);
DWORD dwRet = ::WaitForSingleObject (osStatus.hEvent, iTimeout);
You can check the dwRet value to decide what to do. If timeout, then resend your command.
On the other hand, if you are not using overlapped communication, you may be able to use SetCommTimeouts to set a timeout to your Read function.
Hope this helps but I definitely prefer using overlapped communication because it is so much more robust.
Good luck .
Hujan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|