Skip to content

Commit 28e2e98

Browse files
committed
Handle the error that throws from board
1 parent 0727475 commit 28e2e98

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/core/Board.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -549,20 +549,26 @@
549549
};
550550

551551
proto.sendDigitalData = function (pin, value) {
552-
var portNum = Math.floor(pin / 8);
553-
554-
if (value === Pin.HIGH) {
555-
// Set the bit
556-
this._digitalPort[portNum] |= (value << (pin % 8));
557-
} else if (value === Pin.LOW) {
558-
// Clear the bit
559-
this._digitalPort[portNum] &= ~(1 << (pin % 8));
560-
} else {
561-
// Should not happen...
562-
throw new Error('Invalid value passed to sendDigital, value must be 0 or 1.');
563-
}
552+
try {
553+
var portNum = Math.floor(pin / 8);
554+
555+
if (value === Pin.HIGH) {
556+
// Set the bit
557+
this._digitalPort[portNum] |= (value << (pin % 8));
558+
} else if (value === Pin.LOW) {
559+
// Clear the bit
560+
this._digitalPort[portNum] &= ~(1 << (pin % 8));
561+
} else {
562+
// Should not happen...
563+
throw new Error('Invalid value passed to sendDigital, value must be 0 or 1.');
564+
}
564565

565-
this.sendDigitalPort(portNum, this._digitalPort[portNum]);
566+
this.sendDigitalPort(portNum, this._digitalPort[portNum]);
567+
} catch (err) {
568+
console.error('Board -> sendDigitalData, msg:', err.message, 'value:', value);
569+
this.emit(BoardEvent.ERROR, err);
570+
setImmediate(this.disconnect.bind(this));
571+
}
566572
};
567573

568574
proto.sendServoData = function (pin, value) {

0 commit comments

Comments
 (0)