Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
////////////////////////////////////////////////////////
// Use the cool library //
// git://github.com/voodootikigod/node-serialport.git //
// to send break condition. //
////////////////////////////////////////////////////////
var com = require("serialport");
var serialPort = new com.SerialPort("/dev/tty.usbserial-A700eTSd", {
baudrate: 115200,
parser: com.parsers.readline('\r\n')
}, false);
serialPort.on('open',function() {
console.log('Port open');
});
serialPort.on('data', function(data) {
console.log(data);
});
function asserting() {
console.log('asserting');
serialPort.set({brk:true}, function(err, something) {
console.log('asserted');
function openPort(port) {
var serialPort = new serial.SerialPort(port.comName, {
baudrate: port.baudrate
}, false);
// TODO: Retry open
serialPort.open(function (err) {
if (err) throw err;
console.log('Port opened:', port.comName);
makeTcpBridge(serialPort);
});
}
var read = function(callback) { // this should be 'setup'
debug("in read connecting to " + portname);
state = "connecting";
conn = new com.SerialPort(portname, {
baudrate: BAUD_RATE, disconnectedCallback:function () { callback("disconnected") },
parser: com.parsers.readline("\n")
});
conn.on("error", function(err) {
debug("in read " + err);
debug("Cannot connect to " + portname);
state = "error";
callback(state);
});
conn.on("open", function () {
debug("in read open");
state = "read"; // state should be 'open'
callback("");
});
conn.on("closed", function () {
debug("in read closed");
function CUL_FS20() {
this.serialPort = new SerialPort("/dev/ttyACM0", {
baudrate: 9600
});
this.CUL_connected = false;
this.commands = {
// List of commands
// http://fhz4linux.info/tiki-index.php?page=FS20%20Protocol
// http://www.eecs.iu-bremen.de/archive/bsc-2008/stefanovIvan.pdf
'off' : '00',
'dim06' : '01', // Switch to Brightness level 1 (min.)
'dim12' : '02',
'dim18' : '03',
'dim25' : '04',
'dim31' : '05',
'dim37' : '06',
'dim43' : '07',
$scope.serialOpen = function () {
if (!$scope.port) {
var openOptions = {
baudRate: $scope.serialdata.selectedBaudRate,
dataBits: 8,
parity: 'none',
stopBits: 1
};
$scope.port = new SerialPort.SerialPort($scope.serialdata.selectedPort, openOptions, false);
$scope.port.on('open', function (error) {
if (!error) {
$scope.port.on('data', function (data) {
div_terminal.innerHTML += data.toString();
});
$scope.port.on('error', function (err) {
console.log(err);
});
$scope.serialClear();
$scope.port.set({rts:false, dtr:false}, function(err, results) { });
$scope.port.flush();
document.getElementById('serial-status').style.fill = '#3DD738';
_sphero.open = function(device, callback) {
_serialPort = new serialPort.SerialPort(device, {
parser:responseParser.spheroResponseParser()
}, true, function(err){
if (err){
if (callback && typeof(callback) == 'function'){
callback(err);
}
}});
_serialPort.on('open', function() {
_serialPort.on('data', function(packet) {
_sphero.emit('packet', packet);
switch (packet.SOP2) {
case 0xFF:
_sphero.emit('message', packet);
break;
case 0xFE:
function run(env){
if(!env.port){
out.error('Serial port not specified.');
process.exit(1);
}
var serialPort = new SerialPort(env.port, {
baudrate: env.baud
});
serialPort.on("open", function () {
out.log('Console open, use Ctr-c to exit.\r\n');
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function() {
var chunk = process.stdin.read();
if (chunk !== null) {
serialPort.write(chunk.toString());
}
});
process.stdin.on('end', function() {
getComName(function(err, comName) {
if(err) {
setSerialStatus('not found, searching');
reconnect();
return;
}
serial = new serialport.SerialPort(comName, {
baudrate: 115200,
parser: serialport.parsers.readline('\r'),
disconnectedCallback: function() {
setSerialStatus('disconnected, reconnecting');
reconnect();
}
}, false);
serial.on('data', dataCallback);
serial.open(function(err) {
if(err) {
setSerialStatus('error connecting, reconnecting');
reconnect();
} else {
setSerialStatus('connected');
startupSequence();
}
constructor(port, baudrate) {
this.options = _.merge({}, this.options, { port: port, baudrate: baudrate });
this.serialport = new serialport.SerialPort(this.options.port, {
baudrate: this.options.baudrate,
parser: serialport.parsers.readline('\n')
}, false);
this.grbl = new Grbl(this.serialport);
this.grbl.on('raw', (data) => {
});
this.grbl.on('status', (status) => {
});
this.grbl.on('statuschange', (status) => {
});
this.grbl.on('parserstate', (parsestate) => {
});
this.grbl.on('parserstatechange', (parsestate) => {
});
function SerialComms (port) {
this._echoBuffer = '';
this._responseBuffer = '';
this._port = new SerialPort(port, {
baudrate: 9600,
disconnectedCallback: process.exit
}, false);
this._initPort();
}