Lego Mindstorm and Squeak
ned at bike-nomad.com
Fri Mar 29 18:02:50 UTC 2002
On Friday 29 March 2002 09:17 am, Bergel Alexandre wrote:
> I have finally make a little web page about my work with lego mindstorm.
> It works fine, but... I need help for getting out of my troubles with
> serial port.
> LegoMindstorm on Squeak here :
> Do not hesitate to inform me about your comment...
First, the version of sqUnixSerial.c you have seems to be broken. Make these
retrieving revision 220.127.116.11
diff -r18.104.22.168 sqUnixSerial.c
< /* defaultTermios.c_cflag = 0; */
> defaultTermios.c_cflag = CREAD;
< defaultTermios.c_cc[VTIME] = 5;
< defaultTermios.c_cc[VMIN] = 1;
> defaultTermios.c_cc[VTIME] = 0;
> defaultTermios.c_cc[VMIN] = 0;
Second, you really don't want blocking I/O for the serial port. Not even if
you think you do. If you use blocking I/O nothing at all will happen while
you're waiting for bytes.
We need to provide real Semaphore signaling for the serial ports like there
is for the Sockets, but until that time, is there some reason why you can't
just do polling?
That is: have a background Process that does nothing but receive bytes,
stuffing received strings into a SharedQueue. This would be polling at a
reasonable rate. Of course, you would have to assemble the received fragments
at the other end.
That is, this Workspace code works fine for me on Linux:
queue _ SharedQueue new.
port _ SerialPort new openPort: 5.
| delay buffer bytesRead |
delay _ Delay forMilliseconds: 200.
buffer _ String new: 100.
bytesRead _ port readInto: buffer startingAt: 1.
bytesRead > 0 ifTrue: [
queue nextPut: (buffer copyFrom: 1 to: bytesRead).
] forkAt: Processor userInterruptPriority.
queue size > 0 ifTrue: [ Transcript show: queue next ].
currently: Stanwood, WA
email: ned at bike-nomad.com
More information about the Squeak-dev