Read/Write to/from serial port, physically attached to host computer.

class SerialPort {
        constructor SerialPort('a name');
        bool open( String filename );
        bool close();
        bool hasData();
        bool writePort( string );
        bool writeBytes( Array );
        string readPort();

        string getLastErrorMsg();


var p = new SerialPort('ACM0');


.open( String name [, Speed])
open 'name' port at speed 'speed', allowed values : ouvre le port 'name' à la vitesse 'speed', valeurs possibles

  • not specified : vitesse par défaut du périphérique
  • or one of these values : 1200,1800,2400,4800,9600,38400,115200,230400,460800


Close serial port of an object SerialPort





Send the given string to the serial port

.writePort( string );


Send the given array to the serial port

.writeBytes( Array );

example :

var serial = new SerialPort('comm');
if( '/dev/ttyUSB0', 9600) == false ) {
    print('cannot open serial communication');

var data = new Array();
datas.push( 0x00 );
datas.push( 0x01 );

serial.writeBytes( datas );


Retrieve serial buffer into text object



Retrieve serial buffer into Uint8Array object



Retrieve serial buffer into Uint16Array object



var p = new SerialPort('toto');
    if('/dev/ttyUSB0', 9600 ) != true ) {
        print('cannot open port');
    p.writePort('Hello world');
    if( p.hasData() ) {
        var rep = p.readPort();
        print('reply:' + rep );
        var raw = p.readBytes();
        for( var i=0 ; i < raw.length, i++ ) {
Last update: July 6, 2023