+17
-13
@@ -39,26 +39,30 @@ const Serial = {
|
||||
// Request a list of available ports, from
|
||||
// the result set, filter for valid paths
|
||||
// via known path pattern match.
|
||||
serialport.list().then(result => {
|
||||
var ports = result.filter(function(val) {
|
||||
var available = true;
|
||||
serialport.list().then(results => {
|
||||
const portPaths = results.reduce((accum, result) => {
|
||||
let available = true;
|
||||
|
||||
// Match only ports that Arduino cares about
|
||||
// Match only portPaths that Arduino cares about
|
||||
// ttyUSB#, cu.usbmodem#, COM#
|
||||
if (!rport.test(val.path)) {
|
||||
if (!rport.test(result.path)) {
|
||||
available = false;
|
||||
}
|
||||
|
||||
// Don't allow already used/encountered usb device paths
|
||||
if (Serial.used.includes(val.path)) {
|
||||
if (Serial.used.includes(result.path)) {
|
||||
available = false;
|
||||
}
|
||||
|
||||
return available;
|
||||
}).map(({comName}) => comName);
|
||||
if (available) {
|
||||
accum.push(result.path);
|
||||
}
|
||||
|
||||
// If no ports are detected...
|
||||
if (!ports.length) {
|
||||
return accum;
|
||||
}, []);
|
||||
|
||||
// If no portPaths are detected...
|
||||
if (!portPaths.length) {
|
||||
|
||||
/* istanbul ignore if */
|
||||
if (IS_TEST_MODE && this.abort) {
|
||||
@@ -90,12 +94,12 @@ const Serial = {
|
||||
return;
|
||||
}
|
||||
|
||||
this.info("Available", chalk.grey(ports));
|
||||
this.info("Available", chalk.grey(portPaths));
|
||||
|
||||
// Get the first available device path
|
||||
// from the list of detected ports
|
||||
// from the list of detected portPaths
|
||||
|
||||
callback.call(this, ports[0]);
|
||||
callback.call(this, portPaths[0]);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
gerado
+84
-87
@@ -235,6 +235,87 @@
|
||||
"integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==",
|
||||
"dev": true
|
||||
},
|
||||
"@serialport/binding-abstract": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/binding-abstract/-/binding-abstract-8.0.6.tgz",
|
||||
"integrity": "sha512-1swwUVoRyQ9ubxrkJ8JPppykohUpTAP4jkGr36e9NjbVocSPfqeX6tFZFwl/IdUlwJwxGdbKDqq7FvXniCQUMw==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"debug": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"@serialport/binding-mock": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/binding-mock/-/binding-mock-8.0.6.tgz",
|
||||
"integrity": "sha512-BIbY5/PsDDo0QWDNCCxDgpowAdks+aZR8BOsEtK2GoASTTcJCy1fBwPIfH870o7rnbH901wY3C+yuTfdOvSO9A==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"@serialport/binding-abstract": "^8.0.6",
|
||||
"debug": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"@serialport/bindings": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/bindings/-/bindings-8.0.6.tgz",
|
||||
"integrity": "sha512-4raWw8U2Qz9vhcPZP7DZamRZW+KEIFjf4FpoJTV85lW+Bzjd52wWmVuUBJNo54m4R8g0f6yXLP+/7/FsKM3opA==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"@serialport/binding-abstract": "^8.0.6",
|
||||
"@serialport/parser-readline": "^8.0.6",
|
||||
"bindings": "^1.5.0",
|
||||
"debug": "^4.1.1",
|
||||
"nan": "^2.14.0",
|
||||
"prebuild-install": "^5.3.0"
|
||||
}
|
||||
},
|
||||
"@serialport/parser-byte-length": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-byte-length/-/parser-byte-length-8.0.6.tgz",
|
||||
"integrity": "sha512-92mrFxFEvq3gRvSM7ANK/jfbmHslz91a5oYJy/nbSn4H/MCRXjxR2YOkQgVXuN+zLt+iyDoW3pcOP4Sc1nWdqQ==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/parser-cctalk": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-cctalk/-/parser-cctalk-8.0.6.tgz",
|
||||
"integrity": "sha512-pqtCYQPgxnxHygiXUPCfgX7sEx+fdR/ObjpscidynEULUq2fFrC5kBkrxRbTfHRtTaU2ii9DyjFq0JVRCbhI0Q==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/parser-delimiter": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-delimiter/-/parser-delimiter-8.0.6.tgz",
|
||||
"integrity": "sha512-ogKOcPisPMlVtirkuDu3SFTF0+xT0ijxoH7XjpZiYL41EVi367MwuCnEmXG+dEKKnF0j9EPqOyD2LGSJxaFmhQ==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/parser-readline": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-readline/-/parser-readline-8.0.6.tgz",
|
||||
"integrity": "sha512-OYBT2mpczh9QUI3MTw8j0A0tIlPVjpVipvuVnjRkYwxrxPeq04RaLFhaDpuRzua5rTKMt89c1y3btYeoDXMjAA==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"@serialport/parser-delimiter": "^8.0.6"
|
||||
}
|
||||
},
|
||||
"@serialport/parser-ready": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-ready/-/parser-ready-8.0.6.tgz",
|
||||
"integrity": "sha512-xcEqv4rc119WR5JzAuu8UeJOlAwET2PTdNb6aIrrLlmTxhvuBbuRFcsnF3BpH9jUL30Kh7a6QiNXIwVG+WR/1Q==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/parser-regex": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-regex/-/parser-regex-8.0.6.tgz",
|
||||
"integrity": "sha512-J8KY75Azz5ZyExmyM5YfUxbXOWBkZCytKgCCmZ966ttwZS0bUZOuoCaZj2Zp4VILJAiLuxHoqc0foi67Fri5+g==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/stream": {
|
||||
"version": "8.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/stream/-/stream-8.0.6.tgz",
|
||||
"integrity": "sha512-ym1PwM0rwLrj90vRBB66I1hwMXbuMw9wGTxqns75U3N/tuNFOH85mxXaYVF2TpI66aM849NoI1jMm50fl9equg==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"debug": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"@types/color-name": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||
@@ -344,9 +425,9 @@
|
||||
"optional": true
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.3.6",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
|
||||
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
|
||||
"version": "2.3.7",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
|
||||
"integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"core-util-is": "~1.0.0",
|
||||
@@ -4476,90 +4557,6 @@
|
||||
"@serialport/parser-regex": "^8.0.4",
|
||||
"@serialport/stream": "^8.0.4",
|
||||
"debug": "^4.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@serialport/binding-abstract": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/binding-abstract/-/binding-abstract-8.0.4.tgz",
|
||||
"integrity": "sha512-1/CWzAk0tIlaf+WkTYD9YogUi6RGurNSV78cHlpkwsJeLY7z3i1rtwapspV5lIziGT/UJPj8pNVcXrv3K2uKZQ==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"debug": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"@serialport/binding-mock": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/binding-mock/-/binding-mock-8.0.4.tgz",
|
||||
"integrity": "sha512-n6XGkZQaEOZk+wvxKSCNwv9wopS3faD1nf97FJJwJXZdtKk7h2XFtScfrol3bBfHanDMLjwx8oLgs29Jtlxmwg==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"@serialport/binding-abstract": "^8.0.4",
|
||||
"debug": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"@serialport/bindings": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/bindings/-/bindings-8.0.4.tgz",
|
||||
"integrity": "sha512-VNEJs6swCw9D4X0M08850RFvj5wUt+YiVQrQ9/ms9sYfuh//S/TsEKKQuVkyYtaTkiyZUgknkzBH/8u74w8aKQ==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"@serialport/binding-abstract": "^8.0.4",
|
||||
"@serialport/parser-readline": "^8.0.4",
|
||||
"bindings": "^1.5.0",
|
||||
"debug": "^4.1.1",
|
||||
"nan": "^2.14.0",
|
||||
"prebuild-install": "^5.3.0"
|
||||
}
|
||||
},
|
||||
"@serialport/parser-byte-length": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-byte-length/-/parser-byte-length-8.0.4.tgz",
|
||||
"integrity": "sha512-5tQQbJZ5KL0eaP750oF1w0iT+E3lFkpDRz/BzONS2jJsGc+Warb+6FH2aWqj1+smz0mAZWdcxNQgJZLrhFy+sw==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/parser-cctalk": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-cctalk/-/parser-cctalk-8.0.4.tgz",
|
||||
"integrity": "sha512-7GsVAlVgk9pAMfuhbEy5m5t1pe8WCdR8HzXjroE8jwXCPHrGT7aY/sjZSTF91fx+qzqhojLiTJyIlf1HwnqM+g==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/parser-delimiter": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-delimiter/-/parser-delimiter-8.0.4.tgz",
|
||||
"integrity": "sha512-4XkOQD2uj7jj4q4CltAM74Rk3HNwCk8pqrgvfAtouA3Pmt0AdrC/n9OrpRY13ioZwv+Yjc54HWU2z9VOOGn45Q==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/parser-readline": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-readline/-/parser-readline-8.0.4.tgz",
|
||||
"integrity": "sha512-STs0WnGKLBwlXbG3CnTiI+kuWxmHBzwcslrWA2su9G5pPYQJpKGCHs2URLDDhYKmGZtzTftCJXEXABpsTXfNxQ==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"@serialport/parser-delimiter": "^8.0.4"
|
||||
}
|
||||
},
|
||||
"@serialport/parser-ready": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-ready/-/parser-ready-8.0.4.tgz",
|
||||
"integrity": "sha512-HXFmYve6mcFnOyX/efLvo7MpvOtD0uJrYWXFvuk0xw3DYRBvabL1zYvK0rYPrWJu32I0M3AFFsldSELm0Ic3mQ==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/parser-regex": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/parser-regex/-/parser-regex-8.0.4.tgz",
|
||||
"integrity": "sha512-uruaOaxBN4E90oqW/Tfb594uP9qPEgL79XXwXUQGbT554EK4k1VVa9TV1JO16qE8EB6Km6XxdEPEVxAx7HKmpg==",
|
||||
"optional": true
|
||||
},
|
||||
"@serialport/stream": {
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@serialport/stream/-/stream-8.0.4.tgz",
|
||||
"integrity": "sha512-Ux6qhFRPGiW/2XYpR6PeZSCidF32eqC5GEpXrjwHGmif0wvuGWjbJVfl1azBvgXcjARWeyGjSwVEcsJbsDX1QQ==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"@serialport/binding-mock": "^8.0.4",
|
||||
"debug": "^4.1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"set-blocking": {
|
||||
|
||||
@@ -11,10 +11,11 @@ exports["Serial"] = {
|
||||
};
|
||||
|
||||
this.sandbox.stub(SerialPort, "list", () => {
|
||||
return this.responses.error ? Promise.reject(this.responses.error) : Promise.resolve(this.responses.list);
|
||||
return this.responses.error ?
|
||||
Promise.reject(this.responses.error) :
|
||||
Promise.resolve(this.responses.list);
|
||||
});
|
||||
|
||||
|
||||
this.sandbox.stub(Firmata, "Board", (port, callback) => {
|
||||
// Necessary to preserve callback invocation order
|
||||
process.nextTick(callback);
|
||||
|
||||
+42
-54
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var serialport = require("serialport");
|
||||
var SerialPort = serialport.SerialPort;
|
||||
var readline = serialport.parsers.readline;
|
||||
var optimist = require("optimist");
|
||||
var async = require("async");
|
||||
const serialport = require("serialport");
|
||||
const SerialPort = serialport.SerialPort;
|
||||
const readline = serialport.parsers.readline;
|
||||
const optimist = require("optimist");
|
||||
const async = require("async");
|
||||
|
||||
/**
|
||||
* This program will setup an xbee 802.15.4 (series 1) to talk serially at 57600bps
|
||||
@@ -14,7 +14,7 @@ var async = require("async");
|
||||
* See http://ftp1.digi.com/support/documentation/90000982_L.pdf
|
||||
*/
|
||||
|
||||
var args = optimist
|
||||
const args = optimist
|
||||
.alias("h", "help")
|
||||
.alias("h", "?")
|
||||
.options("portname", {
|
||||
@@ -50,17 +50,15 @@ if (args.help) {
|
||||
|
||||
if (!args.portname) {
|
||||
console.error("Serial port name is required. \n `-p /dev/PORTNAME` \n Use one of the following");
|
||||
serialport.list().then(data => {
|
||||
data.forEach(function (v) {
|
||||
console.log("\t" + v.path);
|
||||
});
|
||||
serialport.list().then(results => {
|
||||
results.forEach(({path}) => console.log(`\t${path}`));
|
||||
});
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
var guardTime = args.guardtime * 1000;
|
||||
const guardTime = args.guardtime * 1000;
|
||||
|
||||
var openOptions = {
|
||||
const openOptions = {
|
||||
baudRate: args.baud,
|
||||
dataBits: args.databits,
|
||||
parity: args.parity,
|
||||
@@ -68,64 +66,54 @@ var openOptions = {
|
||||
parser: readline("\r")
|
||||
};
|
||||
|
||||
var port = new SerialPort(args.portname, openOptions);
|
||||
const port = new SerialPort(args.portname, openOptions);
|
||||
|
||||
var open = function (cb) {
|
||||
const open = cb => {
|
||||
console.log("port open!");
|
||||
port.once("open", cb);
|
||||
};
|
||||
|
||||
var wait = function (ms) {
|
||||
return function (cb) {
|
||||
setTimeout(cb, ms);
|
||||
};
|
||||
const wait = ms => cb => {
|
||||
setTimeout(cb, ms);
|
||||
};
|
||||
|
||||
var sendCmd = function (str) {
|
||||
return function (cb) {
|
||||
port.once("data", function (data) {
|
||||
if (data === "OK") {
|
||||
cb(null, data);
|
||||
} else {
|
||||
cb(new Error("Not OK"));
|
||||
}
|
||||
});
|
||||
port.write(str);
|
||||
};
|
||||
};
|
||||
|
||||
var readCmd = function (str) {
|
||||
return function (cb) {
|
||||
port.once("data", function (data) {
|
||||
const sendCmd = str => cb => {
|
||||
port.once("data", data => {
|
||||
if (data === "OK") {
|
||||
cb(null, data);
|
||||
});
|
||||
port.write(str);
|
||||
};
|
||||
} else {
|
||||
cb(new Error("Not OK"));
|
||||
}
|
||||
});
|
||||
port.write(str);
|
||||
};
|
||||
|
||||
var exit = function () {
|
||||
const readCmd = str => cb => {
|
||||
port.once("data", data => {
|
||||
cb(null, data);
|
||||
});
|
||||
port.write(str);
|
||||
};
|
||||
|
||||
const exit = () => {
|
||||
console.log("quiting");
|
||||
// port.close();
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
var print = function (str) {
|
||||
return function (cb) {
|
||||
console.log(str);
|
||||
const print = str => cb => {
|
||||
console.log(str);
|
||||
cb();
|
||||
};
|
||||
|
||||
const printCmd = (msg, str) => cb => {
|
||||
readCmd(`${str}\r`)((err, data) => {
|
||||
console.log(`${msg} (${str}): ${data}`);
|
||||
cb();
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
var printCmd = function (msg, str) {
|
||||
return function (cb) {
|
||||
readCmd(str + "\r")(function (err, data) {
|
||||
console.log(msg + " (" + str + "): " + data);
|
||||
cb();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
var systemInfo = function (cb) {
|
||||
const systemInfo = cb => {
|
||||
async.series([
|
||||
print("System Information"),
|
||||
printCmd("\tVersion Info", "ATVR"),
|
||||
@@ -139,7 +127,7 @@ var systemInfo = function (cb) {
|
||||
]);
|
||||
};
|
||||
|
||||
var cmdMode = function (cb) {
|
||||
const cmdMode = cb => {
|
||||
wait(guardTime)(
|
||||
sendCmd("+++")(
|
||||
cb
|
||||
@@ -147,7 +135,7 @@ var cmdMode = function (cb) {
|
||||
);
|
||||
};
|
||||
|
||||
var exitCmdMode = function (cb) {
|
||||
const exitCmdMode = cb => {
|
||||
sendCmd("ATCN\r")(cb);
|
||||
};
|
||||
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário