Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Mini-Maestro and Unity3D compatibility issue


Hello, I’m a long-time Maestro user and lover. I want to use a chain of Maestros together with the wonderful Unity3D application, which uses Mono, based on .net 2.0, for its scripting. I am using Windows 7 64-bit and Unity 4.0 along with a single 24-channel Maestro for now. But I can’t get Unity to talk to the COM ports. Here is the appropriate JavaScript code snippet:[code]
private var paryPortName = new Array();
private var pprtMaestro : System.IO.Ports.SerialPort;
// These namespace references are at the top, above this code snippet:
// import System;
// import System.IO.Ports;

function Start () {
var L : int;
var strPortName : String;

// Iterate through the available ports and save their names in an array
for (var s : String in System.IO.Ports.SerialPort.GetPortNames()){paryPortName.Push(s);}

// Iterate through the array displaing the names of all available ports
for (L = 0; L < paryPortName.length; L++){print("L=" + L + " name=" + paryPortName[L]);}

// Get the name of the Pololu control (NOT TTL) port, always the second to the last the way I use my system.
strPortName = paryPortName[paryPortName.length - 2];
// Create the port reference and assign the name, baud rate, parity, data bits and stop bit.
pprtMaestro = new System.IO.Ports.SerialPort(strPortName, 115200, Parity.None, 8, StopBits.One);
// Be ready for trouble
try {
	// Open the port
catch(err) {
	print("Port is not open  " + err);

[/code]I get the catch phrase which says, “Port is not open.” The appended error says, “System.IO.IOException: The port ‘COM23’ does not exist.” COM23 is exactly the name that I see in the Device Manager for the Control port (COM24 is the TTL port). So GetPortName gets the name, but IOException says it doesn’t exist, even though I use the name via variable without any chance of corrupting the name string (and every reasonable permutation to get it to work, like hard-coding “COM23”). Maybe there is some implied portion of the name or path I am supposed to be adding (I have tried ‘/dev/COM23’ because I saw a hint that might work). Maybe .net 2.0 doesn’t like COM port names higher than 4 or 5. Does anyone have any insight about this kind of problem? By the way, Unity converts my optional JavaScript scripts to C++, just as it does Unity’s optional C# or Boo scripts, so going with the C# equivalent of my script doesn’t make any difference-- I’ve tried it. I’ve had great success communicating with my chained Maestros using VB.net, UscCmd works with AutoHotKey just great, I can talk to the current Maestro using the Control Center, and Unity 4.0 is just exquisite and modern except for Mono’s use of .net 2.0. However, I need some of Unity’s matchless 3D features so I need to get it to talk to the Control COM port. Can you help me? Thanks so much! Loren


Hello, Loren.

Sometimes the USB-to-Serial driver usbser.sys gets into a bad state and you just have to reset it. Have you tried unplugging the Maestro, closing all programs that might be using a COM port, and plugging it back in? Have you tried rebooting the computer?

It shouldn’t be necessary but you could also try entering “USBSER000” as the COM port name if the Maestro is the only device plugged in that is using usbser.sys.

Another thing to try is to add \\.\ to the beginning of the COM port name. To write that properly as a string in your source code, you probably have to escape the slashes, so you would write it as "\\\\.\\COM23".



David!!! You pegged it first try! Well done!! The \\\\.\\COM2 trick did the job! I understand that translates to \\.\, but what does it mean? And how did you know about that? I’d like to know so I can pass it on, or, even better, take the time you probably don’t have to expand on the topic for the benefit of my fellow Maestro-users so they can learn how a .net application could come to require that special prefix or path designation or whatever it is.
Anyway, great job. That should be useful information to a lot of people.



Actually I am not sure what it means. I just know that if you want to open a COM port above COM9 with the CreateFile function you need that prefix. You can also open other objects like \\.\USBSER000 this way and the WinObj utility can provide a list of those objects.



\\.\ is the “device” namespace in the Windows NT file system.

You can start here: support.microsoft.com/kb/235128
although this part of Windows really lacks good overview – AFAICT, you’re supposed to go take a sysinternals.com class to learn how to do Windows device drivers :-/