Question

For my project I need to communicate with an Cypress PSoC5. I can use a serial connection or a USB HID connection.

I created a C# project for sending and reading data to/from PSoC5. Right now I'm using the ReceivedData event of the serialport to get notified if there is new data. Basically my project can either receive a datastream that should be plotted in realtime or just some settings I want to update within the GUI.

Right now I face the problem that the ReceivedData event fires very often (every 32 bytes), which is of course not good when there is a datastream. Basically I receive 24000 bytes per second if I get data for the plot. I know I can adjust the ReceivedBytesThreshold, but then I will not get an event for data below the threshold.

Can anyone tell if there is an approach to handle this?

Would it be an advantage to use the PSoC5 as a HID device instead?

Was it helpful?

Solution

By default SerialPort.ReadBufferSize is set to 4096 bytes. Slighly more info here. But you can easily change it to accomodate necessary amount of data. Then in DataReceived event handler do something like this

 static void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {

       if (Serial.BytesToRead < 24000) return;

               ... //Recieve and process your data here
    }

24000 is given here for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top