Skip to content

Commit

Permalink
fixes Windows PNP ID regex
Browse files Browse the repository at this point in the history
  • Loading branch information
thingersoft committed Jun 12, 2018
1 parent 9a64f2e commit 595fc8a
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions lib/g2core-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ class G2coreAPI extends EventEmitter {
// See https://github.com/synthetos/TinyG/wiki/TinyG-Status-Codes#status-report-enumerations
// for more into about stat codes.

// 3 program stop or no more blocks (M0, M1, M60)
// 4 program end via M2, M30
// 3 program stop or no more blocks (M0, M1, M60)
// 4 program end via M2, M30
if (sr.stat == 3 || sr.stat == 4) {
// if (this.doneSending) {
// this.emit('doneSending');
// }

// 2 machine is in alarm state (shut down)
// 2 machine is in alarm state (shut down)
} else if (sr.stat == 2) {
// Fatal error! Shut down!
// this.emit('doneSending', sr);
Expand Down Expand Up @@ -611,15 +611,15 @@ class G2coreAPI extends EventEmitter {
this.ignoredResponses++;
}
this._write(value);
// handle flush command
if(typeof value === 'string' && value.match(/%+/)) {
this._resetLinesRequested();
this.linesSent = 0;
this.ignoredResponses = 0;
this.lineBuffer.length = 0;
}
// handle flush command
if(typeof value === 'string' && value.match(/%+/)) {
this._resetLinesRequested();
this.linesSent = 0;
this.ignoredResponses = 0;
this.lineBuffer.length = 0;
}
return;
}

Expand Down Expand Up @@ -902,8 +902,8 @@ class G2coreAPI extends EventEmitter {
if (sr.stat) {
// console.log("sr.stat: " + this.lineCountToSend)

// 3 program stop or no more blocks (M0, M1, M60)
// 4 program end via M2, M30
// 3 program stop or no more blocks (M0, M1, M60)
// 4 program end via M2, M30
if (sr.stat == 3 || sr.stat == 4) {
if (sr.stat == 4) {
if (fileEnded && doneSending) {
Expand All @@ -912,7 +912,7 @@ class G2coreAPI extends EventEmitter {
stopOrEndStat = true;
}

// 2 machine is in alarm state (shut down)
// 2 machine is in alarm state (shut down)
} else if (sr.stat == 2) {
// If the machine is in error, we're done no matter what
if (!this.timedSendsOnly) {
Expand Down Expand Up @@ -1206,20 +1206,27 @@ class G2coreAPI extends EventEmitter {

for (let i = 0; i < results.length; i++) {
let item = results[i];
let x;

if (process.platform === 'win32') {
// Windows:
// pnpId: USB\VID_1D50&PID_606D&MI_00\6&3B3CEA53&0&0000
// pnpId: USB\VID_1D50&PID_606D&MI_02\6&3B3CEA53&0&0002
// pnpId: USB\VID_1D50&PID_606D\0084-D639-0084-08C6

// WARNING -- explicit test against VIP/PID combo.
if ((x = item.pnpId.match(/^USB\\VID_([0-9A-Fa-f]+)&PID_([0-9A-Fa-f]+)&MI_([0-9]+)\\(.*)$/)) && // eslint-disable-line
if ((x = item.pnpId.match(/^USB\\VID_([0-9A-Fa-f]+)&PID_([0-9A-Fa-f]+)(?:(?:&MI_([0-9]+)\\(.*))|(?:\\(.*)))$/)) && // eslint-disable-line
(x[1] == '1D50') && (x[2] == '606D')
) {
let serialNumber;
// let vendor = x[1]; // never used
// let pid = x[2]; // never used
let theRest = x[4].split('&');
let serialNumber = theRest[1];
if(x[4]) {
let theRest = x[4].split('&');
serialNumber = theRest[1];
} else {
serialNumber = x[5];
}

if (
(g2s.length > 0) &&
Expand Down

0 comments on commit 595fc8a

Please sign in to comment.