Dealing with Unix character devices?

David T. Lewis lewis at mail.msen.com
Thu Aug 28 13:27:51 UTC 2003


On Thu, Aug 28, 2003 at 12:55:11AM -0500, Aaron J Reichow wrote:
> Ahoy!
> 
> I'm rather new to dealing with Unix serial/character devices in Squeak.
> Anyone have any tips to impart?  Can I just approach grabbing data via a
> /dev/* file with a regular FileStream, or do I need a) OSProcess or b)
> something else?
> 
> All I'm interested in is reading from the device, I don't need to write to
> it.  The specific device is /dev/ttyS0, the physical device is the IR
> port, and the purpose of this is to read codes from the IrDA keyboard I
> have.  The Qtopia driver doesn't seem to interact well with the Squeak VM,
> so I thought I'd try my hand at writing a driver that has no underlying
> dependencies beyond some serial access.
> 
> I've attempted to just use a file stream (FileStream oldFileNamed:
> '/dev/ttyS0')  and then sending it #next to get the next character.
> Unfortunately, when I tell it to #next, Squeak just locks up.  I've not
> done much investigation as to why this is, but I thought perhaps this was
> something others have dealt with in the past...

Your VM is blocking on a read, and this is the expected behavior.
Since you are using Linux, the next time you get stuck like this, look
in /proc/yourSqueakPid/fd/* and feed some data to whatever open file
descriptor you were trying to read. This will unblock your Squeak VM.

You can set a file stream on /dev/ttyS0 for nonblocking reads using
OSProcess. Look for methods called setNonblocking* or something like
that (I'm away from my Squeak box so I can't give you this exact
references). This will let you set up a nonblocking file stream on
/dev/ttyS0, and you could use a process with a polling loop to handle
the incoming data. Crude, but it works.

I've implemented event-driven reads with Ian's aio functions in the
Unix VM, but I don't think it's in any of the stuff I've released
on the list yet. I'll try to get you a copy (probably this weekend).
The required primitives are already on the OSPP plugin, it just needs
a little support code to forward the "data ready on /dev/ttyWhatever"
event to a semaphore in Squeak.

There are also various serial port support packages that folks have
done, and maybe one of these is more appropriate for what you are
doing. Try searching the swiki, or maybe someone else can supply a
good pointer.

HTH,
Dave



More information about the Squeak-dev mailing list