user346443
user346443

Reputation: 4862

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.

Upvotes: 3

Views: 1640

Answers (1)

SwDevMan81
SwDevMan81

Reputation: 50018

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

Upvotes: 1

Related Questions