1.0.2 • Published 2 years ago

usbdmx-js v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

usbdmx-js

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)

Usage

Get connected DMX interfaces

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)]"
}

Initialize and open interface

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);

Set Interface IO-mode

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);

Write data

To write data, the DMXInterface class provides a write function. It takes an array of DMXCommand as its only argument

DMXCommand

{
  "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);

Read 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
}

Close Interface

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();

Full API

getConnectedInterfaces = (): {vid: number, pid: number, path: string}[]

  • Gets all connected USB interfaces and returns an array of objects containing the vendor ID, product ID and path

DMXInterface object

device = new DMXInterface(path: string)

  • Initializes an DMXInterface object and opens the HID device

device = DMXInterface.open(path: string)

  • Does the same as the command above

setMode = (mode: number): number

  • Sets the Interface mode to the provided mode number

write = (data: DMXCommand[] | undefined): number

  • Writes the provided data array to the dmx output
  • If data is undefined, the current output is written again

writeMap = (array: number[]): number

  • 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

dataCallback: (value: DMXCommand) => void

  • Can be used to listen to the DMX input of the device when the correct mode is set

close = ()

  • Sets the Interface mode to 0 and closes the HID connection

License

This project is licensed unter the MIT-license. More information can be found in the LICENSE file.

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago