Last active
June 26, 2018 16:01
-
-
Save joepie91/1e5d84fc1c32995bea10131fd7c7d9cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// file: serial.js | |
const SerialPort = require('serialport') | |
module.exports = function() { | |
const port = SerialPort('path/to/serial/port') | |
const e = new events.EventEmitter() | |
// listen for incoming serial data | |
port.on('data', function (data) { | |
// emit event 'serialdata' | |
e.emit('serialdata', data); | |
}) | |
return e | |
} | |
// file app.js | |
const serial = require('./serial') | |
const events = require('events') | |
const e = serial() | |
e.on('serialdata', ()=>{ | |
console.log('Serial data received') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment