Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
<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();
                        //Debug.WriteLine(data[j]);
                        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()
        {
            // configure dispatcher
            _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.
Posted
Comments
[no name] 19-Mar-21 14:02pm    
The master "asks" for data; the slave then sends.
Romain Figoli 22-Mar-21 4:36am    
Hi, so why doesn't the master read the last data received but the next data after the last received even if it was a few seconds ago?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900