SerialPort cross-platform question...

Dan Ingalls Dan at SqueakLand.org
Sun Feb 24 00:58:53 UTC 2002


>On Monday 11 February 2002 03:05 am, Bergel Alexandre wrote:
>> > Actually, the peculiar enumeration of the ports is a Mac-ism. On the
>> > Windoze and Unix platforms, it would make more sense to supply a name.
>>
> > Why to supply a name ? 'COMx' belong to windows world...

and Ned Konz <ned at bike-nomad.com> replied...
>How would you know, portably, what the name of the serial port is in a Unix
>system? Could be anything (including a symlink to an entry in /dev
>somewhere). There are _no_ reliable standard names for serial ports in Unix.
>I picked /dev/ttyS0 etc. because that worked on my system and common PC Linux
>systems. But it's not going to work if (for instance) you have an intelligent
>multiport serial card installed also and want to use one of those ports.
>
>For instance, /dev/ttyH0, /dev/ttyC0, /dev/ttyD0, /dev/ttyE0, /dev/ttySR0,
>etc. are all typical names for a serial device. But these are only the
>traditional names. And if someone linked /wherever/mySerialPort to one of
>these (or made a node with that name), we should be able to use it as well.
>This is why I said that names would help.
>
>On the Windows machines, there is no guarantee that there is any consecutive
>number of the COMx ports. I have a Windows box whose COM ports start at COM4.
>
>> > And it's not clear how the ports are numbered on the Mac when you hang
>> > USB serial ports on one (per Dan Ingalls).
>>
>> I use on my linux a usb->serial adaptor, and it is the same then a real
>> port. I guess it should be the same for mac.
>
>So did we, but Dan hasn't been able to find a number that worked reliably.

I've just learned a couple more useful facts.  First of all, John McIntosh steered me toward a wonderful facility provided quite a while ago by John Maloney.  At least on the Mac (I'm curious about other platforms), you can print,
	MidiPrimTester new getPortList
to get a listing like the following (this Mac had a Belkin USB unit attached):

MIDI Ports:
	0: Infrared Port (in/out)
	1: Internal Modem (in/out)
	2: Printer Port USB (in/out)
	3: Belkin Serial Port (in/out)
	4: QuickTime MIDI (out)

This immediately cleared up some questions I had about how the Belkin adapter (USB to 2 serial ports) worked.  More importantly, it steered John Mc straight to a bug in the Mac serial primitive that prevents opening any port numbered higher than 1.  He's preparing a fix even as I write.

If the portCount and portName primitives used by this facility work on all platforms, then there is at least the promise of things being pretty civilized.

	- Dan



More information about the Squeak-dev mailing list