dmx-flok/drivers/enttec-usb-dmx-pro.js

76 lines
1.5 KiB
JavaScript
Raw Normal View History

"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
;
function EnttecUSBDMXPRO(device_id, options) {
var self = this
options = options || {}
this.universe = new Buffer(513)
this.universe.fill(0)
2012-09-01 12:17:39 +00:00
this.dev = new SerialPort(device_id, {
2018-01-10 20:28:44 +00:00
'baudRate': 250000,
'databits': 8,
'stopbits': 2,
'parity': 'none'
2016-10-14 11:36:16 +00:00
}, function(err) {
if(!err) {
self.send_universe()
}
})
}
EnttecUSBDMXPRO.prototype.send_universe = function() {
2018-01-10 20:28:44 +00:00
if(!this.dev.writable) {
return
}
var hdr = Buffer([
ENTTEC_PRO_START_OF_MSG,
ENTTEC_PRO_SEND_DMX_RQ,
(this.universe.length) & 0xff,
((this.universe.length) >> 8) & 0xff,
ENTTEC_PRO_DMX_STARTCODE
])
var msg = Buffer.concat([
hdr,
this.universe.slice(1),
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)
}
EnttecUSBDMXPRO.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
2012-09-02 12:36:08 +00:00
}
this.send_universe()
}
EnttecUSBDMXPRO.prototype.updateAll = function(v){
for(var i = 1; i <= 512; i++) {
2015-05-15 12:34:24 +00:00
this.universe[i] = v
}
this.send_universe()
}
EnttecUSBDMXPRO.prototype.get = function(c) {
return this.universe[c]
2012-09-01 12:17:39 +00:00
}
2018-01-10 20:28:44 +00:00
module.exports = EnttecUSBDMXPRO