MattIPv4 / PyDMXControl

A Python 3 module to control DMX using OpenDMX or uDMX - Featuring fixture profiles, built-in effects and a web control panel.
https://pypi.org/project/PyDMXControl/
GNU General Public License v3.0
121 stars 23 forks source link

Support for OLA? #36

Open gorenje opened 4 years ago

gorenje commented 4 years ago

Hi,

There isn't support for the Open Lighting Architecture if I see that right? I was wondering whether it would make sense to have a controller that interfaces with OLA via their Python APIs?

I'm new to DMX and OLA but I've got a setup working with OLA and a BitWizard usb dongle (http://www.bitwizard.nl/shop/raspberry-pi?product_id=154). What I'm looking for is a QLCplus-like web interface for managing my lights.

So I'm kinda wondering if this is the right project for me!

Cheers!

MattIPv4 commented 4 years ago

Hey!

You are correct, this currently doesn't have support for OLA. If you're familiar with OLA it'd be great to have someone implement a controller for it, similar to how the uDMX controller is implemeneted! :)

gorenje commented 4 years ago

Ok, then I'll have a look and see what I can do!

I was looking at their API (https://www.openlighting.org/ola/developer-documentation/python-api/) and it seems that, roughly speaking, the controller would do something like:

### import and initalise OLA
from array import array
from ola.ClientWrapper import ClientWrapper

def DmxSent(state):
    wrapper.Stop()

### ... in the controller ...

def _send_data(self):
      # Get the data
      data = self.get_frame()

      # Attempt to send data max 5 times, then 2 more with reconnect to device
      # Thanks to Dave Hocker (pyudmx author) for giving me this solution to the random usb errors
      success = False
      retry_count = 0
      while not success:
          try:
              wrapper = ClientWrapper()
              client = wrapper.Client()
              client.SendDmx(4, array('B', data), DmxSent)
              success = True
          except Exception as e:
              retry_count += 1
              if retry_count > 7:
                  raise e

But I don't know what data consists of. OLA assumes an arrray with one entry per channel ... I assume that's the same here.

MattIPv4 commented 4 years ago

That looks roughly correct -- You'll probably want to persist the wrapper/client in the controller rather than creating them each time & off the top of my head (haven't touched this in-depth for a while), yeah, data should be a list containing values for the entire universe.

gorenje commented 4 years ago

Had a play around and got some working code together --> https://github.com/gorenje/PyDMXControl/commit/eb551e70370c0b9544bfba6852a0d2a0496951a9

As you said, I persisted the wrapper and client but I also prevented the controller from bombarding the OLA daemon since OLA remembers it's state. To keep things simple, I removed the error handling and retry, don't know what the consequence of doing that is.

This basically "works for me"(TM) - running OLA and PyDMXControl on a Raspberry Pi 3+.