From e51a9fb1a19379d2cdbdc28f9d8d5aa9e0f9d38f Mon Sep 17 00:00:00 2001 From: Cheton Wu Date: Mon, 27 Mar 2017 14:01:43 +0800 Subject: [PATCH] Check serialport connection before sending periodical commands --- src/app/controllers/Grbl/GrblController.js | 18 +++++++++++------- .../controllers/Smoothie/SmoothieController.js | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/app/controllers/Grbl/GrblController.js b/src/app/controllers/Grbl/GrblController.js index 17f8a2a9b..0b76ccdaa 100644 --- a/src/app/controllers/Grbl/GrblController.js +++ b/src/app/controllers/Grbl/GrblController.js @@ -391,9 +391,11 @@ class GrblController { return; } - this.actionMask.queryStatusReport = true; - this.actionTime.queryStatusReport = now; - this.serialport.write('?'); + if (this.isOpen()) { + this.actionMask.queryStatusReport = true; + this.actionTime.queryStatusReport = now; + this.serialport.write('?'); + } }; const queryParserState = _.throttle(() => { @@ -416,10 +418,12 @@ class GrblController { return; } - this.actionMask.queryParserState.state = true; - this.actionMask.queryParserState.reply = false; - this.actionTime.queryParserState = now; - this.serialport.write('$G\n'); + if (this.isOpen()) { + this.actionMask.queryParserState.state = true; + this.actionMask.queryParserState.reply = false; + this.actionTime.queryParserState = now; + this.serialport.write('$G\n'); + } }, 500); this.queryTimer = setInterval(() => { diff --git a/src/app/controllers/Smoothie/SmoothieController.js b/src/app/controllers/Smoothie/SmoothieController.js index 96294087b..3369c65f4 100644 --- a/src/app/controllers/Smoothie/SmoothieController.js +++ b/src/app/controllers/Smoothie/SmoothieController.js @@ -345,9 +345,11 @@ class SmoothieController { return; } - this.actionMask.queryStatusReport = true; - this.actionTime.queryStatusReport = now; - this.serialport.write('?'); + if (this.isOpen()) { + this.actionMask.queryStatusReport = true; + this.actionTime.queryStatusReport = now; + this.serialport.write('?'); + } }; const queryParserState = _.throttle(() => { @@ -370,10 +372,12 @@ class SmoothieController { return; } - this.actionMask.queryParserState.state = true; - this.actionMask.queryParserState.reply = false; - this.actionTime.queryParserState = now; - this.serialport.write('$G\n'); + if (this.isOpen()) { + this.actionMask.queryParserState.state = true; + this.actionMask.queryParserState.reply = false; + this.actionTime.queryParserState = now; + this.serialport.write('$G\n'); + } }, 500); this.queryTimer = setInterval(() => {