Author Topic: Has Anyone seen this with the Event Handler?  (Read 17807 times)

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Has Anyone seen this with the Event Handler?
« 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
« Last Edit: January 13, 2012, 07:28:35 am by GlennP »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Has Anyone seen this with the Event Handler?
« Reply #1 on: January 13, 2012, 10:11:10 am »
If you wait for 12 bytes, you might miss the final bytes if < 12.

Jan