IOException using Serial dll

I am trying to read a serial port with Unity and get a puzzling IOException.

The bare bones of the C# Class Serial Library dll is:

using System.IO.Ports;

namespace SerialLib
{
    public class SerialClass
    {
        static SerialPort sp;
       

        //Constructor
        public SerialClass()
        {
          
        }

        public string GetValue(string portName)
        {
            {
		    string result = “”;
                sp = new SerialPort();
                sp.PortName = portName;
                sp.Open();


                if (sp.IsOpen)
                {
                    sp.WriteLine("?"); //Character to query serial device
                    result = sp.ReadTo("\r");
                    sp.Close();
                }
		    return result;

            }
        }
    }
}

A simple Windows Form to test this follows. This works fine!

using System.Windows.Forms;
using SerialLib;

namespace SerialTest
{
    public partial class Form1 : Form
    {
     
        SerialClass myPort;

        public Form1()
        {
          
            InitializeComponent();

            myPort = new SerialClass();
        
            string value =myPort.GetEncoderValue("COM11");
            label1.Text = value;
        }
    }
}

However, similar code in Unity results in IOException: The port ‘COM11’ does not exist.

using UnityEngine; 
using System.Collections; 
using SerialLib;


public class SerialTestScript : MonoBehaviour { 
    
	
		SerialClass myPort;
		
	
    
   // This method is for initialization and test. 
   void Start () { 
        myPort = new SerialClass();
        string value =myPort.GetEncoderValue("COM11");
        print(value);
	   
   } 

}

Any help with solving this would be greatly appreciated.

Thanks!

Use anything under COM10 :confused:

Its some stupid issue with .NET / Mono assuming that all COM ports follow the naming convention “COM#” and nothing else. I just ran into this tonight.

“\\.\COM10”, // address of name of the communications device
Try above and follow the link below. It worked for me. I know this is not a new thread. Just do some community work since I have been benefitted from Unity3D forum for so long. Thank you all.

http://support.microsoft.com/kb/115831

IOException: The port `COM4’ does not exist.
System.IO.Ports.WinSerialStream.ReportIOError (System.String optional_arg)…why?