Python API
OLA is distributed with a Python API. This makes it easy to quickly prototype new DMX512 generators.
Installation
If you’re installing from source you need to pass --enable-python-libs when running configure. i.e.
$ ./configure --enable-python-libs
Once the configure script completes, you can check where the Python modules are going to be installed by running:
$ grep ^pythondir config.log pythondir='/Library/Python/2.5/site-packages'
After running make and make install, check that the modules have been correctly installed into $pythondir.
Finally check that $pythondir appears in sys.path:
$ python -c "import sys; print sys.path"
If it doesn’t add it to $PYTHONPATH:
$ export PYTHONPATH=$PYTHONPATH:/path/to/your/pythondir
You probably want to put this line in your shell .rc file.
Sending DMX
A simple example to send one frame of DMX data:
import array from ola.ClientWrapper import ClientWrapper def DmxSent(state): wrapper.Stop() universe = 1 data = array.array('B', [10, 50, 255]) wrapper = ClientWrapper() client = wrapper.Client() client.SendDmx(universe, data, DmxSent) wrapper.Run()
Sending Multiple Frames
import array from ola.ClientWrapper import ClientWrapper wrapper = None loop_count = 0 TICK_INTERVAL = 100 # in ms def DmxSent(state): if not state.Succeeded(): wrapper.Stop() def SendDMXFrame(): # schdule a function call in 100ms # we do this first in case the frame computation takes a long time. wrapper.AddEvent(TICK_INTERVAL, SendDMXFrame) # compute frame here data = array.array('B') global loop_count data.append(loop_count % 255) loop_count += 1 # send wrapper.Client().SendDmx(1, data, DmxSent) wrapper = ClientWrapper() wrapper.AddEvent(TICK_INTERVAL, SendDMXFrame) wrapper.Run()
Receiving DMX
Here is some code to receive DMX on universe 1.
from ola.ClientWrapper import ClientWrapper def NewData(data): print data universe = 1 wrapper = ClientWrapper() client = wrapper.Client() client.RegisterUniverse(universe, client.REGISTER, NewData) wrapper.Run()
Further Examples
For further examples, including using other parts of OLA aside from sending and receiving DMX, take a look at our Python examples here:
https://github.com/OpenLightingProject/ola/tree/master/python/examples