How respond quickly on serial port? 
Author Message
 How respond quickly on serial port?

Hi!

I'm developing for Windows CE on a PC-104 platform.
My problem is the following:
I need to respond to the incoming data quicker than 5ms since the last
character has been received but WaitCommEvent doesn't return until 5 ms
after the data has been received so that is very difficult. I don't know why
it takes such a long time for WaitCommEvent to respond (The FIFO buffers? I
can't access the settings for them, and SetupComm doesn't seem to have any
effect).

Any hint on have to make this better? My application works now since I can
respond on exactly 5 ms, but I'd like to have some margin to the
specifications of the hardware I'm communicating with.

// J



Mon, 30 May 2005 03:03:28 GMT  
 How respond quickly on serial port?
Hi,

WaitCommEvent() doesn't wait 5ms before returning an indication of a
character being received, in general.  How are you arriving at that figure?

Paul T.


Quote:
> Hi!

> I'm developing for Windows CE on a PC-104 platform.
> My problem is the following:
> I need to respond to the incoming data quicker than 5ms since the last
> character has been received but WaitCommEvent doesn't return until 5 ms
> after the data has been received so that is very difficult. I don't know
why
> it takes such a long time for WaitCommEvent to respond (The FIFO buffers?
I
> can't access the settings for them, and SetupComm doesn't seem to have any
> effect).

> Any hint on have to make this better? My application works now since I can
> respond on exactly 5 ms, but I'd like to have some margin to the
> specifications of the hardware I'm communicating with.

> // J



Mon, 30 May 2005 03:28:41 GMT  
 How respond quickly on serial port?
I'm responding immediately by sending a character back on the serial port
when I receive the incoming data, and when measuring on the serial port with
an oscilloscope I see that the response starts sending about 5.1ms after the
end of the incoming data. Of course, there is the possibility that the delay
is in the output, (i.e. the output is buffered for a while before it is
sent) but it doesn't seem that way.

// J



Quote:
> Hi,

> WaitCommEvent() doesn't wait 5ms before returning an indication of a
> character being received, in general.  How are you arriving at that
figure?

> Paul T.



> > Hi!

> > I'm developing for Windows CE on a PC-104 platform.
> > My problem is the following:
> > I need to respond to the incoming data quicker than 5ms since the last
> > character has been received but WaitCommEvent doesn't return until 5 ms
> > after the data has been received so that is very difficult. I don't know
> why
> > it takes such a long time for WaitCommEvent to respond (The FIFO
buffers?
> I
> > can't access the settings for them, and SetupComm doesn't seem to have
any
> > effect).

> > Any hint on have to make this better? My application works now since I
can
> > respond on exactly 5 ms, but I'd like to have some margin to the
> > specifications of the hardware I'm communicating with.

> > // J



Mon, 30 May 2005 04:05:42 GMT  
 How respond quickly on serial port?
Right, so what you've measured is the time to respond to the interrupt for
the character arrival, the wake up of the thread which calls
WaitCommEvent(), the time it takes to call ReadFile() to read the character,
and the time to call WriteFile() to send the response?  If so, the
ReadFile() might be responsible, since the serial port can be set up for
time-outs and ReadFile() will use those parameters regardless of whether
there are already characters present or not.

Paul T.


Quote:
> I'm responding immediately by sending a character back on the serial port
> when I receive the incoming data, and when measuring on the serial port
with
> an oscilloscope I see that the response starts sending about 5.1ms after
the
> end of the incoming data. Of course, there is the possibility that the
delay
> is in the output, (i.e. the output is buffered for a while before it is
> sent) but it doesn't seem that way.

> // J



> > Hi,

> > WaitCommEvent() doesn't wait 5ms before returning an indication of a
> > character being received, in general.  How are you arriving at that
> figure?

> > Paul T.



> > > Hi!

> > > I'm developing for Windows CE on a PC-104 platform.
> > > My problem is the following:
> > > I need to respond to the incoming data quicker than 5ms since the last
> > > character has been received but WaitCommEvent doesn't return until 5
ms
> > > after the data has been received so that is very difficult. I don't
know
> > why
> > > it takes such a long time for WaitCommEvent to respond (The FIFO
> buffers?
> > I
> > > can't access the settings for them, and SetupComm doesn't seem to have
> any
> > > effect).

> > > Any hint on have to make this better? My application works now since I
> can
> > > respond on exactly 5 ms, but I'd like to have some margin to the
> > > specifications of the hardware I'm communicating with.

> > > // J



Mon, 30 May 2005 05:29:19 GMT  
 How respond quickly on serial port?
Aha!
I checked the documentation and you are right, there is a time out value to
wait for more characters to arrive when doing the read.
This will probably do it.
I'll try it later this week.

Thanks!

// J



Quote:
> Right, so what you've measured is the time to respond to the interrupt for
> the character arrival, the wake up of the thread which calls
> WaitCommEvent(), the time it takes to call ReadFile() to read the
character,
> and the time to call WriteFile() to send the response?  If so, the
> ReadFile() might be responsible, since the serial port can be set up for
> time-outs and ReadFile() will use those parameters regardless of whether
> there are already characters present or not.

> Paul T.



> > I'm responding immediately by sending a character back on the serial
port
> > when I receive the incoming data, and when measuring on the serial port
> with
> > an oscilloscope I see that the response starts sending about 5.1ms after
> the
> > end of the incoming data. Of course, there is the possibility that the
> delay
> > is in the output, (i.e. the output is buffered for a while before it is
> > sent) but it doesn't seem that way.

> > // J


meddelandet

> > > Hi,

> > > WaitCommEvent() doesn't wait 5ms before returning an indication of a
> > > character being received, in general.  How are you arriving at that
> > figure?

> > > Paul T.



> > > > Hi!

> > > > I'm developing for Windows CE on a PC-104 platform.
> > > > My problem is the following:
> > > > I need to respond to the incoming data quicker than 5ms since the
last
> > > > character has been received but WaitCommEvent doesn't return until 5
> ms
> > > > after the data has been received so that is very difficult. I don't
> know
> > > why
> > > > it takes such a long time for WaitCommEvent to respond (The FIFO
> > buffers?
> > > I
> > > > can't access the settings for them, and SetupComm doesn't seem to
have
> > any
> > > > effect).

> > > > Any hint on have to make this better? My application works now since
I
> > can
> > > > respond on exactly 5 ms, but I'd like to have some margin to the
> > > > specifications of the hardware I'm communicating with.

> > > > // J



Mon, 30 May 2005 06:00:08 GMT  
 How respond quickly on serial port?
Unfortunately, this was not the problem. I already had the following code in
the initialization part of the port:

  // Retrieve the time-out parameters for all read and write operations
  // on the port.
  GetCommTimeouts (hPort_, &CommTimeouts);

  // Change the COMMTIMEOUTS structure settings.
  CommTimeouts.ReadIntervalTimeout = MAXDWORD;
  CommTimeouts.ReadTotalTimeoutMultiplier = 0;
  CommTimeouts.ReadTotalTimeoutConstant = 0;
  CommTimeouts.WriteTotalTimeoutMultiplier = 10;
  CommTimeouts.WriteTotalTimeoutConstant = 1000;

  // Set the time-out parameters for all read and write operations
  // on the port.
  if (!SetCommTimeouts (hPort_, &CommTimeouts))
  {
    // Could not create the read thread.
 error("Unable to set the time-out parameters");
    // dwError = GetLastError ();
  }

// J



Quote:
> Right, so what you've measured is the time to respond to the interrupt for
> the character arrival, the wake up of the thread which calls
> WaitCommEvent(), the time it takes to call ReadFile() to read the
character,
> and the time to call WriteFile() to send the response?  If so, the
> ReadFile() might be responsible, since the serial port can be set up for
> time-outs and ReadFile() will use those parameters regardless of whether
> there are already characters present or not.

> Paul T.



> > I'm responding immediately by sending a character back on the serial
port
> > when I receive the incoming data, and when measuring on the serial port
> with
> > an oscilloscope I see that the response starts sending about 5.1ms after
> the
> > end of the incoming data. Of course, there is the possibility that the
> delay
> > is in the output, (i.e. the output is buffered for a while before it is
> > sent) but it doesn't seem that way.

> > // J


meddelandet

> > > Hi,

> > > WaitCommEvent() doesn't wait 5ms before returning an indication of a
> > > character being received, in general.  How are you arriving at that
> > figure?

> > > Paul T.



> > > > Hi!

> > > > I'm developing for Windows CE on a PC-104 platform.
> > > > My problem is the following:
> > > > I need to respond to the incoming data quicker than 5ms since the
last
> > > > character has been received but WaitCommEvent doesn't return until 5
> ms
> > > > after the data has been received so that is very difficult. I don't
> know
> > > why
> > > > it takes such a long time for WaitCommEvent to respond (The FIFO
> > buffers?
> > > I
> > > > can't access the settings for them, and SetupComm doesn't seem to
have
> > any
> > > > effect).

> > > > Any hint on have to make this better? My application works now since
I
> > can
> > > > respond on exactly 5 ms, but I'd like to have some margin to the
> > > > specifications of the hardware I'm communicating with.

> > > > // J



Tue, 31 May 2005 00:25:37 GMT  
 How respond quickly on serial port?
Why would you set the interval time-out to MAXDWORD?  If you don't want
interval time-outs, set it to zero.  I think that this section of the help
might help you:

If an application sets ReadIntervalTimeout and ReadTotalTimeoutMultiplier to
MAXDWORD and sets ReadTotalTimeoutConstant to a value greater than zero and
less than MAXDWORD, one of the following occurs when the ReadFile function
is called:
  a.. If there are any characters in the input buffer, ReadFile returns
immediately with the characters in the buffer.
  b.. If there are no characters in the input buffer, ReadFile waits until a
character arrives and then returns immediately.
  c.. If no characters arrive within the time specified by
ReadTotalTimeoutConstant, ReadFile times out.
Paul T.


Quote:
> Unfortunately, this was not the problem. I already had the following code
in
> the initialization part of the port:

>   // Retrieve the time-out parameters for all read and write operations
>   // on the port.
>   GetCommTimeouts (hPort_, &CommTimeouts);

>   // Change the COMMTIMEOUTS structure settings.
>   CommTimeouts.ReadIntervalTimeout = MAXDWORD;
>   CommTimeouts.ReadTotalTimeoutMultiplier = 0;
>   CommTimeouts.ReadTotalTimeoutConstant = 0;
>   CommTimeouts.WriteTotalTimeoutMultiplier = 10;
>   CommTimeouts.WriteTotalTimeoutConstant = 1000;

>   // Set the time-out parameters for all read and write operations
>   // on the port.
>   if (!SetCommTimeouts (hPort_, &CommTimeouts))
>   {
>     // Could not create the read thread.
>  error("Unable to set the time-out parameters");
>     // dwError = GetLastError ();
>   }

> // J



> > Right, so what you've measured is the time to respond to the interrupt
for
> > the character arrival, the wake up of the thread which calls
> > WaitCommEvent(), the time it takes to call ReadFile() to read the
> character,
> > and the time to call WriteFile() to send the response?  If so, the
> > ReadFile() might be responsible, since the serial port can be set up for
> > time-outs and ReadFile() will use those parameters regardless of whether
> > there are already characters present or not.

> > Paul T.



> > > I'm responding immediately by sending a character back on the serial
> port
> > > when I receive the incoming data, and when measuring on the serial
port
> > with
> > > an oscilloscope I see that the response starts sending about 5.1ms
after
> > the
> > > end of the incoming data. Of course, there is the possibility that the
> > delay
> > > is in the output, (i.e. the output is buffered for a while before it
is
> > > sent) but it doesn't seem that way.

> > > // J


> meddelandet

> > > > Hi,

> > > > WaitCommEvent() doesn't wait 5ms before returning an indication of a
> > > > character being received, in general.  How are you arriving at that
> > > figure?

> > > > Paul T.



> > > > > Hi!

> > > > > I'm developing for Windows CE on a PC-104 platform.
> > > > > My problem is the following:
> > > > > I need to respond to the incoming data quicker than 5ms since the
> last
> > > > > character has been received but WaitCommEvent doesn't return until
5
> > ms
> > > > > after the data has been received so that is very difficult. I
don't
> > know
> > > > why
> > > > > it takes such a long time for WaitCommEvent to respond (The FIFO
> > > buffers?
> > > > I
> > > > > can't access the settings for them, and SetupComm doesn't seem to
> have
> > > any
> > > > > effect).

> > > > > Any hint on have to make this better? My application works now
since
> I
> > > can
> > > > > respond on exactly 5 ms, but I'd like to have some margin to the
> > > > > specifications of the hardware I'm communicating with.

> > > > > // J



Tue, 31 May 2005 01:06:00 GMT  
 How respond quickly on serial port?
I saw that one, but I also saw this one:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcec...

To assist with multitasking, it is common to configure COMMTIMEOUT so that
ReadFile immediately returns with the characters to be read. To do this, set
ReadIntervalTimeout to MAXWORD and set both ReadTotalTimeoutMultiplier and
ReadTotalTimeoutConstant to zero.

in the sample code supplied with the above comment, they had used MAXDWORD
instead of MAXWORD.

// J



Quote:
> Why would you set the interval time-out to MAXDWORD?  If you don't want
> interval time-outs, set it to zero.  I think that this section of the help
> might help you:

