| 1 |
// list of Serial IO |
| 2 |
SerialIO.list() @=> string list[]; |
| 3 |
// print list |
| 4 |
for( int i; i < list.size(); i++ ) |
| 5 |
{ |
| 6 |
chout <= i <= ": " <= list[i] <= IO.newline(); |
| 7 |
} |
| 8 |
|
| 9 |
// parse first argument as device number |
| 10 |
0 => int device; |
| 11 |
if( me.args() ) me.arg(0) => Std.atoi => device; |
| 12 |
if( device >= list.size() ) |
| 13 |
{ |
| 14 |
cherr <= "serial device #" <= device <= " not available\n"; |
| 15 |
me.exit(); |
| 16 |
} |
| 17 |
|
| 18 |
// serial io |
| 19 |
SerialIO cereal; |
| 20 |
// open device |
| 21 |
if( !cereal.open(device, SerialIO.B9600, SerialIO.ASCII) ) |
| 22 |
{ |
| 23 |
chout <= "unable to open serial device '" <= list[device] <= "'\n"; |
| 24 |
me.exit(); |
| 25 |
} |
| 26 |
|
| 27 |
// infinite time-loop |
| 28 |
while( true ) |
| 29 |
{ |
| 30 |
// wait for event |
| 31 |
cereal.onLine() => now; |
| 32 |
// get line |
| 33 |
cereal.getLine() => string line; |
| 34 |
// print |
| 35 |
if( line$Object != null ) |
| 36 |
chout <= "line: " <= line <= IO.newline(); |
| 37 |
} |