Created
March 7, 2019 20:05
-
-
Save nucleardreamer/c7fb56bf52fac0ba7fd7fb4346e06100 to your computer and use it in GitHub Desktop.
Southco EA-A06-01 USB Controller
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 port = new SerialPort('/dev/ttyUSB0', { | |
baudRate: 38400, | |
dataBits: 8, | |
stopBits: 1, | |
parity: 'none' | |
}) | |
const parseBufPayload = data => data.toString().replace(/[^a-zA-Z0-9]/gi, '') | |
function write (cmd, lockNum = '', delay = 0, cb = function () {}) { | |
setTimeout(function () { | |
port.flush(function (err) { | |
if (err) console.log('Flush err', err.message) | |
port.write(`${cmd}${lockNum}\r`, err => { | |
if (err) console.log('Error on write: ', err.message) | |
cb() | |
}) | |
}) | |
}, delay) | |
} | |
port.on('data', function (data) { | |
let parsed = parseBufPayload(data) | |
console.log('PAYLOAD', parsed) | |
}) | |
port.on('error', function(err) { | |
console.log('Error: ', err.message) | |
}) | |
// changes status mode for monitoring latch status | |
// write('changemode') | |
// toggle power to all latches | |
// write('power') | |
// write a command, the lock number, and then optional delay | |
write('status', 1, 0) | |
write('open', 1, 1000) | |
write('status', 1, 5000) | |
write('close', 1, 10000) | |
write('status', 1, 15000, function () { | |
process.exit(0) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment