2018-12-19 19:24:06 +00:00
|
|
|
const SerialPort = require('serialport');
|
2013-11-17 00:41:27 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
const ENTTEC_PRO_DMX_STARTCODE = 0x00;
|
|
|
|
const ENTTEC_PRO_START_OF_MSG = 0x7e;
|
|
|
|
const ENTTEC_PRO_END_OF_MSG = 0xe7;
|
|
|
|
const ENTTEC_PRO_SEND_DMX_RQ = 0x06;
|
|
|
|
// var ENTTEC_PRO_RECV_DMX_PKT = 0x05;
|
2012-09-01 12:17:39 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
function EnttecUSBDMXPRO(deviceId, options = {}) {
|
|
|
|
const self = this;
|
2012-09-01 12:17:39 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
this.universe = Buffer.alloc(513, 0);
|
2018-02-19 11:51:00 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
this.dev = new SerialPort(deviceId, {
|
|
|
|
'baudRate': 250000,
|
|
|
|
'dataBits': 8,
|
|
|
|
'stopBits': 2,
|
|
|
|
'parity': 'none',
|
|
|
|
}, err => {
|
|
|
|
if (!err) {
|
|
|
|
self.sendUniverse();
|
|
|
|
}
|
|
|
|
});
|
2013-11-17 00:41:27 +00:00
|
|
|
}
|
2013-11-16 16:35:17 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.sendUniverse = function () {
|
|
|
|
if (!this.dev.writable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const hdr = Buffer.from([
|
|
|
|
ENTTEC_PRO_START_OF_MSG,
|
|
|
|
ENTTEC_PRO_SEND_DMX_RQ,
|
|
|
|
(this.universe.length) & 0xff,
|
|
|
|
((this.universe.length) >> 8) & 0xff,
|
|
|
|
ENTTEC_PRO_DMX_STARTCODE,
|
|
|
|
]);
|
2013-11-17 00:41:27 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
const msg = Buffer.concat([
|
|
|
|
hdr,
|
|
|
|
this.universe.slice(1),
|
|
|
|
Buffer.from([ENTTEC_PRO_END_OF_MSG]),
|
|
|
|
]);
|
2013-11-17 00:41:27 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
this.dev.write(msg);
|
|
|
|
};
|
2015-05-15 12:34:24 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.start = () => { };
|
|
|
|
EnttecUSBDMXPRO.prototype.stop = () => { };
|
2015-05-15 12:34:24 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.close = function (cb) {
|
|
|
|
this.dev.close(cb);
|
|
|
|
};
|
2013-11-17 00:41:27 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.update = function (u) {
|
|
|
|
for (const c in u) {
|
|
|
|
this.universe[c] = u[c];
|
|
|
|
}
|
|
|
|
this.sendUniverse();
|
|
|
|
};
|
2014-04-24 17:53:07 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.updateAll = function (v) {
|
|
|
|
for (let i = 1; i <= 512; i++) {
|
|
|
|
this.universe[i] = v;
|
|
|
|
}
|
|
|
|
this.sendUniverse();
|
|
|
|
};
|
|
|
|
|
|
|
|
EnttecUSBDMXPRO.prototype.get = function (c) {
|
|
|
|
return this.universe[c];
|
|
|
|
};
|
2013-11-17 00:41:27 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
module.exports = EnttecUSBDMXPRO;
|