2.0.1 • Published 1 year ago

@mangar2/serialhelper v2.0.1

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
github
Last release
1 year ago

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
NameTypeDescription
eventstringevent name ( not case sensitive ) for the callback ( supports 'data' )
callbackDatafunction ( . . . parameter )
on throws
TypeDescription
Errorif the event is not supported
Errorif the callback is not 'function'

open

async open (serialPortName, baudRate) => {Promise}

Opens the serial port

open Parameters
NameTypeDescription
serialPortNamestringname of the serial port ( example "COM1" )
baudRatenumberbaud rate ( example 9600 )
open returns
TypeDescription
Promise

sendData

async sendData (byteArray) => {}

Sends data to the serial port

sendData Parameters
NameTypeDescription
byteArrayArray.<byte>serial data as byte stream
sendData returns
TypeDescription
| true , if sending was successful