I’ve developed a C#.NET application that communicates with an Arduino using the SerialPort.Open method and that works great. However, I recently wanted to use the same code in Unity and tried both in 3.5 and 4 and both versions throw the following exception (.NET part of stack trace included)
System.IO.IOException: The port `COM10’ does not exist.
at System.IO.Ports.WinSerialStream.ReportIOError (System.String optional_arg) [0x00000] in :0
at System.IO.Ports.WinSerialStream…ctor (System.String port_name, Int32 baud_rate, Int32 data_bits, Parity parity, StopBits sb, Boolean dtr_enable, Boolean rts_enable, Handshake hs, Int32 read_timeout, Int32 write_timeout, Int32 read_buffer_size, Int32 write_buffer_size) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.IO.Ports.WinSerialStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
The port obviously exists as I can open up my C# application and communicate with the Arduino fine, but Unity always says the port does not exist.
To eliminate any error on my part, after using the string “COM10”, I tried using the SerialPort.GetPortNames() method and use the string directly form that in .Open, but it was to no avail.
I exit my application before trying it out in Unity. No matter how many times I close my application and how many times I try Unity, the situation is the same.
