BSSerialPort
4 min
For more information about available methods, refer to the roSerialPortroSerialPort entry.
If possible, use @brightsign/serialport with the Node Package serialport instead of BSSerialPort. A basic reference implementation can be found in this GitHub repository.
Object Creation
BSSerialPort(in unsigned long port);
Methods
- SetBaudRate(in unsigned long baudRate) raises(DOMException) void
- SetDataBits(in unsigned long dataBits) raises(DOMException) void
- SetStopBits(in unsigned long stopBits) raises(DOMException) void
- SetParity(in DOMString parity) raises(DOMException) void
- SetEcho(in boolean flag) boolean
- SetInverted(in boolean flag) boolean
- SetFlowControl(in boolean flag)
- SetGenerateByteEvent(in boolean flag) raises(DOMException) void
- SetGenerateLineEvent(in boolean flag) raises(DOMException) void
- SetLineEnding(in DOMString eol) raises(DOMException) void
- SendByte(in unsigned long byte) boolean
- SendBytes(in ArrayBuffer data) boolean
- SendBytes(in ArrayBufferView data) boolean
- SendBytes(in DOMString data) boolean
- SendBreak(in long duration_ms) boolean
- Flush() raises(DOMException) void
- Close()void: Shuts down the instance, preventing it from further consuming resources. If this method is not called, garbage collection determines when the instance will be destroyed.
Events
The following events are available via the BSSerialPort object. Each event can receive a SerialPortEvent event.
- onserialbyte
- onserialline
SerialPortEvent – Attributes
For the onserialbyte event:
- sbyte unsigned long readonly
For the onserialline event:
- sdata DOMString readonly
Example
function serialOut()
{
console.log("*** serialOut **");
// '2' is the first externally connected USB port on Cheetah
var serial_out = new BSSerialPort(2);
serial_out.SetBaudRate(115200);
serial_out.SetDataBits(8);
serial_out.SetStopBits(1);
serial_out.SetParity("none");
serial_out.SetEcho(true);
serial_out.SetGenerateByteEvent(true);
serial_out.SetGenerateLineEvent(true);
serial_out.onserialbyte = function(e){
console.log('### onserialbyte: ' + e.sbyte);
}
serial_out.onserialline = function(e){
console.log('### onserialline: ' + e.sdata);
}
serial_out.SendByte(89);
serial_out.SendByte(90);
serial_out.SendByte(91);
serial_out.SendBytes('Hello World!');
serial_out.SendBytes(String.fromCharCode(64, 27, 66, 67))
}