jrowberg / bglib

BGLib implementation for Bluegiga BLE Bluetooth Smart modules
Other
239 stars 170 forks source link

BgLib performance issue using C# #18

Closed alecha closed 9 years ago

alecha commented 9 years ago

Hi, I've noticed that maybe there are some performance issue using BgLib for C#.

In particular, I'm reading data from a BLED112, and I've noticed that the BytesToRead property of the SerialPort starts increasing a lot before BgLib is able to finish parsing the previous data.

Looking ad the DataReceivedHandler method:

private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e){ var sp = (SerialPort)sender;

        var bytesToRead = sp.BytesToRead;
        var inData = new byte[bytesToRead];

        // read all available bytes from serial port in one chunk
        sp.Read(inData, 0, bytesToRead);

        // parse all bytes read through BGLib parser
        foreach (var t in inData)
        {
            _bglib.Parse(t);
        }
    }

Printing bytesToRead property reveals that the value is for example 9, then 2000, then 12000 and so on, so I'm seeing the data with an increasing delay!

Anyone has noticed this? Are there any workaround?

My data has a frequency of 64hz.

Thanks!

sjoerdboerhout commented 6 years ago

Any solution for this issue? I'm experiencing the same issue. Parse function fails with an index out of bound exception and the application becomes unusable...