Serial Port - overlapped I/O - WaitCommEvent/SetCommMask/ReadFile/etc questions
-
Sorry for reposting this, but I thought I may get some help now that it's the weekend... I have now undertaken rewriting the serial portion of my code to use CreateFile and the like. It's all a bit complicated though, and being new to this, I have a few questions. It starts with overlapping, and also involves WaitCommEvent and GetCommMask. I did a search on the topics and read a few articles that were found, but while they cleared a few things up, they still left me with a few questions unanswered. First, I understand that SetCommMask allows you to screen for only a few of the events. But after calling SetCommMask to look for only what you want, how does one screen for these events and process them appropriately? I know you can use WaitCommEvent, but in that case, why would you even need GetCommMask? I also need to use overlapping for this program, but I'm not sure how to implement it or even what it actually is (do I need to use the overlapped structure at all?). I was able to find this piece of example code on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/monitoring\_communications\_events.asp I do not fully understand how it operates, though. Also, this article was very helpful, to a point: http://www.codeproject.com/system/serial\_com.asp Where I got lost was the huge block of code where he uses the OVERLAPPED structure and the Threadfn function, after which he writes "If you understood the above code , you will understand the whole of this article and the source code provided." Gulp. Basically, I have trouble understanding what he does there and where that overlapped structure comes into play. As always, the help is very much appreciated.
-
Sorry for reposting this, but I thought I may get some help now that it's the weekend... I have now undertaken rewriting the serial portion of my code to use CreateFile and the like. It's all a bit complicated though, and being new to this, I have a few questions. It starts with overlapping, and also involves WaitCommEvent and GetCommMask. I did a search on the topics and read a few articles that were found, but while they cleared a few things up, they still left me with a few questions unanswered. First, I understand that SetCommMask allows you to screen for only a few of the events. But after calling SetCommMask to look for only what you want, how does one screen for these events and process them appropriately? I know you can use WaitCommEvent, but in that case, why would you even need GetCommMask? I also need to use overlapping for this program, but I'm not sure how to implement it or even what it actually is (do I need to use the overlapped structure at all?). I was able to find this piece of example code on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/monitoring\_communications\_events.asp I do not fully understand how it operates, though. Also, this article was very helpful, to a point: http://www.codeproject.com/system/serial\_com.asp Where I got lost was the huge block of code where he uses the OVERLAPPED structure and the Threadfn function, after which he writes "If you understood the above code , you will understand the whole of this article and the source code provided." Gulp. Basically, I have trouble understanding what he does there and where that overlapped structure comes into play. As always, the help is very much appreciated.
Why do you think you need to use overlapped IO? IMO it only makes sense to consider overlapped IO with serial ports if you plan to operate multiple ports on a single thread. What sort of protocol are you implementing? Paul