Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# SerialPort.ReadExisting Error

I have hooked a Unity project up to an Arduino board via a com port. I am receiving data from it fine while using SerialPort.ReadLine(), however, if i use SerialPort.ReadExisting() I get the error:

Object reference not set to an instance of an object

I need to use ReadExisting as my application cant keep up with the rate that the Ardunio board is spitting out data.

I have got ReadExisting working fine in a XNA project, just when used in a unity project i have issues.

Any help would be highly appreciated.

like image 974
user346443 Avatar asked Feb 06 '26 15:02

user346443


1 Answers

I would use the DataReceived event. Then inside the event handler, try and call ReadExisting. The link I posted has an example.

like image 176
SwDevMan81 Avatar answered Feb 09 '26 04:02

SwDevMan81