delphi - Resetting comm event mask -


I recently overlap serial port communications in Delphi and I have a problem, I'm not sure how to solve To do. / P>

I communicate with a modem I write a request frame (AT command) in the COM port of the modem and then wait for the modem to respond. The port's event mask is set to EV_RXCHAR, so when I write a request, I call WaitCommEvent () and wait for the data to appear in the input queue. When the event is awaiting to finish, I immediately start reading data from the queue and reads all that the device sends at one time:

1) Write a request
2) WaitCommEvent () Call and Wait Waiting
3) Read all the data that the device sends (Not only the data is in the input queue at that time)
4) Do something and then geto 1.

Waiting for the event to end after the first byte is visible in the input queue. During my reading work, however, more bytes appear in queue and each one has to set an internal event flag. This means that when I read all data from the queue and call WaitCommEvent () for the second time, it will return immediately with the EV_RXCHAR mask, even if no data is read.

How do I handle reading and waiting for the event to ensure that the Events Mask is always valid by WaitCommEvent ()? Is it possible to reset the flag of the serial port, so that when I read all the data from the queue and then call the wait coment (), then it will not return immediately with a mask before reading this data?

The only solution that comes to my mind is:

1) Write a request
2) Call the WaitingCommunity () and wait for the wait to finish
4) Call WaitCommEvent () which should immediately return the event set immediately on the internal set set the flag
5) Do something and geto 1

Is this a good idea or stupid? Of course I know that the modem almost always completes its answers with the CRLF characters, so I can set the com mask to EV_RXFALG and wait for the # 10 character to come, but there are many other devices I communicate with And they do not always send the letters of the end of the frame.

Your help will be appreciated. thank you in advanced!

Marijucius.

Your solution is voice-playable. I use a state machine to handle the infection.

(psuedocode)

  ioState: = ioIdle; Iostate (ioState & lt; & gt; ioFinished) and (not canceled) IOItle case: If there is data to read, set the position to ioMidFrame ioMidframe: If the data is read to read, then the end of the frame Set on IioEndFrame IioEndFrame: Process Data and IoFinished set on IoFinished: // nothing, only ends for doctor purposes;  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -