Node.js library for the FX5 DMX and Digital Enlightenment USB Interface.
Code based on the FX5 usbdmx driver (uses node-hid for USB/HID communication)
The package is available on npm and can be installed like this:
npm install usbdmx-js
import { getConnectedInterfaces } from "usbdmx-js";
var interfaces = getConnectedInterfaces();
This will return an array of objects, which looks like this:
{
"vid": "[Vendor ID (number)]",
"pid": "[Product ID (number)]",
"path": "[System Path to HID device (string)]"
}
There are two ways to open the interface, which basically to the same thing. You need the path
key from getConnectedInterfaces
for this step.
import { DMXInterface } from "usbdmx-js";
const path = "foo"
const fx5 = new DMXInterface(path);
// OR
const fx5 = DMXInterface.open(path);
The FX5/Digital Enlightenment Interface provides multiple modes for operation:
- 0: Do nothing - Standby
- 1: DMX In -> DMX Out
- 2: PC Out -> DMX Out
- 3: DMX In + PC Out -> DMX Out
- 4: DMX In -> PC In
- 5: DMX In -> DMX Out & DMX In -> PC In
- 6: PC Out -> DMX Out & DMX In -> PC In
- 7: DMX In + PC Out -> DMX Out & DMX In -> PC In
In standby mode, the status indicator LED on the device is turned off. Upon setting a different mode, it will turn on
import { DMXInterface } from "usbdmx-js"
const mode = 6;
// Create USBDMX Interface
const path = "foo";
const fx5 = new DMXInterface(path);
// Set mode to value inside the variable
fx5.setMode(mode);
To write data, the DMXInterface
class provides a write
function. It takes an array of DMXCommand
as its only argument
{
"channel": "[DMX channel (1-512; number)]",
"value": "[DMX value (0-255; number)]"
}
Example:
// variable fx5 already defined
const data = [{channel: 0, value: 255}]
fx5.write(data);
The USB Interface also has a DMX Input. If the corresponding mode is selected, you can read that data input. The callback function provides the DMXCommand
object.
// variable fx5 already defined
fx5.dataCallback = (data: DMXCommand) => {
// handle data
}
To close the interface, call the close
function on an DMXInterface
object.
This will set the DMX mode to 0
and closes the HID connection. Any attempts to write to the device will fail.
// variable fx5 already defined
fx5.close();
- Gets all connected USB interfaces and returns an array of objects containing the vendor ID, product ID and path
- Initializes an
DMXInterface
object and opens the HID device
- Does the same as the command above
- Sets the Interface mode to the provided mode number
- Writes the provided data array to the dmx output
- If data is undefined, the current output is written again
- Write an array of 512 values (each entry is for a channel in the universe; sorted by channel)
- If you want to write a lot of data, this method is faster because it skips looping through the data and updating the output list which
write
does
- Can be used to listen to the DMX input of the device when the correct mode is set
- Sets the Interface mode to 0 and closes the HID connection
This project is licensed unter the MIT-license. More information can be found in the LICENSE file.