Overview
Olc C++ library is intended to control Ophir® infrared lenses (Ophir® is a registered trademark of MKS Instruments, Inc. or a subsidiary of MKS Instruments Inc). The Olc library inherits Lens interfaces. The library has advanced auto focus functions. It depends on libraries: Lens (provides interface and data structures to control lenses, source code included, Apache 2.0 license), Logger (provides functions to print logs, source code included, Apache 2.0 license), SerialPort (provides functions to work with serial ports, source code included, Apache 2.0 license) and AFEngine (provides auto focus functions, source code included). The Olc library provides a simple interface to be integrated in any C++ projects. The library repository (folder) is provided by source code and doesn’t have third-party dependencies to be specially installed in the OS. It is developed with C++17 standard and is compatible with Linux and Windows.
Documentation
Documentation: GO TO DOCUMENTATION
Lens control interface
class Olc : public Lens
{
public:
/// Class constructor.
Olc();
/// Class destructor.
~Olc();
/// Get lens class version.
static std::string getVersion();
/// Open controller serial port and run communication thread.
bool openLens(std::string initString) override;
/// Init lens controller by params class.
bool initLens(LensParams& params) override;
/// Close serial port and stop communication thread.
void closeLens() override;
/// Get serial port open status.
bool isLensOpen() override;
/// Get lens connection status.
bool isLensConnected() override;
/// Set the lens controller param.
bool setParam(LensParam id, float value) override;
/// Get the lens controller param.
float getParam(LensParam id) override;
/// Get the lens controller params class.
void getParams(LensParams& params) override;
/// Execute action command.
bool executeCommand(LensCommand id, float arg = 0) override;
/// Add video frame for auto focus purposes.
void addVideoFrame(cr::video::Frame& frame) override;
/// Decode and execute command.
bool decodeAndExecuteCommand(uint8_t* data, int size) override;
};
Simple example
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include "Olc.h"
int main(void)
{
// Init lens controller.
cr::lens::Lens* lc = new cr::lens::Olc();
if (!lc->openLens("/dev/ttyUSB0;57600;50"))
return -1;
// Get lens Zoom position
std:: cout<< "Zoom pos: " <<
lc->getParam(cr::lens::LensParam::ZOOM_POS) << std::endl;
// Set Zoom speed to 10%.
lc->setParam(cr::lens::LensParam::ZOOM_SPEED, 10);
// Go to zoom position 65535 (Full tele).
lc->executeCommand(cr::lens::LensCommand::ZOOM_TO_POS, 65535);
// Show zoom movement (changing position).
for (int i = 0; i < 50; ++i)
{
std:: cout<< "Zoom pos: " <<
lc->getParam(cr::lens::LensParam::ZOOM_POS) << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return 1;
}

