fix send queueing
This commit is contained in:
parent
e38d512322
commit
9fe6e63e76
1 changed files with 9 additions and 3 deletions
|
|
@ -90,6 +90,8 @@ class FFControl {
|
||||||
})
|
})
|
||||||
.on("connect", () => {
|
.on("connect", () => {
|
||||||
console.log({connected: [host, port]});
|
console.log({connected: [host, port]});
|
||||||
|
this.connected = true;
|
||||||
|
this.doSendTimer();
|
||||||
})
|
})
|
||||||
.on("line", line => {
|
.on("line", line => {
|
||||||
line = line.toString();
|
line = line.toString();
|
||||||
|
|
@ -99,8 +101,9 @@ class FFControl {
|
||||||
} else {
|
} else {
|
||||||
console.log({reply_no_cmd: this.output});
|
console.log({reply_no_cmd: this.output});
|
||||||
}
|
}
|
||||||
this.doSendTimer();
|
|
||||||
this.output = [];
|
this.output = [];
|
||||||
|
this.timer = null;
|
||||||
|
this.doSendTimer();
|
||||||
} else {
|
} else {
|
||||||
this.output.push(line);
|
this.output.push(line);
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +121,7 @@ class FFControl {
|
||||||
|
|
||||||
socket.lineBuffer = new LineBuffer(socket);
|
socket.lineBuffer = new LineBuffer(socket);
|
||||||
|
|
||||||
|
this.connected = false;
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.queue = [];
|
this.queue = [];
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
|
|
@ -131,8 +135,8 @@ class FFControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
doSendTimer() {
|
doSendTimer() {
|
||||||
if (this.timer) return;
|
if (!this.connected || this.timer) return;
|
||||||
if (this.queue.length > 0) setTimeout(() => {
|
if (this.queue.length > 0) this.timer = setTimeout(() => {
|
||||||
this.doSend()
|
this.doSend()
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -150,6 +154,8 @@ class GXSender {
|
||||||
const buffer = fs.readFileSync(file);
|
const buffer = fs.readFileSync(file);
|
||||||
const ctrl = new FFControl(host, port);
|
const ctrl = new FFControl(host, port);
|
||||||
ctrl.sendCommand("M601 S1", lines => { console.log(lines) });
|
ctrl.sendCommand("M601 S1", lines => { console.log(lines) });
|
||||||
|
ctrl.sendCommand("M115", lines => { console.log(lines) });
|
||||||
|
ctrl.sendCommand("M27", lines => { console.log(lines) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue