PORTS Forum

Ports and Interfaces => Serial Ports => Topic started by: GlennP on January 13, 2012, 05:51:17 am

Title: Has Anyone seen this with the Event Handler?
Post by: GlennP on January 13, 2012, 05:51:17 am
Hi All,

Glenn again (!), I have an issue with the event handler it does not appear to catch all the data coming into the port. The event hanlder is
   InputData = myComPort.ReadExisting();
          if (InputData != String.Empty)
          {
            this.BeginInvoke(new SetTextCallback(SetText), new object[]{ InputData});
          }
I appear to solved this with the following
   int valueWait = WaitForData(12, 10);
which calls the function wait for data which uses while loop to sleep the thread 10ms for 12 bytes of data.  Will this admitedly dirty solution cause any other issues and still cure the missing data issue.
I am worried that if the event handler is missing data the WaitForData() function could issues as it uses the BytesToRead function.

Glenn

Update:

the serial port was serial port event handler before the WaitForData function was seeing

UD:0001=H2000749724900011250077136 >
UD:0002=H220
When checked with a serialport monitor the device was sending


UD:0002=H2207301416100000041075142 >
this was being read as UD:0002=H220
Title: Re: Has Anyone seen this with the Event Handler?
Post by: Jan Axelson on January 13, 2012, 10:11:10 am
If you wait for 12 bytes, you might miss the final bytes if < 12.

Jan