[squeak-dev] Re: Linux and ttyUSB0

Séverin Lemaignan skadge at gmail.com
Sun Jan 4 22:54:22 UTC 2009

Hello everyone,

A couple of months later, I'm eventually working on getting the
SerialPort plugin to work for arbitrary nodes name under Linux (and
thus MacOS).

A quick summary of the issue, to refresh memories: today, you can open
a serial port in Squeak with "SerialPort new openPort:portNum.". Eg,
for portNum = 1, it would map to COM1 under Windows and /dev/ttyS1
under Linux.
That's fine, except that recent Linux kernels don't mount most serial
devices on /dev/ttySxx, but on more specific nodes, like /dev/ttyACMxx
for modems, /dev/ttyUSBxx for certain USB->COM converters, etc.

To circumvent it, I modified the Serial Port plugin to accept either
port numbers or arbitrary paths. I still have some cleaning to do, but
the plugin itself (sqUnixSerial.c) basically works.
But I have some troubles to get it to work from Squeak. I modified
SqueakPlugin.c to introduce new primitive calls (plus their
corresponding "exports" declaration), namely:
EXPORT(sqInt) primitiveSerialPortCloseByName(void);
EXPORT(sqInt) primitiveSerialPortOpenByName(void);
EXPORT(sqInt) primitiveSerialPortReadByName(void);
EXPORT(sqInt) primitiveSerialPortWriteByName(void);

For each of them, I need to get the port name. I did like that
(copy-pasted from another plugin):

        int spName;
        char * spNameIndex;

        spName = interpreterProxy->stackValue(0);
        spNameIndex = interpreterProxy->firstIndexableField(spName);

But I probably do something wrong since if I call the primitive
"primSerialPortOpenByName" with "/dev/ttyACM0" as port name from
Squeak, the plugin code in sqUnixSerial.c receives a different string
("/dev/ttyACM0_��@�w@�w"), thus failing to open the serial port.

Does someone knows how to correctly transmit a string argument to a plugin?

I attach to the mail my working versions of sqUnixSerial.c,
SerialPlugin.c, SerialPlugin.h. If needed, I can send as well some
test code for sqUnixSerial.c.

And by the way, happy new year to everybody!


2008/6/18 David T. Lewis <lewis at mail.msen.com>:
> On Wed, Jun 18, 2008 at 04:10:39AM +0100, S??verin Lemaignan wrote:
>> Thanks, Dave, for the answer.
>> > A slightly more difficult change would be to add an optional primitive for
>> > Unix/Linux that sets the serialPortBaseName string. That would let you control
>> > it from Squeak, and would not require any changes to the existing primitives.
>> That's actually probably what I'll try to do. Stupid question, but
>> where can I fetch the sqUnixSerial.c file (and it's MacOS
>> counterpart)?
> Severin,
> The sqUnixSerial.c file is part of the external support code (as opposed
> to the parts that are distributed in the VMMaker package). The external
> support code is maintained in a Subversion repository at http://squeakvm.org
> and you will also find it at the various VM home pages. If you are working
> with Linux for example, just grab one of Ian's distributions on
> http://squeakvm.org/unix/.
> The sqUnixSerial.c file is in platforms/unix/plugins/SerialPlugin.
> The corresponding support code for other platforms is in e.g.
> platforms/Mac OS/plugins/serialPlugin.
> I don't know enough about Mac OS to give any guidance there, but the
> support code for SerialPlugin looks like it might be for some older
> version of Mac OS. I understand that on OS X you can actually use
> a plugin from the unix sources, but I'm afraid I don't know the details.
> Dave
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqUnixSerial.c
Type: text/x-csrc
Size: 12856 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090104/1b844381/sqUnixSerial.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SerialPlugin.c
Type: text/x-csrc
Size: 11465 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090104/1b844381/SerialPlugin.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SerialPlugin.h
Type: text/x-chdr
Size: 897 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090104/1b844381/SerialPlugin.h

More information about the Squeak-dev mailing list