Skip to content

Commit

Permalink
Fixed error handling when serialport cannot make a connection
Browse files Browse the repository at this point in the history
  • Loading branch information
rooi committed Jun 13, 2021
1 parent ff20ef2 commit 8a6519c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
"type": "integer",
"default": -79,
"required": true
},
"timeout": {
"title": "Timeout Between commands",
"type": "integer",
"default": 500,
"required": false
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ module.exports = function(homebridge) {
this.log("sendCommand: " + command);

if(!this.serialPort.isOpen){
this.log.warn("serialPort is not open... open it");
this.open();
this.log.warn("serialPort is not open... trying to open it");
this.open(function(result, error) {
if(error && callback) callback(result,error);
});
}

this.serialPort.write(command);
Expand Down Expand Up @@ -212,12 +214,12 @@ module.exports = function(homebridge) {
this.serialPort.open(function (error) {
if(error) {
this.log.error("Error when opening serialport: " + error);
if(callback) callback(0,error);
if(callback) callback(0, error);
}
else {
this.log("Set auto status feedback to full");
setTimeout(function() {this.sendCommand("@AST:F\r");}.bind(this), 5000);
if(callback) callback();
if(callback) callback(1);
}
}.bind(this));
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-marantz-rs232",
"version": "0.2.2",
"version": "0.2.3",
"description": "Marantz rs232 receiver plugin for homebridge: https://github.com/nfarina/homebridge",
"license": "ISC",
"keywords": [
Expand Down

0 comments on commit 8a6519c

Please sign in to comment.