63 lines · 1.3 KB · Text
RawDownload
// list serial devicesSerialIO.list() @=> string list[];// no serial devices availableif( list.size() == 0 ){    cherr <= "no serial devices available\n";    me.exit(); }// print list of serial deviceschout <= "available devices\n";for( int i; i < list.size(); i++ ){    chout <= i <= ": " <= list[i] <= IO.newline();} // parse first argument as device number0 => int device;if( me.args() ) me.arg(0) => Std.atoi => device; if( device >= list.size() ){    cherr <= "serial device #" <= device <= "not available\n";    me.exit(); } // open serial deviceSerialIO cereal;if( !cereal.open(device, SerialIO.B9600, SerialIO.BINARY) ){    chout <= "unable to open serial device '" <= list[device] <= "'\n";    me.exit();} // pause to let serial device finish opening2::second => now; // ASCII string: hi!\n[ 'h', 'i', '!', '\n' ] @=> int bytes[]; // infinite time-loopwhile( true ){    // write to serial device    cereal.writeBytes( bytes );        // read one line    int byte;    string line;    while( byte != '\n' )    {        cereal.onByte() => now;        cereal.getByte() => byte;                line + " " => line;        line.setCharAt( line.length()-1, byte );    }        // print    chout <= "=> " <= line;     // advance time    1::second => now;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t