2017-07-16 16:53:44 +00:00
|
|
|
"use strict"
|
|
|
|
|
|
|
|
var SerialPort = require("serialport")
|
|
|
|
|
|
|
|
var DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE = 0x00
|
|
|
|
, DMXKING_ULTRA_DMX_PRO_START_OF_MSG = 0x7e
|
|
|
|
, DMXKING_ULTRA_DMX_PRO_END_OF_MSG = 0xe7
|
|
|
|
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ = 0x06
|
|
|
|
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ = 0x64
|
|
|
|
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ = 0x65
|
|
|
|
, DMXKING_ULTRA_DMX_PRO_RECV_DMX_PKT = 0x05
|
|
|
|
;
|
|
|
|
|
|
|
|
function DMXKingUltraDMXPro(device_id, options) {
|
|
|
|
var self = this
|
|
|
|
this.options = options || {}
|
2018-11-14 20:47:25 +00:00
|
|
|
this.universe = Buffer.alloc(513, 0);
|
2018-02-19 11:51:00 +00:00
|
|
|
|
2017-07-16 16:53:44 +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
|
|
|
|
2017-07-16 16:53:44 +00:00
|
|
|
this.dev = new SerialPort(device_id, {
|
2018-01-10 20:28:44 +00:00
|
|
|
'baudRate': 250000,
|
2018-02-19 11:51:00 +00:00
|
|
|
'dataBits': 8,
|
|
|
|
'stopBits': 2,
|
2017-07-16 16:53:44 +00:00
|
|
|
'parity': 'none'
|
|
|
|
}, function(err) {
|
|
|
|
if(!err) {
|
|
|
|
self.send_universe()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
DMXKingUltraDMXPro.prototype.send_universe = function() {
|
2018-01-10 20:28:44 +00:00
|
|
|
if(!this.dev.writable) {
|
2017-07-16 16:53:44 +00:00
|
|
|
return
|
|
|
|
}
|
2018-11-14 20:47:25 +00:00
|
|
|
var hdr = Buffer.from([
|
2017-07-16 16:53:44 +00:00
|
|
|
DMXKING_ULTRA_DMX_PRO_START_OF_MSG,
|
|
|
|
this.sendDMXReq,
|
2017-07-30 15:17:05 +00:00
|
|
|
(this.universe.length) & 0xff,
|
|
|
|
((this.universe.length) >> 8) & 0xff,
|
2017-07-16 16:53:44 +00:00
|
|
|
DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE
|
|
|
|
])
|
|
|
|
|
|
|
|
var msg = Buffer.concat([
|
|
|
|
hdr,
|
2017-07-30 15:17:05 +00:00
|
|
|
this.universe.slice(1),
|
2018-11-14 20:47:25 +00:00
|
|
|
Buffer.from([DMXKING_ULTRA_DMX_PRO_END_OF_MSG])
|
2017-07-16 16:53:44 +00:00
|
|
|
])
|
|
|
|
this.dev.write(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
DMXKingUltraDMXPro.prototype.start = function() {}
|
|
|
|
DMXKingUltraDMXPro.prototype.stop = function() {}
|
|
|
|
|
|
|
|
DMXKingUltraDMXPro.prototype.close = function(cb) {
|
|
|
|
this.dev.close(cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
DMXKingUltraDMXPro.prototype.update = function(u) {
|
|
|
|
for(var c in u) {
|
|
|
|
this.universe[c] = u[c]
|
|
|
|
}
|
|
|
|
this.send_universe()
|
|
|
|
}
|
|
|
|
|
|
|
|
DMXKingUltraDMXPro.prototype.updateAll = function(v){
|
2017-07-30 15:17:05 +00:00
|
|
|
for(var i = 1; i <= 512; i++) {
|
2017-07-16 16:53:44 +00:00
|
|
|
this.universe[i] = v
|
|
|
|
}
|
|
|
|
this.send_universe()
|
|
|
|
}
|
|
|
|
|
|
|
|
DMXKingUltraDMXPro.prototype.get = function(c) {
|
|
|
|
return this.universe[c]
|
|
|
|
}
|
|
|
|
|
2018-01-10 20:28:44 +00:00
|
|
|
module.exports = DMXKingUltraDMXPro
|