Last active
April 21, 2018 13:28
-
-
Save nenjiru/2087cc1bc25cb8341a9d to your computer and use it in GitHub Desktop.
Artnet for NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
-------------------------------------------------------------------------------- | |
Config | |
-------------------------------------------------------------------------------- | |
*/ | |
var dgram = require('dgram') | |
, Buffer = require('buffer').Buffer; | |
var HEADER = [65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14, 0, 0, 0, 0]; | |
var HOST = '192.168.0.255'; | |
var PORT = 6454; | |
/* | |
-------------------------------------------------------------------------------- | |
UDP Client | |
-------------------------------------------------------------------------------- | |
*/ | |
var udp = dgram.createSocket('udp4'); | |
/** | |
* Send UDP | |
*/ | |
function _send(data, host, port) | |
{ | |
var upper = Math.floor(data.length / 256) | |
, lower = data.length % 256 | |
, data = HEADER.concat([upper, lower]).concat(data) | |
, buffer = Buffer(data); | |
udp.send(buffer, 0, buffer.length, port, host, function(){}); | |
} | |
/* | |
-------------------------------------------------------------------------------- | |
Send Artnet | |
-------------------------------------------------------------------------------- | |
*/ | |
var CHANNEL = 150 | |
, LED = [] | |
; | |
for (var i = 0; i < CHANNEL; i++) | |
{ | |
LED[i] = 255; | |
} | |
_send(LED, HOST, PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, thanks for the code!
I'd like to send other OpCodes, but I don't get how you convert them. In the example above, you have an OpDMX code, but what's the conversion involved from 0x5000 to [0, 80] in JavaScript ?
I know I can do something like this in c++
but I'd like to see how to do it in JavaScript?
Regards,
Xavier