@cutos/drivers
v3.2.4
Published
SerialPort provides basic serial port communication functions, and the SerialPortSimulator class can be used to simulate serial port behavior for testing and development. SerialPort is used to handle serial port communication, using the serial port path,
Downloads
301
Readme
Introduction
SerialPort provides basic serial port communication functions, and the SerialPortSimulator class can be used to simulate serial port behavior for testing and development. SerialPort is used to handle serial port communication, using the serial port path, baud rate, callback function and simulator to create a new serial port object. SerialPortSimulator creates a new serial port simulator object to simulate serial port behavior.
Table of Contents
SerialPort
Constructor
constructor(path, baudRate, callback = null, simulator = null)
Serialport
create a new serialport instance
let serialport = new Serialport();
SerialPortSimulator
SerialPortSimulator
Constructor, create a serialPortSimulator instance
let serialPortSimulator = new SerialPortSimulator();
serialPortSimulator.init
SerialPortSimulator initialization
serialPortSimulator.init(port, ipc = null)
- port: port string
- ipc: default null
Example:
serialPortSimulator.init('xxx')
serialPortSimulator.onOpen
The listening port is open and can be used to perform certain operations
serialPortSimulator.onOpen()
serialPortSimulator.emitData
emit serialPortSimulator data
serialPortSimulator.emitData(data)
- data: emit data
Example:
serialPortSimulator.emitData({user: '1001'})
serialPortSimulator.processCommand
serialPortSimulator.processCommand(command, callback)
Example:
serialPortSimulator.processCommand('cmd-connect', (result, error) => {
if (!error) {
console.log(result)
}
})
serialPortSimulator.onEvent
process event
serialPortSimulator.onEvent(event, params, callback)
serialPortSimulator.getHelp
get help
serialPortSimulator.getHelp()