Cancelation of WriteFile WINAPI
-
Hi I'm using the WriteFile and ReadFile WINAPI to write/read from a COM port periodically. The protocol is : first wirte to a port and then read the response from a port (=device). The write operation occures every 50 msec at least. Every second attempt to call WriteFile fails and GetLastError returns ERROR_OPERATION_ABORTED. Then I use PurgeComm to clean a port after the failure. The next call to WriteFile succeedes, ReadFile succeedes, and the next try to write is cancelled and so on. Does anybody know what can cause this error? Thanks :(( Natalie
-
Hi I'm using the WriteFile and ReadFile WINAPI to write/read from a COM port periodically. The protocol is : first wirte to a port and then read the response from a port (=device). The write operation occures every 50 msec at least. Every second attempt to call WriteFile fails and GetLastError returns ERROR_OPERATION_ABORTED. Then I use PurgeComm to clean a port after the failure. The next call to WriteFile succeedes, ReadFile succeedes, and the next try to write is cancelled and so on. Does anybody know what can cause this error? Thanks :(( Natalie
I don't have a direct answer as to the cause, but you might want to look into overlapped IO in a situation like this - creating a file with FILE_FLAG_OVERLAPPED allows simultaneous reads and writes, and gives you a more windows like async type of operation. Takes a little more work to set up - there's good stuff on codeproject to help - (pj naughter's class may use this approach, or both - not sure) - but once you get it going its nice - polling is soooo passe... And don't be scared by the docs - overlapped io is available for COM devices on win9x. Just a thought. :)