Create a gist now

Instantly share code, notes, and snippets.

@evantahler /dmx.js
Last active Mar 22, 2018

Embed
enttec open dmx + nodejs
#!/usr/bin/env node
// A simple DMX example which will turn all the lights on and off every second
// You can use this as a fork within another application as well (cluster-awareness)
////////////
// dmx.js //
////////////
var ftdi = require('ftdi');
var cluster = require('cluster');
var settings = {
// 'baudrate': 250000,
// 'baudrate': 250000 / 4,
'baudrate': 115200 / 2,
'databits': 8,
'stopbits': 2,
'parity' : 'none',
};
var sleepTime = 0.026 * 1000;
var device;
var universe = new Buffer(512, 'binary');
var on = false;
var loopTimer;
function writeLoop(){
clearTimeout(loopTimer);
// device.write([]);
setTimeout(function(){
device.write([0x00]);
device.write(universe);
if(cluster.isMaster){ process.stdout.write("."); }
loopTimer = setTimeout(writeLoop, sleepTime);
}, 88);
}
function set(k,v){
universe[parseInt(k) - 1] = parseInt(v);
console.log('[DMX] ' + k + ':' + v);
}
function setAll(v){
var i = 0;
while(i < universe.length){
universe[i] = parseInt(v);
i++;
}
console.log('[DMX] all:' + v);
}
var flop = function(){
if(on === true){
setAll(0);
}else{
setAll(250);
}
on = !on;
};
////////
// GO //
////////
setAll(0);
ftdi.find(function(err, devices){
console.log(devices);
device = new ftdi.FtdiDevice(devices[0]);
device.open(settings, function(){
writeLoop();
if(cluster.isMaster){
setInterval(flop, 500);
}else{
process.on('message', function(message){
message = JSON.parse(message);
if(message.all === true){
setAll(message.power);
}else{
set(message.channel, message.power);
}
});
}
});
});
@evantahler

This comment has been minimized.

Show comment
Hide comment
@evantahler

evantahler Mar 25, 2014

I need help talking to the Enttec Open DMX USB DMX controller. I feel that I'm very close, and only have trouble with forming the DMX buffer itself (starting on line 101)

  • The excellent fdti package for node easly fins the device and can connect to it.
    • if you are on Maverics, you need to unload the built-in OSX FTDI driver with sudo kextunload -b com.apple.driver.AppleUSBFTDI
  • The DMX device relies on the computer to continuously send data (there is no onboard clock)
    • DMX operates at about 40 fames/sec, so we send the universe every ~20 ms (the exact frequency shouldn't matter, as DMX devices will keep their last state until the next signal)
  • The DMX start/stop codes, baudrate, etc have been confirmed and validated by both this ruby and node package
  • I can confirm that I can talk to the dmx device and the hardware works by using this OSX product
    • I can "reach" the dimmer pack, as when I send a signal, it does register a DMX signal... hence my supposition that the message is malformed.

Help?

Owner

evantahler commented Mar 25, 2014

I need help talking to the Enttec Open DMX USB DMX controller. I feel that I'm very close, and only have trouble with forming the DMX buffer itself (starting on line 101)

  • The excellent fdti package for node easly fins the device and can connect to it.
    • if you are on Maverics, you need to unload the built-in OSX FTDI driver with sudo kextunload -b com.apple.driver.AppleUSBFTDI
  • The DMX device relies on the computer to continuously send data (there is no onboard clock)
    • DMX operates at about 40 fames/sec, so we send the universe every ~20 ms (the exact frequency shouldn't matter, as DMX devices will keep their last state until the next signal)
  • The DMX start/stop codes, baudrate, etc have been confirmed and validated by both this ruby and node package
  • I can confirm that I can talk to the dmx device and the hardware works by using this OSX product
    • I can "reach" the dimmer pack, as when I send a signal, it does register a DMX signal... hence my supposition that the message is malformed.

Help?

@evantahler

This comment has been minimized.

Show comment
Hide comment
@evantahler

This comment has been minimized.

Show comment
Hide comment
@evantahler

evantahler Apr 6, 2014

@mcallegari I believe you are a DMX expert from your qlcplus project. Any advice?

Owner

evantahler commented Apr 6, 2014

@mcallegari I believe you are a DMX expert from your qlcplus project. Any advice?

@evantahler

This comment has been minimized.

Show comment
Hide comment
@evantahler

evantahler Apr 19, 2014

Solved! Code updated above with a simple CLI tool to set channels on your DMX universe

Owner

evantahler commented Apr 19, 2014

Solved! Code updated above with a simple CLI tool to set channels on your DMX universe

@jondashkyle

This comment has been minimized.

Show comment
Hide comment
@jondashkyle

jondashkyle Apr 19, 2014

Oh man, timing couldn't be any better on this!

Oh man, timing couldn't be any better on this!

@coolaj86

This comment has been minimized.

Show comment
Hide comment
@coolaj86

coolaj86 May 6, 2015

Sweet! Now I can go buy one. W00T!!!

coolaj86 commented May 6, 2015

Sweet! Now I can go buy one. W00T!!!

@evantahler

This comment has been minimized.

Show comment
Hide comment
@evantahler

evantahler Dec 1, 2015

Updated. Note: this method seems to only work for odd-numbered channels. Also, the ftdi package only compiles for node v0.10

Owner

evantahler commented Dec 1, 2015

Updated. Note: this method seems to only work for odd-numbered channels. Also, the ftdi package only compiles for node v0.10

@hugohil

This comment has been minimized.

Show comment
Hide comment
@hugohil

hugohil Feb 2, 2016

Thank you very much for this script, it's awesome ! 👍

I have a tip for future users: on osx 10.11.3, I had to do sudo kextunload -bundle-id com.FTDI.driver.FTDIUSBSerialDriver to resolve the FT_DEVICE_NOT_OPENED error. (And do not forget to ``sudo kextload -bundle-id com.FTDI.driver.FTDIUSBSerialDriver` when you're done)

hugohil commented Feb 2, 2016

Thank you very much for this script, it's awesome ! 👍

I have a tip for future users: on osx 10.11.3, I had to do sudo kextunload -bundle-id com.FTDI.driver.FTDIUSBSerialDriver to resolve the FT_DEVICE_NOT_OPENED error. (And do not forget to ``sudo kextload -bundle-id com.FTDI.driver.FTDIUSBSerialDriver` when you're done)

@Keyes

This comment has been minimized.

Show comment
Hide comment
@Keyes

Keyes Nov 9, 2017

Do you have an updated version of the above code or maybe a better solution? I'm at the same problem as you two years ago: I can only control odd numbered channels (and to be honest: I have not a single clue why)

Keyes commented Nov 9, 2017

Do you have an updated version of the above code or maybe a better solution? I'm at the same problem as you two years ago: I can only control odd numbered channels (and to be honest: I have not a single clue why)

@fichrist

This comment has been minimized.

Show comment
Hide comment
@fichrist

fichrist Mar 22, 2018

Hi, any updates on the odd numbered channels?

Hi, any updates on the odd numbered channels?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment