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 Sender
The quickest way to get started is by using ola::StreamingClient. 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,.....
#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.
Callback Client Sender
The ola::OlaCallbackClient 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 Sender example.
#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);
}
}
DMX Receiver
#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(
}