Overview
This page introduces the OLA Client API, and provides sample programs to send and receive DMX512 data from olad.
Building
Once OLA is installed on your system, the examples can be built with:
g++ example.cpp $(pkg-config --cflags --libs libola)
Streaming Client DMX512 Transmit
The quickest way to get started is by using ola::client::StreamingClient (ola::StreamingClient in releases < 0.9.0). The program below sends 100 frames of DMX data to the olad server on universe 1. The frames are sent 25ms apart which gives a frame rate of 40 fps.
Each frame consists of 512 DMX data slots. The first slot is incremented by one each frame, the other slots are always 0. This produces the following DMX frames:
Time (ms) DMX Data
0 0,0,0,0,.....
25 1,0,0,0,.....
50 2,0,0,0,.....
75 3,0,0,0,.....
....
2475 100,0,0,0,.....
For releases 0.9.0 onwards, you should use code such as:
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
using std::cout;
using std::endl;
int main(int, char *[]) {
unsigned int universe = 1;
if (!ola_client.Setup()) {
std::cerr << "Setup failed" << endl;
exit(1);
}
for (unsigned int i = 0; i < 100; i++) {
if (!ola_client.SendDmx(universe, buffer)) {
cout << "Send DMX failed" << endl;
exit(1);
}
usleep(25000);
}
return 0;
}
For releases prior to 0.9.0, use
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
using std::cout;
using std::endl;
int main(int, char *[]) {
unsigned int universe = 1;
if (!ola_client.Setup()) {
std::cerr << "Setup failed" << endl;
exit(1);
}
for (unsigned int i = 0; i < 100; i++) {
if (!ola_client.SendDmx(universe, buffer)) {
cout << "Send DMX failed" << endl;
exit(1);
}
usleep(20000);
}
return 0;
}
While ola::StreamingClient is easy to use it has the drawback that it can only send DMX512 data. It's not possible to retrieve information (like the active universes etc.) from olad using the StreamingClient.
OLA Client DMX512 Transmit
The ola::client::OlaClient provides a much richer interface for interacting with the server. However, because of this it's slightly harder to use.
The following code behaves thes same as the Streaming Client DMX512 Transmit example.
For releases 0.9.0 onwards, you should use code such as:
#include <ola/io/SelectServer.h>
using std::cout;
using std::endl;
static unsigned int universe = 1;
static unsigned int i = 0;
if (++i == 100) {
}
return true;
}
int main(int, char *[]) {
std::cerr << "Setup failed" << endl;
exit(1);
}
}
For releases prior to 0.9.0, use
#include <ola/io/SelectServer.h>
#include <ola/OlaClientWrapper.h>
using std::cout;
using std::endl;
static unsigned int universe = 1;
static unsigned int i = 0;
wrapper->
GetClient()->SendDmx(universe, buffer);
if (++i == 100) {
}
return true;
}
int main(int, char *[]) {
std::cerr << "Setup failed" << endl;
exit(1);
}
}
DMX512 Receive
For releases 0.9.0 onwards, you should use code such as:
#include <string>
static const unsigned int UNIVERSE = 1;
}
}
std::cout <<
"Received " << data.
Size()
<<
" channels for universe " << metadata.
universe
<<
", priority " <<
static_cast<int>(metadata.
priority)
<< std::endl;
}
int main() {
exit(1);
}
For releases prior to 0.9.0, use
#include <ola/OlaClientWrapper.h>
#include <string>
static const unsigned int UNIVERSE = 1;
void RegisterComplete(const std::string& error) {
if (!error.empty()) {
OLA_WARN <<
"Failed to register universe";
}
}
void NewDmx(unsigned int universe,
uint8_t priority,
const std::string &error) {
if (error.empty()) {
<< " channels for universe " << universe
<< ", priority " << static_cast<int>(priority);
} else {
OLA_WARN <<
"Receive failed: " << error;
}
}
int main() {
exit(1);
client->RegisterUniverse(
}