Problems Accessing SerialPort

Hi to all,

I need to access to a COM port to receive data from a input system. For this, I tried many things. I’ve tried SerialPort.ReadLine that doesn’t function to me and stuck me unity in this instruction. Moreover, I’ve tried to create a Separate Thread with a simple ReadByte (that function to me, but data arriving to fast and it takes disordered data). In separate thread nothing is read and I don’t understand why. I read that separate threads can’t access to unity API but SerialPort is not part of unity API or not? Moreover, I tried to use SerialPort BeginRead and EndRead with Asyncronous call but Unity remain blocked on the BeginRead call despite it is async.

Have you any other idea? How I can do to solve my problem?

Thank you very Much


Solved using a secondary Thread with a locked variable on a ActionQueue. On each frame in the update method I see if there are some action that the main thread has to invoke for completing this frame. This solves posted problems, if someone else have the same problem like me.

This older thread might be of help to you. There is one post that comments on reading from an Arduino. That code looks pretty good. Resembles C++ code I have used to read from a com port.

I found a alternative temporal solution for this, please read the following thread: