[Newbies] communication with serial port
ned at bike-nomad.com
Thu Nov 2 19:27:59 UTC 2006
Benjamin Schroeder wrote:
> On Oct 31, 2006, at 5:24 PM, remin at elgen.dk wrote:
>> hello to all,
>> i am new in this forum... so forgive me if this subject has been
>> posted before!
>> (is there an archive of old posts on the beginners list? i cant see it
>> at http://www.lists.squeakfoundation.org/cgi-bin/ezmlm-browse)
>> is there any good tutorials/examples on how to communicate with the
>> serial port? for beginners of squeak?
>> i am building a physical computer interface and display which i would
>> like to control the functionality of with squeak. the physical
>> controller is the arduino board (www.arduino.cc) linked to the
>> computer via USB (since my laptop has no serial plug i use a
>> serial->USB converter). the serial monitor in the arduino environment
>> works perfectly fine (i get lots of input), so i guess the USB signal
>> is treated like a serial signal via the arduino USB/serial
> Hi Jacob,
> What operating system are you running on?
> I also have an Arduino. I use Mac OS X, and my board shows up as a Unix
> device, in /dev/cu.usbserial-something or other. (I'm afraid I've left
> the board at the lab so I can't check right now! :)
> Squeak has a SerialPort class, but I'm not sure how to get it to
> recognize serial ports on OS X.
The stock SerialPort doesn't work, AFAICT, on OS/X. The source code is
John McIntosh did a new serial port interface for OS/X (and other
Unixes) that uses the standard termios calls but I am not sure what its
status is now. When he wrote it I was still using Linux on my main
machine and tried to port it to Linux but then didn't finish.
It is also possible that an async file handle would work but you'd have
to figure out a way to do serial-specific stuff.
I don't know enough OS/X details to be able to suggest a simple way to
get the stock SerialPort plugin code for Linux to be able to work on OS/X.
The main problem with the existing SerialPort plugin is that it
identifies ports by a SmallInteger. Which assumes some kind of
repeatable way to map from /dev/cu.* names to numbers, and I don't know
if there's a call to actually enumerate serial ports on OS/X.
I suppose that we could use a hash function to map from a name to a port
number both in Squeak and in the plugin, but that's a bit of a pain.
When I did the serial port plugin on Linux I took advantage of the fact
that most serial ports ended up with names like /dev/ttyS0 etc., and
just made the value of the last character equal to the port number.
The problem on OS/X is that the device driver is free to name device
instances whatever it wants to. And they can come and go, so a simple
enumeration by alphabetical order wouldn't work well. You'd have to
repeat the same enumeration in Squeak to get the number.
That is as if you'd done this:
ls /dev/cu.* | sort | cat -n
which on my system results in:
nedsmini:ned $ ls /dev/cu.* | sort | cat -n
But these numbers would only be valid between changes in available
Ideally we'd have an interface that could also take a String or
ByteArray with the name of the port.
I suppose the call could be polymorphic, taking either a String or a
> I hear it works well on Windows - and
> maybe Linux - but I'll leave explaining it to folks who know better. It
> looks like Ned Konz wrote a short introduction to it recently, at
> (The rest of the archives are at
> "http://lists.squeakfoundation.org/pipermail/beginners/" - I think it
> must just be on a different mailing list system than the page you found.)
> On OS X, I've instead written a small C library to read and write the
> serial port, and talked to it using Squeak's "FFI" functionality. (FFI
> stands for Foreign Function Interface, and it's a way to call external
> libraries from Squeak.) I've had success talking to the Arduino this way.
> I'd be happy to share my Unix/OS X code if it would help - let me know!
I'd like to see the code too. I'd be willing to put it on one of my
servers if you'd like.
Another possibility is to make a little proxy program that you could
connect to using a named pipe that would just talk to the serial port.
Its command protocol would have to support all the SerialPort primitives.
ned at bike-nomad.com
More information about the Beginners