Personal tools
The Open Lighting Project has moved!

We've launched our new site at www.openlighting.org. This wiki will remain and be updated with more technical information.

Difference between revisions of "OLA Python API"

From wiki.openlighting.org

Jump to: navigation, search
(Building the Python Bindings)
Line 1: Line 1:
 
== Building the Python Bindings ==
 
== Building the Python Bindings ==
  
See [[Building LLA]]  but run ''./configure --enable-python-libs''
+
You need the python version of protocol buffers installed.
  
Note that you have to install Swig in order to build the python bindings (sudo apt-get install swig)
+
See [[Building LLA]]  but run
  
There is also a forgotten data in lla/python/Makefile : you have to add -I../include to the value of DEFAULT_INCLUDES at the line 70.
+
<pre>
 +
$ ./configure --enable-python-libs
 +
</pre>
  
At the end of the installation, you should run ldconfig as root in order to use the python bindings.
+
Check where the modules are going to be installed:
 +
 
 +
<pre>
 +
$ grep ^pythondir config.log
 +
pythondir='/Library/Python/2.5/site-packages'
 +
</pre>
 +
 
 +
Run the usual: make, make check, make install.
 +
 
 +
Check that the modules have been installed correctly in the $pythondir above.
 +
 
 +
Check that $pythondir appears in sys.path:
 +
 
 +
<pre>
 +
$ python -c "import sys; print sys.path"
 +
</pre>
 +
 
 +
If it doesn't add it to $PYTHONPATH:
 +
 
 +
<pre>
 +
$ export PYTHONPATH=$PYTHONPATH:/path/to/your/install/dir
 +
</pre>
 +
 
 +
You probably want to put this line in your shell .rc file.
  
 
== Interesting Classes ==
 
== Interesting Classes ==

Revision as of 11:50, 9 January 2011

Building the Python Bindings

You need the python version of protocol buffers installed.

See Building LLA but run

$ ./configure --enable-python-libs

Check where the modules are going to be installed:

$ grep ^pythondir config.log
pythondir='/Library/Python/2.5/site-packages'

Run the usual: make, make check, make install.

Check that the modules have been installed correctly in the $pythondir above.

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/install/dir

You probably want to put this line in your shell .rc file.

Interesting Classes

LlaClient
the main connection class
dmxBuffer
represents a list of DMX channel values
LlaClientObserver
base class to handle events
LlaPlugin
represents a Plugin
LlaDevice
represents a Device

Sending DMX

A simple example to send DMX:

from lla import *
import sys

con = LlaClient()
if con.start():
  sys.exit()

universe = 0

# create a dmxBuffer for the channel values
DMX_LEN = 512
dmx = dmxBuffer(DMX_LEN)
for i in range(0, DMX_LEN):
  dmx[i] = i

con.send_dmx(universe, dmx, DMX_LEN)

Receiving DMX

Receiving is slightly harder, we need to setup an Observer object to handle the events:

THIS ISN'T WORKING YET [simonn]

from lla import *
import sys

class Observer(LlaClientObserver):
  """ Handle the events """
  def new_dmx(self, uni, length, data):
    """ Called with new dmx buffer """
    return 0


# create a new LlaClient
con = LlaClient()

# create an observer object and register
ob = Observer()
con.set_observer(ob)

if con.start():
  sys.exit()

con.register_uni(1, LlaClient.REGISTER)

while True:
  con.fd_action(1)