PyDMX icon indicating copy to clipboard operation
PyDMX copied to clipboard

Sending Raw DMX Values

Open EuanSteven opened this issue 1 year ago • 2 comments

I have been working on a program for some school stage lights and I have searched high and low on the module code on how to just send a plain DMX value to a specific channel but I have come up short.

Is this possible, and I have just missed it in my search, or is this not available yet?

Thanks

EuanSteven avatar Aug 16 '23 18:08 EuanSteven

So it's important to note that you can't simply send a value to a single slot (assuming that you mean a single data slot by a single channel). The addresses are inherent in the location of the data in the DMX frame, this means that you will update every other slot up to the slot you want to update (you can end transmission early to not affect slots after that if you want to). I cover how DMX works in more depth in the README.md.

If you don't mind overwriting the slots at addresses below the slot you want to update then you can definitely achieve this using this library. The example code in the README.md (included below) uses the DMXUniverse class to make life easier. But you could instead call set_frame directly. For instance interface.set_frame([0,0,0,0xF0]) (followed by interface.send_update()) would send the value 0xF0 to whatever is at address 4.

Code from README.md for reference

from dmx import Colour, DMXInterface, DMXLight3Slot, DMXUniverse

PURPLE = Colour(255, 0, 255)

# Open an interface
with DMXInterface("FT232R") as interface:
    # Create a universe
    universe = DMXUniverse()

    # Define a light
    light = DMXLight3Slot(address=8)

    # Add the light to a universe
    universe.add_light(light)

    # Update the interface's frame to be the universe's current state
    interface.set_frame(universe.serialise())

    # Send an update to the DMX network
    interface.send_update()

    # Set light to purple
    light.set_colour(PURPLE)

    # Update the interface's frame to be the universe's current state
    interface.set_frame(universe.serialise())

    # Send an update to the DMX network
    interface.send_update()

You could also implement a single slot "light" and add that to your DMX universe as you would any other light.

The architecture of DMX assumes that there will only ever be one lighting controller on any single universe, which is why it's "okay" to overwrite other data. The logic goes, if there's only one controller it must know what data it's overwriting and therefore what data to replace there. At least, that's my understanding!

Hopefully some of that is useful, happy to answer any more questions on the topic.

JMAlego avatar Aug 16 '23 19:08 JMAlego

Thank you for your very speedy response, the interface.set_frame trick has worked a treat! It's exactly what I was looking for, won't be able to test the code fully until the morning but will update on progress.

EuanSteven avatar Aug 16 '23 19:08 EuanSteven