add DMX4ALL (NanoDMX USB) driver

This commit is contained in:
Sebastian Wiedenroth 2016-11-12 17:31:45 +01:00
parent 8e7efd398c
commit ae6c017ff9
2 changed files with 66 additions and 0 deletions

1
dmx.js
View file

@ -10,6 +10,7 @@ function DMX(options) {
this.devices = options.devices || require('./devices') this.devices = options.devices || require('./devices')
this.registerDriver('null', require('./drivers/null')) this.registerDriver('null', require('./drivers/null'))
this.registerDriver('dmx4all', require('./drivers/dmx4all'))
this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro')) this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro'))
this.registerDriver('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx')) this.registerDriver('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx'))
this.registerDriver('artnet', require('./drivers/artnet')) this.registerDriver('artnet', require('./drivers/artnet'))

65
drivers/dmx4all.js Normal file
View file

@ -0,0 +1,65 @@
"use strict"
var SerialPort = require("serialport")
function DMX4ALL(device_id, options) {
var self = this
options = options || {}
this.universe = new Buffer(512)
this.universe.fill(0)
this.dev = new SerialPort(device_id, {
'baudrate': 38400,
'databits': 8,
'stopbits': 1,
'parity': 'none'
}, function(err) {
if(!err) {
self.send_universe()
}
})
this.dev.on('data', function(data) {
//process.stdout.write(data.toString('ascii'))
})
}
DMX4ALL.prototype.send_universe = function() {
if(!this.dev.isOpen()) {
return
}
var msg = Buffer(this.universe.length * 3)
for(var i = 0; i < this.universe.length; i++) {
msg[i * 3 + 0] = (i < 256) ? 0xE2 : 0xE3
msg[i * 3 + 1] = i
msg[i * 3 + 2] = this.universe[i]
}
this.dev.write(msg)
}
DMX4ALL.prototype.start = function() {}
DMX4ALL.prototype.stop = function() {}
DMX4ALL.prototype.close = function(cb) {
this.dev.close(cb)
}
DMX4ALL.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
}
this.send_universe()
}
DMX4ALL.prototype.updateAll = function(v){
for(var i = 0; i < 512; i++) {
this.universe[i] = v
}
this.send_universe()
}
DMX4ALL.prototype.get = function(c) {
return this.universe[c]
}
module.exports = DMX4ALL