Read serialport data in under 2ms in C#

I need to receive 3 characters every 2 milliseconds in a loop. I am using SerialPort.Read() but it takes 5 to 6 miliseconds to read incoming data. Is there possible way to do it? Thanks a lot.


You may want to call the serial port in C++,

Then you can call that from C#,

I expect this will be faster, but you will have a slow down in getting the data from C++ -> C#, and your window of 2-3 ms is very tiny.

You can get the data in that time, I expect, from C++, but you may need to buffer it, so I would put a timestamp with each piece of data, and when you call it from C# you may need to return more than one piece, and then process them.

In C++ DLL you will want to have a separate thread for reading from the serial port.

You will want to use the thread class, and detach it after creation.

And finally you will want to use a thread safe queue, so you can look at these two links and pick which one you like better:

C++11 thread-safe queue

Need Your Help

How do I generate points that match a histogram?

c algorithm histogram probability numerical-analysis

I am working on a simulation system. I will soon have experimental data (histograms) for the real-world distribution of values for several simulation inputs.

iOS ARC block retain cycle

ios automatic-ref-counting block retain-cycle

Can someone confirm if the block below is turning into a retain cycle please? Please note the block is being called by SampleClass2 not SampleClass1.