Lego Mindstorm and Squeak

Ned Konz ned at bike-nomad.com
Fri Mar 29 18:02:50 UTC 2002


On Friday 29 March 2002 09:17 am, Bergel Alexandre wrote:
> Hello,
>
> 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 :
> http://minnow.cc.gatech.edu/squeak/2412
>
> Do not hesitate to inform me about your comment...

First, the version of sqUnixSerial.c you have seems to be broken. Make these 
changes:

RCS file: 
/cvsroot/squeak/squeak/platforms/unix/plugins/SerialPlugin/sqUnixSerial.c,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 sqUnixSerial.c
337c337
<       /* defaultTermios.c_cflag = 0; */
---
>       defaultTermios.c_cflag = CREAD;
341,342c341,342
<       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.

"Receive loop"
[
	| delay buffer bytesRead |
	delay _ Delay forMilliseconds: 200.
	buffer _ String new: 100.
	[
		delay wait.
		bytesRead _ port readInto: buffer startingAt: 1.
		bytesRead > 0 ifTrue: [
			queue nextPut: (buffer copyFrom: 1 to: bytesRead).
		].
	] repeat.
] forkAt: Processor userInterruptPriority.

"Foreground process"

[
	queue size > 0 ifTrue: [ Transcript show: queue next ].
	World doOneCycle.
] repeat.


-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com



More information about the Squeak-dev mailing list