> If an application sets ReadIntervalTimeout and ReadTotalTimeoutMultiplier
to
> MAXDWORD and sets ReadTotalTimeoutConstant to a value greater than zero
and
> less than MAXDWORD, one of the following occurs when the ReadFile function
> is called:
>   a.. If there are any characters in the input buffer, ReadFile returns
> immediately with the characters in the buffer.
>   b.. If there are no characters in the input buffer, ReadFile waits until
a
> character arrives and then returns immediately.
>   c.. If no characters arrive within the time specified by
> ReadTotalTimeoutConstant, ReadFile times out.
> Paul T.



> > Unfortunately, this was not the problem. I already had the following
code
> in
> > the initialization part of the port:

> >   // Retrieve the time-out parameters for all read and write operations
> >   // on the port.
> >   GetCommTimeouts (hPort_, &CommTimeouts);

> >   // Change the COMMTIMEOUTS structure settings.
> >   CommTimeouts.ReadIntervalTimeout = MAXDWORD;
> >   CommTimeouts.ReadTotalTimeoutMultiplier = 0;
> >   CommTimeouts.ReadTotalTimeoutConstant = 0;
> >   CommTimeouts.WriteTotalTimeoutMultiplier = 10;
> >   CommTimeouts.WriteTotalTimeoutConstant = 1000;

> >   // Set the time-out parameters for all read and write operations
> >   // on the port.
> >   if (!SetCommTimeouts (hPort_, &CommTimeouts))
> >   {
> >     // Could not create the read thread.
> >  error("Unable to set the time-out parameters");
> >     // dwError = GetLastError ();
> >   }

> > // J


meddelandet

> > > Right, so what you've measured is the time to respond to the interrupt
> for
> > > the character arrival, the wake up of the thread which calls
> > > WaitCommEvent(), the time it takes to call ReadFile() to read the
> > character,
> > > and the time to call WriteFile() to send the response?  If so, the
> > > ReadFile() might be responsible, since the serial port can be set up
for
> > > time-outs and ReadFile() will use those parameters regardless of
whether
> > > there are already characters present or not.

> > > Paul T.



> > > > I'm responding immediately by sending a character back on the serial
> > port
> > > > when I receive the incoming data, and when measuring on the serial
> port
> > > with
> > > > an oscilloscope I see that the response starts sending about 5.1ms
> after
> > > the
> > > > end of the incoming data. Of course, there is the possibility that
the
> > > delay
> > > > is in the output, (i.e. the output is buffered for a while before it
> is
> > > > sent) but it doesn't seem that way.

> > > > // J


> > meddelandet

> > > > > Hi,

> > > > > WaitCommEvent() doesn't wait 5ms before returning an indication of
a
> > > > > character being received, in general.  How are you arriving at
that
> > > > figure?

> > > > > Paul T.



> > > > > > Hi!

> > > > > > I'm developing for Windows CE on a PC-104 platform.
> > > > > > My problem is the following:
> > > > > > I need to respond to the incoming data quicker than 5ms since
the
> > last
> > > > > > character has been received but WaitCommEvent doesn't return
until
> 5
> > > ms
> > > > > > after the data has been received so that is very difficult. I
> don't
> > > know
> > > > > why
> > > > > > it takes such a long time for WaitCommEvent to respond (The FIFO
> > > > buffers?
> > > > > I
> > > > > > can't access the settings for them, and SetupComm doesn't seem
to
> > have
> > > > any
> > > > > > effect).

> > > > > > Any hint on have to make this better? My application works now
> since
> > I
> > > > can
> > > > > > respond on exactly 5 ms, but I'd like to have some margin to the
> > > > > > specifications of the hardware I'm communicating with.

> > > > > > // J



Tue, 31 May 2005 01:26:22 GMT  
 How respond quickly on serial port?
ReadTotalTimeoutMultiplier should be set to MAXDWORD, based on the driver
source code.  ReadIntervalTimeout should be set to MAXDWORD also, and
ReadTotalTimeout should be set to zero.  This combination results in the
data being returned immediately.

Paul T.


Quote:
> I saw that one, but I also saw this one:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcec...
Quote:
> /_wcesdk_configuring_time_outs.asp

> To assist with multitasking, it is common to configure COMMTIMEOUT so that
> ReadFile immediately returns with the characters to be read. To do this,
set
> ReadIntervalTimeout to MAXWORD and set both ReadTotalTimeoutMultiplier and
> ReadTotalTimeoutConstant to zero.

> in the sample code supplied with the above comment, they had used MAXDWORD
> instead of MAXWORD.

> // J



> > Why would you set the interval time-out to MAXDWORD?  If you don't want
> > interval time-outs, set it to zero.  I think that this section of the
help
> > might help you:

