2013-11-17 00:41:27 +00:00
|
|
|
"use strict"
|
|
|
|
|
2016-10-14 11:36:16 +00:00
|
|
|
var SerialPort = require("serialport")
|
2012-09-01 12:17:39 +00:00
|
|
|
|
|
|
|
var ENTTEC_PRO_DMX_STARTCODE = 0x00
|
|
|
|
, ENTTEC_PRO_START_OF_MSG = 0x7e
|
|
|
|
, ENTTEC_PRO_END_OF_MSG = 0xe7
|
|
|
|
, ENTTEC_PRO_SEND_DMX_RQ = 0x06
|
|
|
|
, ENTTEC_PRO_RECV_DMX_PKT = 0x05
|
|
|
|
;
|
|
|
|
|
2016-04-09 16:08:19 +00:00
|
|
|
function EnttecUSBDMXPRO(device_id, options) {
|
2013-11-17 00:41:27 +00:00
|
|
|
var self = this
|
2016-04-09 16:08:19 +00:00
|
|
|
options = options || {}
|
2017-07-30 15:17:05 +00:00
|
|
|
this.universe = new Buffer(513)
|
2013-11-17 00:41:27 +00:00
|
|
|
this.universe.fill(0)
|
2012-09-01 12:17:39 +00:00
|
|
|
|
2016-04-09 16:08:19 +00:00
|
|
|
this.dev = new SerialPort(device_id, {
|
2018-01-10 20:28:44 +00:00
|
|
|
'baudRate': 250000,
|
2013-11-16 16:35:17 +00:00
|
|
|
'databits': 8,
|
|
|
|
'stopbits': 2,
|
|
|
|
'parity': 'none'
|
2016-10-14 11:36:16 +00:00
|
|
|
}, function(err) {
|
2013-11-17 00:41:27 +00:00
|
|
|
if(!err) {
|
|
|
|
self.send_universe()
|
|
|
|
}
|
2013-11-16 16:35:17 +00:00
|
|
|
})
|
2013-11-17 00:41:27 +00:00
|
|
|
}
|
2013-11-16 16:35:17 +00:00
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.send_universe = function() {
|
2018-01-10 20:28:44 +00:00
|
|
|
if(!this.dev.writable) {
|
2016-04-09 16:08:19 +00:00
|
|
|
return
|
|
|
|
}
|
2013-11-17 00:41:27 +00:00
|
|
|
var hdr = Buffer([
|
|
|
|
ENTTEC_PRO_START_OF_MSG,
|
|
|
|
ENTTEC_PRO_SEND_DMX_RQ,
|
2017-07-30 15:17:05 +00:00
|
|
|
(this.universe.length) & 0xff,
|
|
|
|
((this.universe.length) >> 8) & 0xff,
|
2013-11-17 00:41:27 +00:00
|
|
|
ENTTEC_PRO_DMX_STARTCODE
|
|
|
|
])
|
|
|
|
|
|
|
|
var msg = Buffer.concat([
|
|
|
|
hdr,
|
2017-07-30 15:17:05 +00:00
|
|
|
this.universe.slice(1),
|
2013-11-17 00:41:27 +00:00
|
|
|
Buffer([ENTTEC_PRO_END_OF_MSG])
|
|
|
|
])
|
|
|
|
this.dev.write(msg)
|
|
|
|
}
|
|
|
|
|
2015-05-15 12:34:24 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.start = function() {}
|
|
|
|
EnttecUSBDMXPRO.prototype.stop = function() {}
|
|
|
|
|
|
|
|
EnttecUSBDMXPRO.prototype.close = function(cb) {
|
|
|
|
this.dev.close(cb)
|
|
|
|
}
|
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.update = function(u) {
|
|
|
|
for(var c in u) {
|
|
|
|
this.universe[c] = u[c]
|
2012-09-02 12:36:08 +00:00
|
|
|
}
|
2013-11-17 00:41:27 +00:00
|
|
|
this.send_universe()
|
|
|
|
}
|
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.updateAll = function(v){
|
2017-07-30 15:17:05 +00:00
|
|
|
for(var i = 1; i <= 512; i++) {
|
2015-05-15 12:34:24 +00:00
|
|
|
this.universe[i] = v
|
|
|
|
}
|
2016-10-13 22:06:13 +00:00
|
|
|
this.send_universe()
|
2014-04-24 17:53:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
EnttecUSBDMXPRO.prototype.get = function(c) {
|
|
|
|
return this.universe[c]
|
2012-09-01 12:17:39 +00:00
|
|
|
}
|
2013-11-17 00:41:27 +00:00
|
|
|
|
2018-01-10 20:28:44 +00:00
|
|
|
module.exports = EnttecUSBDMXPRO
|