Respond to ReadEvent on Serial Port
Hi,
I have found many source codes all over the network about how to access the serial port in Delphi. Everybody uses handles with CreateFile (COMx,......) etc, then uses ReadFile, WriteFile. When it comes to receiving characters, almost everybody uses SetCommMask to set for EV_RXCHAR event, then uses WaitCommEvent to respond to this particular event and read the buffer.
But does it mean that I must use some kind of a loop and wait for the event, thus risking to stay in a loop forever and don't do anything else useful? How can I solve this problem more elegantly, like having an event handler for my COMx handle to respond to? I know that one can write an EventHandle for an object, but an event handler for a virtual file handler referring to COMx ??
I would like to stress that I don't want to use some third party components. This solution with having a handle to COMx and making different system calls like GetCommState, WaitCommEvent etc. seems really nice, but how to respond to the incoming characters immediately and empty the input buffer ??? And still not being in a loop and waiting for event, which might not happen at all or occur once in several minutes or so.
Thank you in advance.
I have found many source codes all over the network about how to access the serial port in Delphi. Everybody uses handles with CreateFile (COMx,......) etc, then uses ReadFile, WriteFile. When it comes to receiving characters, almost everybody uses SetCommMask to set for EV_RXCHAR event, then uses WaitCommEvent to respond to this particular event and read the buffer.
But does it mean that I must use some kind of a loop and wait for the event, thus risking to stay in a loop forever and don't do anything else useful? How can I solve this problem more elegantly, like having an event handler for my COMx handle to respond to? I know that one can write an EventHandle for an object, but an event handler for a virtual file handler referring to COMx ??
I would like to stress that I don't want to use some third party components. This solution with having a handle to COMx and making different system calls like GetCommState, WaitCommEvent etc. seems really nice, but how to respond to the incoming characters immediately and empty the input buffer ??? And still not being in a loop and waiting for event, which might not happen at all or occur once in several minutes or so.
Thank you in advance.