- Home /
Multiple SerialPorts delay (C#)
Hi,
I'm developing an application in Unity that will communicate via Bluetooth (using the SerialPort C# class) with some devices that send me data continuosly. I print this data on the screen and Log, to ensure communication is stablished and data is received at a steady rate. When using only 1 device, everything seems to be running fine, data is shown correctly on the screen.
But when I use 2 devices, data input has a delay of some seconds for one (sometimes both) of the devices. I'm almost 100% sure that the problem comes from the line where I read from the devices:
string result = serialPort.ReadLine();
My guess is that when this code is called for the first device, the second has to wait for the first to end, which causes the delay.
Does anyone know a solution or workaround to this problem? (for example: use another C# classes, another Serialport connection paramteters, use another SerialPort read method to read the input from the devices, use some kind of threading in Unity ,...).
I'm using Untiy and Windows 7 x64.
Thanks in advance
I would recommend the use of threads for this kind of problem.