EvtChar and overlapped Readfile(serialport....
-
Hello, I'm trying to use serial port in asynchronous mode,using overlapped structures and event handlers. Function ReadFile(porthandle,buffer, BytesToReceive....) signals waiting thread ,when received bytes counts to "BytesToReceive. Ok. But i dont know how many bytes will come. One solution is to set BytesToReceive=1. Its not elegant. Other way is to use timeouts. Then ReadFile signals to waiting thread. Other -3th- way is to use EvtChar, in my case i know every received packet ends with known character. I settled event structures and received notification on EV_RXLAG . But how to handle properly? When this event happens, there are ,let say 10 received bytes, but ReadFile is called with BytesToreceive=100. I didnt find explanation how to cancel ReadFile and get these 10 bytes. Any help is welcome!
-
Hello, I'm trying to use serial port in asynchronous mode,using overlapped structures and event handlers. Function ReadFile(porthandle,buffer, BytesToReceive....) signals waiting thread ,when received bytes counts to "BytesToReceive. Ok. But i dont know how many bytes will come. One solution is to set BytesToReceive=1. Its not elegant. Other way is to use timeouts. Then ReadFile signals to waiting thread. Other -3th- way is to use EvtChar, in my case i know every received packet ends with known character. I settled event structures and received notification on EV_RXLAG . But how to handle properly? When this event happens, there are ,let say 10 received bytes, but ReadFile is called with BytesToreceive=100. I didnt find explanation how to cancel ReadFile and get these 10 bytes. Any help is welcome!
You should use the default value of 1 so that you get signalled on every byte received. You then transfer each byte to some data buffer which you later process when you have received a minimum number of bytes or when you are able to recognise that a complete message has been received.
-
You should use the default value of 1 so that you get signalled on every byte received. You then transfer each byte to some data buffer which you later process when you have received a minimum number of bytes or when you are able to recognise that a complete message has been received.
Richard, thank You for post! I understand this method, but it seems to me non-elegant. My question was a little different.
-
Richard, thank You for post! I understand this method, but it seems to me non-elegant. My question was a little different.