We've launched our new site at www.openlighting.org. This wiki will remain and be updated with more technical information.
OLA Python API: Difference between revisions
From wiki.openlighting.org
No edit summary |
|||
| Line 36: | Line 36: | ||
== Interesting Classes == | == Interesting Classes == | ||
; | ; ClientWrapper | ||
: the | : A helper class that connects to the server and creates a new OlaClient | ||
; OlaClient | |||
: The main API | |||
; | |||
: | |||
The best documentation is the set of example programs in the python/examples directory. | |||
== Sending DMX == | == Sending DMX == | ||
| Line 51: | Line 48: | ||
<pre> | <pre> | ||
import array | |||
import | from ola.ClientWrapper import ClientWrapper | ||
def DmxSent(state): | |||
wrapper.Stop() | |||
universe = | universe = 1 | ||
data = array.array('B') | |||
data.append(10) | |||
data.append(50) | |||
data.append(255) | |||
wrapper = ClientWrapper() | |||
client = wrapper.Client() | |||
client.SendDmx(universe, data, DmxSent) | |||
wrapper.Run() | |||
</pre> | </pre> | ||
== Receiving DMX == | == Receiving DMX == | ||
Here is some code to receive DMX on universe 1. | |||
<pre> | <pre> | ||
from | 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() | |||
</pre> | </pre> | ||
Revision as of 18:56, 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
- ClientWrapper
- A helper class that connects to the server and creates a new OlaClient
- OlaClient
- The main API
The best documentation is the set of example programs in the python/examples directory.
Sending DMX
A simple example to send DMX:
import array
from ola.ClientWrapper import ClientWrapper
def DmxSent(state):
wrapper.Stop()
universe = 1
data = array.array('B')
data.append(10)
data.append(50)
data.append(255)
wrapper = ClientWrapper()
client = wrapper.Client()
client.SendDmx(universe, data, DmxSent)
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()