Last active
August 29, 2015 14:23
-
-
Save HERRKIN/c4378a6b026307cc61a6 to your computer and use it in GitHub Desktop.
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
// I have app.js where I have this code somewhere | |
//an array of modems I read from udev, in this case 2 modems | |
mod = [ { DEVNAME: '/dev/ttyUSB3', | |
ID_MODEL: 'E398 LTE/UMTS/GSM Modem/Networkcard' }, | |
{ DEVNAME: '/dev/ttyUSB0', | |
ID_MODEL: 'E173s 3G broadband stick (modem on)' } ] | |
//then I do | |
mod.forEach(function (dev) { | |
modeminit(dev); | |
}) | |
//modeminit function looks like this | |
function modeminit (mo) { | |
var c = config | |
c.serial = {} | |
c.serial.port = mo.DEVNAME | |
var mod = modems[mo.DEVNAME] = new modem(c); | |
mod.openSerial() | |
// and in modem.js | |
var Modem = function (conf) { | |
this.config = conf; | |
} | |
Modem.prototype.openSerial = function(){ | |
l(this.config.serial.port+' opening \n\n'.yellow)//l returns console.log(arg) | |
this.s = new serial(this.config.serial.port); | |
var m = this; | |
this.s.serialPort.on('open',function (d) { | |
l('opened '.yellow + m.config.serial.port) | |
}) | |
} | |
//the output on this is | |
/dev/ttyUSB3 opening | |
/dev/ttyUSB0 opening | |
opened /dev/ttyUSB0 | |
opened /dev/ttyUSB0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment