@mangar2/serialhelper
v2.0.1
Published
Serial connection to microcontroller
Downloads
4
Readme
Abstract
Contents
Meta
Callback definitions
Data
Called when at least one byte has been read from the serial connection
Class SerialConnection
new SerialConnection()
Class shielding the serial port class and provides async interfaces The functions open , close , and send data are async functions . Read data by registering the callback 'data' with the on function
SerialConnection Methods
close
async close ()
Closes the serial port
listAvailablePorts
async listAvailablePorts ()
Lists all available ports to console
on
on (event, callback)
Sets a callback .
on Parameters
| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| event
| string
| event name ( not case sensitive ) for the callback ( supports 'data' ) | |
| callback
| Data
| function ( . . . parameter ) | |
on throws
| Type | Description |
| ---- | ----------- |
| Error
| if the event is not supported |
| Error
| if the callback is not 'function' |
open
async open (serialPortName, baudRate) => {Promise}
Opens the serial port
open Parameters
| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| serialPortName
| string
| name of the serial port ( example "COM1" ) | |
| baudRate
| number
| baud rate ( example 9600 ) | |
open returns
| Type | Description |
| ---- | ----------- |
| Promise
| |
sendData
async sendData (byteArray) => {}
Sends data to the serial port
sendData Parameters
| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| byteArray
| Array.<byte>
| serial data as byte stream | |
sendData returns
| Type | Description | | ---- | ----------- | | `` | true , if sending was successful |