serialport
Advanced tools
Comparing version 0.7.5 to 1.0.0
@@ -0,1 +1,8 @@ | ||
Version 1.0.0 | ||
------------- | ||
- Added Windows support thanks to Joe Ferner. | ||
- Merged in the various underlying changes from node-serialport2 complete thanks to Joe Ferner for that! | ||
- Verified against known installations. | ||
Version 0.6.5 | ||
@@ -2,0 +9,0 @@ ------------- |
@@ -1,14 +0,38 @@ | ||
{ "name" : "serialport", | ||
"version" : "0.7.5", | ||
"description" : "Welcome your robotic javascript overlords. Better yet, program them!", | ||
"author": "Chris Williams <voodootikigod@gmail.com>", | ||
"main": "./serialport", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/voodootikigod/node-serialport.git" | ||
{ | ||
"name": "serialport", | ||
"version": "1.0.0", | ||
"description": "Welcome your robotic javascript overlords. Better yet, program them!", | ||
"author": { | ||
"name": "Chris Williams", | ||
"email": "voodootikigod@gmail.com", | ||
"url": "http://www.voodootikigod.com" | ||
}, | ||
"main": "./serialport", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/voodootikigod/node-serialport.git" | ||
}, | ||
"maintainers": [ | ||
{ | ||
"name": "Chris Williams", | ||
"email": "voodootikigod@gmail.com" | ||
}, | ||
"dependencies": { | ||
"bindings": "*" | ||
}, | ||
"engines": { "node": ">= 0.6.0" } | ||
{ | ||
"name": "Joe Ferner", | ||
"email": "joe.ferner@nearinfinity.com" | ||
} | ||
], | ||
"dependencies": { | ||
"bindings": "0.3.0", | ||
"async": "0.1.18", | ||
"sf": "0.1.3", | ||
"optimist": "~0.3.4" | ||
}, | ||
"engines": { | ||
"node": ">= 0.6.0" | ||
}, | ||
"bin": { | ||
"serialportlist": "./bin/serialportList.js", | ||
"serialportterm": "./bin/serialportTerminal.js" | ||
} | ||
} |
@@ -15,3 +15,3 @@ <pre> | ||
Version: 0.3.0 - Released July 28, 2011 | ||
Version: 1.0.0 - Released July 11, 2012 | ||
@@ -18,0 +18,0 @@ ***** |
@@ -6,15 +6,16 @@ "use strict"; | ||
var util = require('util'); | ||
var Buffer = require('buffer').Buffer; | ||
var stream = require('stream'); | ||
var fs = require('fs'); | ||
var net = require('net'); | ||
var serialport_native = require('bindings')('serialport_native.node'); | ||
var IOWatcher = process.binding('io_watcher').IOWatcher; | ||
var Buffer = require('buffer').Buffer; | ||
var SerialPortBinding = require("bindings")("serialport.node"); | ||
var util = require('util'); | ||
var fs = require('fs'); | ||
var stream = require('stream'); | ||
var path = require('path'); | ||
var async = require('async'); | ||
var child_process = require('child_process'); | ||
var BAUDRATES = [500000, 230400, 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1800, 1200, 600, 300, 200, 150, 134, 110, 75, 50]; | ||
var DATABITS = [8, 7, 6, 5]; | ||
var STOPBITS = [1, 2]; | ||
var PARITY = [0, 1, 2]; | ||
var FLOWCONTROL = [0, 1]; | ||
var DATABITS = [8, 7, 6, 5]; | ||
var STOPBITS = [1, 2, 1.5]; | ||
var PARITY = ['none', 'even', 'mark', 'odd', 'space']; | ||
var FLOWCONTROL = [false, true]; | ||
@@ -42,3 +43,2 @@ var parsers = { | ||
// The default options, can be overwritten in the 'SerialPort' constructor | ||
@@ -49,4 +49,4 @@ var _options = { | ||
stopbits: 1, | ||
parity: 0, | ||
flowcontrol: 0, | ||
parity: 'none', | ||
flowcontrol: false, | ||
buffersize: 255, | ||
@@ -77,39 +77,47 @@ parser: parsers.raw | ||
this.port = path; | ||
this.fd = serialport_native.open(this.port, options.baudrate, options.databits, options.stopbits, options.parity, options.flowcontrol); | ||
if (this.fd == -1) { | ||
throw new Error("Could not open serial port"); | ||
} else { | ||
this.readStream = fs.createReadStream(this.port,{bufferSize:options.buffersize}); | ||
var openCallback = ( function (me) { | ||
return (function (fd) { | ||
me.emit("open",fd); | ||
var self = this; | ||
process.nextTick(function () { | ||
options = options || {}; | ||
options.baudRate = options.baudRate || 9600; | ||
options.dataBits = options.dataBits || 8; | ||
options.parity = options.parity || 'none'; | ||
options.stopBits = options.stopBits || 1; | ||
if (!('flowControl' in options)) { | ||
options.flowControl = false; | ||
} | ||
options.bufferSize = options.bufferSize || 100; | ||
options.dataCallback = function (data) { | ||
options.parser(self, data); | ||
}; | ||
options.errorCallback = function (err) { | ||
self.emit('error', err); | ||
}; | ||
options.disconnectedCallback = function () { | ||
self.emit('error', new Error("Disconnected")); | ||
self.close(); | ||
}; | ||
if (process.platform == 'win32') { | ||
path = '\\\\.\\' + path; | ||
} else { | ||
self.readStream = fs.createReadStream(path, { bufferSize: options.bufferSize }); | ||
self.readStream.on("data", options.dataCallback); | ||
self.readStream.on("error", options.errorCallback); | ||
self.readStream.on("close", function () { | ||
self.close(); | ||
}); | ||
})(this); | ||
var dataCallback = (function (me) { | ||
return (function (buffer) { | ||
options.parser(me, buffer) | ||
self.readStream.on("end", function () { | ||
self.emit('end'); | ||
}); | ||
})(this); | ||
var errorCallback = (function (me) { | ||
return (function (err) { | ||
me.emit("error", err); | ||
}); | ||
})(this); | ||
var closeCallback = (function (me) { | ||
return (function () { | ||
me.emit("close"); | ||
}); | ||
})(this); | ||
var endCallback = (function (me) { | ||
return (function () { | ||
me.emit("end"); | ||
}); | ||
})(this); | ||
this.readStream.on("open", openCallback); | ||
this.readStream.on("data", dataCallback); | ||
this.readStream.on("error", errorCallback); | ||
this.readStream.on("close", closeCallback); | ||
this.readStream.on("end", endCallback); | ||
} | ||
} | ||
SerialPortBinding.open(path, options, function (err, fd) { | ||
self.fd = fd; | ||
if (err) { | ||
return self.emit('error', err); | ||
} | ||
self.emit('open'); | ||
}); | ||
}); | ||
} | ||
@@ -119,43 +127,143 @@ | ||
SerialPort.prototype.close = function () { | ||
if (this.fd) { | ||
serialport_native.close(this.fd); | ||
this.fd = null; | ||
SerialPort.prototype.write = function (buffer, callback) { | ||
var self = this; | ||
if (!this.fd) { | ||
if (callback) { | ||
return callback(new Error("Serialport not open.")); | ||
} else { | ||
return; | ||
} | ||
} | ||
this.readStream.destroy(); | ||
if (!Buffer.isBuffer(buffer)) { | ||
buffer = new Buffer(buffer); | ||
} | ||
SerialPortBinding.write(this.fd, buffer, function (err, results) { | ||
if (err) { | ||
self.emit('error', err); | ||
} | ||
if (callback) { | ||
callback(err, results); | ||
} | ||
}); | ||
}; | ||
SerialPort.prototype.close = function (callback) { | ||
var fd = this.fd; | ||
this.fd = 0; | ||
SerialPort.prototype.write = function (b) { | ||
if (Buffer.isBuffer(b)) | ||
serialport_native.write(this.fd, b); | ||
else | ||
serialport_native.write(this.fd, new Buffer(b)); | ||
if (this.closing) { | ||
return; | ||
} | ||
if (!fd) { | ||
if (callback) { | ||
return callback(new Error("Serialport not open.")); | ||
} else { | ||
return; | ||
} | ||
} | ||
this.closing = true; | ||
try { | ||
var self = this; | ||
if (self.readStream) { | ||
self.readStream.destroy(); | ||
} | ||
SerialPortBinding.close(fd, function (err) { | ||
if (err) { | ||
self.emit('error', err); | ||
} | ||
if (callback) { | ||
callback(err); | ||
} | ||
self.emit('close'); | ||
this.closing = false; | ||
}); | ||
} catch (ex) { | ||
this.closing = false; | ||
throw ex; | ||
} | ||
}; | ||
function listUnix (callback) { | ||
fs.readdir("/dev/serial/by-id", function (err, files) { | ||
if (err) { | ||
// if this directory is not found this could just be because it's not plugged in | ||
if (err.errno === 34) { | ||
return callback(null, []); | ||
} | ||
return console.log(err); | ||
} | ||
SerialPort.prototype.end = function(buf, enc) { | ||
if (buf) { | ||
this.write(buf, enc); | ||
} | ||
this.close(); | ||
var dirName = "/dev/serial/by-id"; | ||
async.map(files, 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); | ||
}); | ||
} | ||
SerialPort.prototype.set_baud_rate = function(baud_rate) { | ||
if (this.fd) { | ||
serialport_native.set_baud_rate(this.fd, baud_rate); | ||
} else { | ||
throw new Error("Can't set baud rate; invalid file descriptor"); | ||
} | ||
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); | ||
}); | ||
} | ||
SerialPort.prototype.set_dtr = function(boolean_value) { | ||
if (this.fd) { | ||
serialport_native.set_dtr(this.fd, boolean_value); | ||
exports.list = function (callback) { | ||
if (process.platform === 'win32') { | ||
SerialPortBinding.list(callback); | ||
} else if (process.platform === 'darwin') { | ||
listOSX(callback); | ||
} else { | ||
throw new Error("Can't set or clear DTR; invalid file descriptor"); | ||
listUnix(callback); | ||
} | ||
} | ||
}; | ||
module.exports.SerialPort = SerialPort; | ||
module.exports.parsers = parsers; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
223494
33
478
1
0
4
1
4
+ Addedasync@0.1.18
+ Addedoptimist@~0.3.4
+ Addedsf@0.1.3
+ Addedasync@0.1.18(transitive)
+ Addedbindings@0.3.0(transitive)
+ Addedoptimist@0.3.7(transitive)
+ Addedsf@0.1.3(transitive)
+ Addedwordwrap@0.0.3(transitive)
- Removedbindings@1.5.0(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
Updatedbindings@0.3.0