Skip to content

Instantly share code, notes, and snippets.

@karlosgliberal
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save karlosgliberal/ea642bd38716dbb0d470 to your computer and use it in GitHub Desktop.

Select an option

Save karlosgliberal/ea642bd38716dbb0d470 to your computer and use it in GitHub Desktop.
Definición básica del modulo serialport
var serialport = require("serialport"), //modulo puerto serie
SerialPort = serialport.SerialPort,
portName = process.argv[2],
ledState = false;
//Configuración básica del puerto y su tasa de transferencia (dependerá de tu sistema)
var myPort = new SerialPort("/dev/ttyACM0", {
baudRate: 115200,
options: false,
parser: serialport.parsers.readline("\r\n")
});
// Llamada cuendo el pueto serie esta abierto:
myPort.on('open', function() {
console.log('port open');
//Definimos la pripeidad abierta como verdadera:
myPort.options.open = true;
});
// Llamada cuando hay datos en el puerto serie:
myPort.on('data', function (data) {
//Pintamos estas datos en el output:
console.log('data: ', data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment