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.
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 "Using OLA with Xcode"
From wiki.openlighting.org
Chatchavan (talk | contribs) (→Example code) |
Chatchavan (talk | contribs) (→Example code) |
||
Line 88: | Line 88: | ||
// create a select server | // create a select server | ||
− | + | ola::network::SelectServer server; | |
− | + | ||
− | + | // create pipe socket | |
− | + | PipeSocket *socket = new PipeSocket(); | |
− | + | if (!socket->Init()) | |
− | + | { | |
− | + | NSLog(@"Cannot create pipe socket"); | |
− | + | return -1; | |
− | + | } | |
− | + | ||
− | + | // add socket to select server | |
− | + | server.AddSocket(socket, true); | |
− | + | ||
− | + | // create server daemon | |
// *** see: olad/Olad.cpp for more detail *** | // *** see: olad/Olad.cpp for more detail *** | ||
− | + | ||
// get a client | // get a client | ||
ola::OlaClient client(socket); | ola::OlaClient client(socket); |
Revision as of 06:30, 26 January 2010
You can use OLA to implement your application in Objective-C++, a bridge between Objective-C and C++. This page explains how to integrate OLA client into your program. The content of this page is based on OLA 0.6.0 Universal Mac Binaries
What you'll need
- Xcode
- OLA 0.6.0 Universal Mac Binaries installed
Configure your project
- Select menu: "Project" -> "Edit Project Settings". All settings below are referred in a "Build" tab
- Set "Architectures" to 32-bit Universal
- Set "Header Search Paths" to
/usr/local/include
Add dylib
- In your project tree, right-click on a group that contain frameworks (e.g. "External Frameworks and Libraries", "Fromeworks/Linked Frameworks"), select "Add" -> "Existing Frameworks"
- Select following frameworks:
- libprotobuf.dylib
- libola.dylib
- libolacommon.dylib
Example code
The following code sends value 255 to channel 0 in universe 0. First, it creates a client from a SimpleClient object. Then, it creates a DMX data array and pack the array to a buffer. In the end, it sends the buffer to a server.
#import <Foundation/Foundation.h> #include <errno.h> #import <ola/DmxBuffer.h> #import <ola/SimpleClient.h> // define type for DMX message typedef unsigned char dmx_t ; // maximum number of channels int MAXCHANNELS=512; int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // get a client ola::SimpleClient simpleClient; if (!simpleClient.Setup()) { NSLog(@"Client setup failed %s", strerror(errno)); return -1; } ola::OlaClient *client = simpleClient.GetClient(); // prepare data int channel = 0; dmx_t *dmx = (dmx_t *)calloc(MAXCHANNELS + 10, sizeof(dmx_t)); dmx[channel] = 255; ola::DmxBuffer buffer(dmx, MAXCHANNELS); // send DMX message int universe = 0; if (!client->SendDmx(universe, buffer)) { NSLog(@"Sending DMX failed %s", strerror(errno)); } [pool drain]; return 0; }
Notice that DMX API is changed since the last documented client API. You can find more information by browsing the source file of DMX example. For me, the src/ola-client.cpp is quite useful.
Here is another example that create OlaServer and communicate with a pipe socket.
#import <Foundation/Foundation.h> #include <errno.h> #import <ola/DmxBuffer.h> #import <ola/OlaClient.h> #import <ola/network/SelectServer.h> #import <ola/network/Socket.h> using ola::network::PipeSocket; // define type for DMX message typedef unsigned char dmx_t ; // maximum number of channels int MAXCHANNELS=512; int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // create a server ola::network::SelectServer server; // create a select server ola::network::SelectServer server; // create pipe socket PipeSocket *socket = new PipeSocket(); if (!socket->Init()) { NSLog(@"Cannot create pipe socket"); return -1; } // add socket to select server server.AddSocket(socket, true); // create server daemon // *** see: olad/Olad.cpp for more detail *** // get a client ola::OlaClient client(socket); if (!client.Setup()) { NSLog(@"Client setup failed %s", strerror(errno)); return -1; } // prepare data int channel = 0; dmx_t *dmx = (dmx_t *)calloc(MAXCHANNELS + 10, sizeof(dmx_t)); dmx[channel] = 255; ola::DmxBuffer buffer(dmx, MAXCHANNELS); // send DMX message int universe = 0; if (!client.SendDmx(universe, buffer)) { NSLog(@"Sending DMX failed %s", strerror(errno)); } // cleanup free(dmx); [pool drain]; return 0; }