> > If an application sets ReadIntervalTimeout and

ReadTotalTimeoutMultiplier

- Show quoted text -

Quote:
> to
> > MAXDWORD and sets ReadTotalTimeoutConstant to a value greater than zero
> and
> > less than MAXDWORD, one of the following occurs when the ReadFile
function
> > is called:
> >   a.. If there are any characters in the input buffer, ReadFile returns
> > immediately with the characters in the buffer.
> >   b.. If there are no characters in the input buffer, ReadFile waits
until
> a
> > character arrives and then returns immediately.
> >   c.. If no characters arrive within the time specified by
> > ReadTotalTimeoutConstant, ReadFile times out.
> > Paul T.



> > > Unfortunately, this was not the problem. I already had the following
> code
> > in
> > > the initialization part of the port:

> > >   // Retrieve the time-out parameters for all read and write
operations
> > >   // on the port.
> > >   GetCommTimeouts (hPort_, &CommTimeouts);

> > >   // Change the COMMTIMEOUTS structure settings.
> > >   CommTimeouts.ReadIntervalTimeout = MAXDWORD;
> > >   CommTimeouts.ReadTotalTimeoutMultiplier = 0;
> > >   CommTimeouts.ReadTotalTimeoutConstant = 0;
> > >   CommTimeouts.WriteTotalTimeoutMultiplier = 10;
> > >   CommTimeouts.WriteTotalTimeoutConstant = 1000;

> > >   // Set the time-out parameters for all read and write operations
> > >   // on the port.
> > >   if (!SetCommTimeouts (hPort_, &CommTimeouts))
> > >   {
> > >     // Could not create the read thread.
> > >  error("Unable to set the time-out parameters");
> > >     // dwError = GetLastError ();
> > >   }

> > > // J


> meddelandet

> > > > Right, so what you've measured is the time to respond to the
interrupt
> > for
> > > > the character arrival, the wake up of the thread which calls
> > > > WaitCommEvent(), the time it takes to call ReadFile() to read the
> > > character,
> > > > and the time to call WriteFile() to send the response?  If so, the
> > > > ReadFile() might be responsible, since the serial port can be set up
> for
> > > > time-outs and ReadFile() will use those parameters regardless of
> whether
> > > > there are already characters present or not.

> > > > Paul T.



> > > > > I'm responding immediately by sending a character back on the
serial
> > > port
> > > > > when I receive the incoming data, and when measuring on the serial
> > port
> > > > with
> > > > > an oscilloscope I see that the response starts sending about 5.1ms
> > after
> > > > the
> > > > > end of the incoming data. Of course, there is the possibility that
> the
> > > > delay
> > > > > is in the output, (i.e. the output is buffered for a while before
it
> > is
> > > > > sent) but it doesn't seem that way.

> > > > > // J


> > > meddelandet

> > > > > > Hi,

> > > > > > WaitCommEvent() doesn't wait 5ms before returning an indication
of
> a
> > > > > > character being received, in general.  How are you arriving at
> that
> > > > > figure?

> > > > > > Paul T.



> > > > > > > Hi!

> > > > > > > I'm developing for Windows CE on a PC-104 platform.
> > > > > > > My problem is the following:
> > > > > > > I need to respond to the incoming data quicker than 5ms since
> the
> > > last
> > > > > > > character has been received but WaitCommEvent doesn't return
> until
> > 5
> > > > ms
> > > > > > > after the data has been received so that is very difficult. I
> > don't
> > > > know
> > > > > > why
> > > > > > > it takes such a long time for WaitCommEvent to respond (The
FIFO
> > > > > buffers?
> > > > > > I
> > > > > > > can't access the settings for them, and SetupComm doesn't seem
> to
> > > have
> > > > > any
> > > > > > > effect).

> > > > > > > Any hint on have to make this better? My application works now
> > since
> > > I
> > > > > can
> > > > > > > respond on exactly 5 ms, but I'd like to have some margin to
the
> > > > > > > specifications of the hardware I'm communicating with.

> > > > > > > // J



Tue, 31 May 2005 02:29:47 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Request/Respond serial port communication

2. How to make keyborad to respond quickly?

3. Serial port to serial port copying software

4. Challenge: Virtual serial ports from real serial port

5. using PC/104 serial expansion board with WinCE, 4 serial ports total

6. Parallel port/ Serial port

7. I want open the COM1 Port (serial Port)

8. Serial port

9. Serial port access

10. Serial port drivers

11. Reading from a Serial Port with C# ???

12. open serial port with C

 

 
Powered by phpBB® Forum Software