2018-12-19 19:24:06 +00:00
|
|
|
const SerialPort = require('serialport');
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
const DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE = 0x00;
|
|
|
|
const DMXKING_ULTRA_DMX_PRO_START_OF_MSG = 0x7e;
|
|
|
|
const DMXKING_ULTRA_DMX_PRO_END_OF_MSG = 0xe7;
|
|
|
|
const DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ = 0x06;
|
|
|
|
const DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ = 0x64;
|
|
|
|
const DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ = 0x65;
|
|
|
|
// var DMXKING_ULTRA_DMX_PRO_RECV_DMX_PKT = 0x05;
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
function DMXKingUltraDMXPro(deviceId, options = {}) {
|
|
|
|
const self = this;
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
this.options = options;
|
|
|
|
this.universe = Buffer.alloc(513, 0);
|
2018-02-19 11:51:00 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ;
|
|
|
|
if (this.options.port === 'A') {
|
|
|
|
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ;
|
|
|
|
} else if (this.options.port === 'B') {
|
|
|
|
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ;
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
});
|
2017-07-16 16:53:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
DMXKingUltraDMXPro.prototype.sendUniverse = function () {
|
|
|
|
if (!this.dev.writable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const hdr = Buffer.from([
|
|
|
|
DMXKING_ULTRA_DMX_PRO_START_OF_MSG,
|
|
|
|
this.sendDMXReq,
|
|
|
|
(this.universe.length) & 0xff,
|
|
|
|
((this.universe.length) >> 8) & 0xff,
|
|
|
|
DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE,
|
|
|
|
]);
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
const msg = Buffer.concat([
|
|
|
|
hdr,
|
|
|
|
this.universe.slice(1),
|
|
|
|
Buffer.from([DMXKING_ULTRA_DMX_PRO_END_OF_MSG]),
|
|
|
|
]);
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
this.dev.write(msg);
|
|
|
|
};
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
DMXKingUltraDMXPro.prototype.start = () => { };
|
|
|
|
DMXKingUltraDMXPro.prototype.stop = () => { };
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
DMXKingUltraDMXPro.prototype.close = function (cb) {
|
|
|
|
this.dev.close(cb);
|
|
|
|
};
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
DMXKingUltraDMXPro.prototype.update = function (u) {
|
|
|
|
for (const c in u) {
|
|
|
|
this.universe[c] = u[c];
|
|
|
|
}
|
|
|
|
this.sendUniverse();
|
|
|
|
};
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
DMXKingUltraDMXPro.prototype.updateAll = function (v) {
|
|
|
|
for (let i = 1; i <= 512; i++) {
|
|
|
|
this.universe[i] = v;
|
|
|
|
}
|
|
|
|
this.sendUniverse();
|
|
|
|
};
|
|
|
|
|
|
|
|
DMXKingUltraDMXPro.prototype.get = function (c) {
|
|
|
|
return this.universe[c];
|
|
|
|
};
|
2017-07-16 16:53:44 +00:00
|
|
|
|
2018-12-19 19:24:06 +00:00
|
|
|
module.exports = DMXKingUltraDMXPro;
|