Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serialport

Package Overview
Dependencies
Maintainers
1
Versions
175
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serialport - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

src/win/enumser.cpp

9

package.json
{
"name": "serialport",
"version": "1.0.8",
"version": "1.1.0",
"description": "Welcome your robotic javascript overlords. Better yet, program them!",

@@ -26,7 +26,6 @@ "author": {

"dependencies": {
"bindings": "0.3.0",
"bindings": "1.1.0",
"async": "0.1.18",
"sf": "0.1.3",
"optimist": "~0.3.4",
"node-gyp": "0.6.2"
"sf": "0.1.6",
"optimist": "~0.3.4"
},

@@ -33,0 +32,0 @@ "devDependencies": {

@@ -15,3 +15,3 @@ <pre>

Version: 1.0.6 - Released August 24, 2012 - Now with Windows Support!!!
Version: 1.1.0 - Released August 24, 2012 - Now with Windows Support!!!

@@ -35,2 +35,3 @@ *****

* [Robotic JavaScript](http://jsconf.eu/2010/speaker/livingroombindmotion_function.html) - The first live presentation of the node-serialport code set as presented at JSConf EU 2010.
* [devicestack](https://github.com/adrai/devicestack) - This module helps you to represent a device and its protocol.

@@ -77,3 +78,5 @@ For getting started with node-serialport, we recommend you begin with the following articles:

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/tty-usbserial1");
var serialPort = new SerialPort("/dev/tty-usbserial1", {
baudrate: 57600
});
</pre>

@@ -91,3 +94,3 @@

* stopbits: Stop Bits, defaults to 1. Must be one of: 1 or 2.
* parity: Parity, defaults to 0. Must be one of: 0, 1, or 2.
* parity: Parity, defaults to 'none'. Must be one of: 'none', 'even', 'mark', 'odd', 'space'
* buffersize: Size of read buffer, defaults to 255. Must be an integer value.

@@ -98,2 +101,43 @@ * parser: The parser engine to use with read data, defaults to rawPacket strategy which just emits the raw buffer as a "data" event. Can be any function that accepts EventEmitter as first parameter and the raw buffer as the second parameter.

open event
----------
You MUST wait for the open event to be emitted before reading/writing to the serial port. The open happens asynchronously so installing 'data' listeners and writing
before the open event might result in... nothing at all.
Assuming you are connected to a serial console, you would for example:
<pre>
serialPort.on("open", function () {
console.log('open');
serialPort.on('data', function(data) {
console.log('data received: ' + data);
});
serialPort.write("ls\n", function(err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
});
</pre>
You can also call the open function, in this case instanciate the serialport with an additional flag.
<pre>
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/tty-usbserial1", {
baudrate: 57600
}, false); // this is the openImmediately flag [default is true]
serialPort.open(function () {
console.log('open');
serialPort.on('data', function(data) {
console.log('data received: ' + data);
});
serialPort.write("ls\n", function(err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
});
</pre>
List Ports

@@ -100,0 +144,0 @@ ----------

@@ -52,6 +52,9 @@ "use strict";

};
function SerialPort (path, options) {
function SerialPort (path, options, openImmediately) {
options = options || {};
options.__proto__ = _options;
openImmediately = (openImmediately === undefined || openImmediately === null) ? true : openImmediately;
var self = this;
if (BAUDRATES.indexOf(options.baudrate) == -1) {

@@ -78,51 +81,37 @@ throw new Error('Invalid "baudrate": ' + options.baudrate);

var self = this;
process.nextTick(function () {
options = options || {};
options.baudRate = options.baudRate || options.baudrate || 9600;
options.dataBits = options.dataBits || options.databits || 8;
options.parity = options.parity || 'none';
options.stopBits = options.stopBits || options.stopbits || 1;
options.bufferSize = options.bufferSize || options.buffersize || 100;
if (!('flowControl' in options)) {
options.flowControl = false;
options = options || {};
options.baudRate = options.baudRate || options.baudrate || 9600;
options.dataBits = options.dataBits || options.databits || 8;
options.parity = options.parity || 'none';
options.stopBits = options.stopBits || options.stopbits || 1;
options.bufferSize = options.bufferSize || options.buffersize || 100;
if (!('flowControl' in options)) {
options.flowControl = false;
}
options.dataCallback = function (data) {
options.parser(self, data);
};
options.errorCallback = function (err) {
self.emit('error', err);
};
options.disconnectedCallback = function () {
if (self.closing) {
return;
}
options.dataCallback = function (data) {
options.parser(self, data);
};
options.errorCallback = function (err) {
self.emit('error', err);
};
options.disconnectedCallback = function () {
if (self.closing) {
return;
}
self.emit('error', new Error("Disconnected"));
self.close();
};
self.emit('error', new Error("Disconnected"));
self.close();
};
if (process.platform == 'win32') {
path = '\\\\.\\' + path;
}
if (process.platform == 'win32') {
path = '\\\\.\\' + path;
}
SerialPortBinding.open(path, options, function (err, fd) {
self.fd = fd;
if (err) {
return self.emit('error', err);
}
if (process.platform !== 'win32') {
self.readStream = fs.createReadStream(path, { bufferSize: options.bufferSize, fd: fd });
self.readStream.on("data", options.dataCallback);
self.readStream.on("error", options.errorCallback);
self.readStream.on("close", function () {
self.close();
});
self.readStream.on("end", function () {
self.emit('end');
});
}
this.options = options;
this.path = path;
self.emit('open');
if (openImmediately) {
process.nextTick(function () {
self.open();
});
});
}
}

@@ -132,2 +121,26 @@

SerialPort.prototype.open = function (callback) {
var self = this;
SerialPortBinding.open(this.path, this.options, function (err, fd) {
self.fd = fd;
if (err) {
return self.emit('error', err);
}
if (process.platform !== 'win32') {
self.readStream = fs.createReadStream(self.path, { bufferSize: self.options.bufferSize, fd: fd });
self.readStream.on("data", self.options.dataCallback);
self.readStream.on("error", self.options.errorCallback);
self.readStream.on("close", function () {
self.close();
});
self.readStream.on("end", function () {
self.emit('end');
});
}
self.emit('open');
if (callback) { callback(err); }
});
};
SerialPort.prototype.write = function (buffer, callback) {

@@ -187,2 +200,3 @@ var self = this;

self.emit('close');
self.removeAllListeners();
self.closing = false;

@@ -205,3 +219,2 @@ });

}
var dirName = "/dev/serial/by-id";

@@ -221,57 +234,46 @@ async.map(files, function (file, callback) {

});
// Suspect code per ticket: #104 removed for deeper inspection.
// fs.readdir("/dev/serial/by-path", function(err_path, paths) {
// if (err_path) {
// if (err.errno === 34) return callback(null, []);
// return console.log(err);
// }
// var dirName, items;
// //check if multiple devices of the same id are connected
// if (files.length !== paths.length) {
// dirName = "/dev/serial/by-path";
// items = paths;
// } else {
// dirName = "/dev/serial/by-id";
// items = files;
// }
// async.map(items, function (file, callback) {
// var fileName = path.join(dirName, file);
// fs.readlink(fileName, function (err, link) {
// if (err) {
// return callback(err);
// }
// link = path.resolve(dirName, link);
// callback(null, {
// comName: link,
// manufacturer: undefined,
// pnpId: file
// });
// });
// }, callback);
}, callback);
});
}
function listOSX (callback) {
child_process.exec('/usr/sbin/system_profiler SPUSBDataType', function (err, stdout, stderr) {
if (err) {
return callback(err);
}
stderr = stderr.trim();
if (stderr.length > 0) {
return callback(new Error(stderr));
}
var lines = stdout.split('\n');
var items = [];
var currentItem = {};
lines.forEach(function (line) {
line = line.trim();
line = line.replace(/\s+/, ' ');
var m;
if (m = line.match(/^Serial Number: (.+)$/)) {
currentItem['serialNumber'] = m[1];
} else if (m = line.match(/^Location ID: (.+)$/)) {
currentItem['locationId'] = m[1];
} else if (m = line.match(/^Product ID: (.+)$/)) {
currentItem['productId'] = m[1];
} else if (m = line.match(/^Vendor ID: (.+)$/)) {
currentItem['vendorId'] = m[1];
} else if (m = line.match(/^Manufacturer: (.+)$/)) {
currentItem['manufacturer'] = m[1];
} else if (/^$/.test(line)) {
if ('serialNumber' in currentItem) {
currentItem['comName'] = "/dev/cu.usbserial-" + currentItem['serialNumber'];
items.push(currentItem);
currentItem = {};
}
}
});
callback(null, items);
});
if (process.platform === 'win32') {
exports.list = SerialPortBinding.list
} else if (process.platform === 'darwin') {
exports.list = SerialPortBinding.list;
} else {
exports.list = listUnix;
}
exports.list = function (callback) {
if (process.platform === 'win32') {
SerialPortBinding.list(callback);
} else if (process.platform === 'darwin') {
listOSX(callback);
} else {
listUnix(callback);
}
};
SerialPort.prototype.flush = function (callback) {

@@ -278,0 +280,0 @@ var self = this;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc