Skip to content

Commit

Permalink
@wip Upgrade to Serialport 4x
Browse files Browse the repository at this point in the history
To be used in testing. By the 4.0.0 release I hope to have browser serialport in parity.

SerialPort 4.0.0-rc1 is out and brings performance improvements, bug fixes and a few changes to the api. It's now out of sync with `browser-serialport` but not in a major way. garrows/browser-serialport#40

I suspect this upgrade won't have any far reaching effects as firmata uses only a fraction of the functions of SerialPort by default. The coms changes will be cleaner when browser serial port catches up.
  • Loading branch information
reconbot committed Jun 17, 2016
1 parent 2a9cc3e commit 9aa1813
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
16 changes: 6 additions & 10 deletions lib/com.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,21 @@ Mock.prototype.close = function () {
this.isClosed = true;
};


var stub = {
SerialPort: Mock,
list: function() {},
};

var com;
Mock.list = function();

try {
if (process.browser || parseFloat(process.versions.nw) >= 0.13) {
com = require("browser-serialport");
var browserSerialport = require("browser-serialport");
com = browserSerialport.SerialPort;
com.list = browserSerialport.list;
} else {
com = global.IS_TEST_MODE ? stub : require("serialport");
com = global.IS_TEST_MODE ? Mock : require("serialport");
}
} catch (err) {}

if (com == null) {
if (global.IS_TEST_MODE) {
com = stub;
com = Mock;
} else {
console.log("It looks like serialport didn't compile properly. This is a common problem and its fix is well documented here https://github.com/voodootikigod/node-serialport#to-install");
throw "Missing serialport dependency";
Expand Down
6 changes: 3 additions & 3 deletions lib/firmata.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Emitter = require("events").EventEmitter;
// Internal Dependencies
var Encoder7Bit = require("./encoder7bit");
var OneWireUtils = require("./onewireutils");
var com = require("./com");
var SerialPort = require("./com");

// Program specifics
var i2cActive = new Map();
Expand Down Expand Up @@ -519,7 +519,7 @@ function Board(port, options, callback) {
if (typeof port === "object") {
this.transport = port;
} else {
this.transport = new com.SerialPort(port, settings.serialport);
this.transport = new SerialPort(port, settings.serialport);
}

// For backward compat
Expand Down Expand Up @@ -1920,7 +1920,7 @@ Board.isAcceptablePort = function(port) {
*/

Board.requestPort = function(callback) {
com.list(function(error, ports) {
SerialPort.list(function(error, ports) {
var port = ports.find(function(port) {
if (Board.isAcceptablePort(port)) {
return port;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"browser-serialport": "*",
"es6-shim": "^0.33.6",
"serialport": "^3.0.0"
"serialport": "4.0.0-rc1"
},
"scripts": {
"test": "grunt",
Expand Down

0 comments on commit 9aa1813

Please sign in to comment.