-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot_serial.js
More file actions
27 lines (21 loc) · 761 Bytes
/
robot_serial.js
File metadata and controls
27 lines (21 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const SerialPort = require('serialport')
const Readline = require('@serialport/parser-readline')
// const Readline = SerialPort.parsers.Readline;
const COM_PORT = "COM8";
const BAUD_RATE = 115200;
// Setup COM port
const port = new SerialPort(COM_PORT, { baudRate: BAUD_RATE });
const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
// The open event is always emitted
port.on('open', function () {
// open logic
console.log("Com Port was opened...")
});
// Display incomming serial port data using the READLINE parser
parser.on('data', console.log)
// Open errors will be emitted as an error event
port.on('error', function (err) {
console.log('Error: ', err.message)
});
module.exports.port = port;
module.exports.parser = parser;