denserial serial interface module

V1.0 - 11 Jan 2018

function listserialports

listserialports() ;

get a list of all serial communication ports

INPUTS: `none
RETURNS: an array of tables, where each table holds description, port name and Hardware ID
THROWS: no
Each element of the returned array has three slots:

slot key value
port serial port name (e.g. "COM1" or "/dev/ttyS0")
descr a description text, depending on OS
hwid a hardware ID string, depending on OS

Class serialport

Any class instance represents a serial port.
Note: A single port can not have more than one instance configured to it

Virtual prototype:

class DBICon {
    constructor(port,timeout[,baud,[bits,[parity,[stopbits,[flowcontrol]]]]]);
    function open();
    function close();
    function isopen();
    function available();
    function flush();
    function read(bytecount[,timeout_ms]) ;
    function readline([lineendstring,[timeout_ms]]) ;
    function write(bufferobj) ;
    function sendbreak(time_ms);
    function setbreak(onoff);
    function setDTR(onoff);
    function setRTS(onoff);
    function getCTS();
    function getDSR();
    function getRI();
    function getCD();
    function waitcontrol();
    function setport(port);
    function getport();
    function settimeout(timeout_ms[,constanttimeout_ms]) ;
    function gettimeout(which) ;
    function setbaudrate(baud);
    function getbaudrate();
    function setbytesize(bitspercharacter);
    function getbytesize();
    function setparity(paritystring) ;
    function getparity();
    function setstopbits(stopbits);
    function getstopbits();
    function setflowcontrol(flowstring);
    function getflowcontrol();

}

serialport Constructor

serialport(port,timeout[,baud,[bits,[parity,[stopbits,[flowcontrol]]]]])

where

port port id string, as returned in the "port" slots of function listserialports
timeout integer. read timeout in milliseconds
baud integer baudrate (e.g.2400,9600,19200,57600,115200 and the like)
bits integer bits per character. Values of 5 to 8 allowed only
parity string. One of Even, Odd, None, Mark or Space (or just the starting character of these)
stopbits integer or float. When integer, 10 times the stopbit count (e.g. 10,15 or 20), when float 1.0, 1.5 or 2.0 allowed
flowcontrol string, one of None, Hardware or Software (or just the starting character of these)

The constructor will automatically open the port, and it will throw an exception on any error.

Methods

serialport.open method

function open()

opens a closed port

INPUTS: none
RETURNS: none
THROWS: on error opening the port, even when already open!

serialport.close method

function close()

closes an open port

INPUTS: none
RETURNS: none
THROWS: on error, including trying to close an already closed port

serialport.isopen method

function isopen()

returns whether the port is open or closed

INPUTS: none
RETURNS: bool, true: port is open, false: port is closed
THROWS: no

serialport.available method

function available()

returns the number of bytes in the read buffer available for reading

INPUTS: none
RETURNS: integer number of bytes available for reading
THROWS: when used on misconfigured port

serialport.flush method

function flush()

flushes all internal I/O buffers of the port

INPUTS: none
RETURNS: none
THROWS: on error

serialport.read method

function read(bytecount[,timeout])

blocks until bytecount bytes read from serial port or timeout occurs. Optionally sets a different timeout

INPUTS:
bytecount: integer, number of bytes to read before method returns
timeout: integer, optional. Timeout in milliseconds. See note below
RETURNS: null when no data was read or a buffer instance holding all read data.
THROWS: on any error except timeouts
Notes:

serialport.readline method

function readline([lineend[,timeout]])

blocks until a "line" is read from the serial port or a timeout occurs, wherebytecount bytes read from serial port or timeout occurs.

INPUTS:
lineend: string, optional. A string determining the line ending. When omitted defaults to "\n" for Linux and "\r\n" for Windows
timeout: integer, optional. Timeout in milliseconds. Also see notes for read
RETURNS: null when no data was read at all, or a string holdign the line read from the serial port.
THROWS: on any error except timeouts
Note: The line can have a maximum length of 65535 characters!

serialport.write method

function write(data)

writes data to the serial port

INPUTS: data: any buffer, sockbuf or blob instance, or any string
RETURNS:: true when all bytes were written, otherwise the integer number of bytes actually written
THROWS: on any error

... Documentation WIP, to be continued ...