SerialPorts.GetPortNames error

I seem to be getting some form of problem with using the SerialPorts.GetPortNames() function.

I want to get a list of the available ports and print them out on the console. I am aware that my ports are there because I’m testing them on Arduino so I know what kind of output I should receive.

I current have;

foreach(string str in SerialPort.GetPortNames())
		{
			Debug.Log(String.Format(str));
		}

But there is no output, anybody know why?

Edit: I’m using OS X if that helps

I have written an alternative for OS X users who wish to use SerialPorts.GetPortNames(), instead of calling this function, OS X users can simply use the method script.

void getPortNames ()
	{
		int p = (int)Environment.OSVersion.Platform;
		List<string> serial_ports = new List<string> ();
		
		// Are we on Unix?
		if (p == 4 || p == 128 || p == 6) {
			string[] ttys = Directory.GetFiles ("/dev/", "tty.*");
			foreach (string dev in ttys) {
				if (dev.StartsWith ("/dev/tty.*"))
					serial_ports.Add (dev);
				Debug.Log (String.Format (dev));
			}
		}
	}

In the GetPortNames function, it looks for ports that begin with “/dev/ttyS” or “/dev/ttyUSB” . However, OS X ports begin with “/dev/tty.”.

The Debug.Log will print out each of the available ports for you.

Thank you to Eroteme for showing me Mono SerialPort.cs.

The method is implemented in the Mono SerialPort.cs. It works as expected on my computer.

If you’re on Windows, perhaps you should double-check if the registry key HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM contain elements.