Skip to content

Instantly share code, notes, and snippets.

@joepie91 joepie91/app.js
Last active Jun 26, 2018

Embed
What would you like to do?
// 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
You can’t perform that action at this time.