Hi,
I'm using an Arduino with a Zigbee to send data from sensors and a Raspberry Pi with an another Zigbee to read the data which is 10 bytes with a head and a stop.
I'm on Windows 10 IoT and I code with VS 2019.
My issue is that my RPI read the data but is getting more and more late so I'm not in real time anymore.
I know that the problem comes from the buffer that force me to read each message and I'm willing to change that.
I would like to read only the last message in the buffer but I don't know how to.
Thank you for your help,
Romain.
<pre>private async Task<ZigBeeCommResult> Read()
{
var retvalue = new ZigBeeCommResult();
try
{
_dataReader = new DataReader(_zbCoordinator.InputStream);
var numBytesRecvd = await _dataReader.LoadAsync(10);
byte[] data = new byte[10];
retvalue.TextResult = "";
Debug.WriteLine(_dataReader.UnconsumedBufferLength);
while (_dataReader.UnconsumedBufferLength > 0)
{
for (uint j = 0; j < 10; j++)
{
data[j] = _dataReader.ReadByte();
retvalue.TextResult += data[j];
}
}
txtHeader.Text = retvalue.TextResult;
}
catch (Exception ex)
{
retvalue.IsSuccessful = false;
retvalue.TextResult = ex.Message;
}
finally
{
if (_dataReader != null)
{
_dataReader.DetachStream();
_dataReader = null;
}
}
return retvalue;
}
and
public void DispatcherTimerReaderSetup()
{
_dispatcherTimerReader = new DispatcherTimer();
_dispatcherTimerReader.Tick += DispatcherTimerReader_Tick;
_dispatcherTimerReader.Interval = new TimeSpan(0, 0, 0, 0, 500);
_dispatcherTimerReader.Start();
}
public void DispatcherTimerReader_Tick(object sender, object e)
{
Read();
}
What I have tried:
I tried to read faster than I send data but error and I also searched how to empty the buffer but I didn't find.