Last active
January 28, 2022 20:28
-
-
Save rdlauer/8bf61b73d84f25898c41dd6985c8e728 to your computer and use it in GitHub Desktop.
Notecard vs Softcard on Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SerialPort = require('serialport') | |
const Readline = require('@serialport/parser-readline') | |
const port = new SerialPort('/dev/ttys001') // ** softcard ** | |
//const port = new SerialPort('/dev/cu.usbmodemNOTE1') // ** notecard ** | |
const parser = port.pipe(new Readline({ delimiter: '\r' })) | |
port.on('open', showPortOpen); | |
port.on('close', showPortClose); | |
port.on('error', showError); | |
//port.on('data', showSerialData); | |
parser.on('data', showSerialData); | |
function writeRequest() { | |
port.write('{"req":"card.version"}\n'); | |
} | |
function showPortOpen() { | |
console.log('port open. Data rate: ' + port.baudRate); | |
writeRequest(); | |
} | |
function showPortClose() { | |
console.log('port closed.'); | |
} | |
function showError(error) { | |
console.log('Serial port error: ' + error); | |
} | |
function showSerialData(data) { | |
console.log(data.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment