irayftcamera_web_logo

IRayFtCamera C++ library

v2.0.7

Table of contents

Overview

The IRayFtCamera C++ library is a software controller for IRay FT cameras. The camera is controlled through a serial port. The IRayFtCamera library inherits Camera interface. It depends on libraries: Camera (provides interface and data structures to control cameras; depends on the ConfigReader library), Logger (provides function to print log information in console and files), SerialPort (provides functions to work with serial ports). The repositories of these libraries are not part of the IRayFtCamera repository, see Build and connect to your project. The IRayFtCamera library provides simple interface to be integrated in any C++ projects. It doesn’t need third-party libraries installed in the OS. It developed with C++17 standard and compatible with Linux and Windows.

IRayFtCamera is general-purpose software: it is not tied to any sector or application, and the developer of a program decides what the program does with it.

The library code was developed by reverse engineering the serial port communication protocol of the cameras.

Versions

Table 1 - Library versions.

Version Release date What’s new
1.0.0 30.05.2023 - First version
2.0.0 07.03.2024 - Interface updated.
- Test application updated.
- Documentation updated.
2.0.1 24.04.2024 - Code review and documentation update.
2.0.2 23.05.2024 - Documentation updated.
- Submodules updated.
2.0.3 07.08.2024 - CMake structure updated.
2.0.4 03.04.2025 - Logger submodule update.
2.0.5 26.10.2025 - SerialPort submodule update.
2.0.6 12.10.2026 - Submodules updated.
2.0.7 17.10.2026 - Repository does not contain sub-repositories: ConfigReader, Camera, SerialPort and Logger are located next to the library or are added by the parent project.
- Fixed hang of setParam(…) and executeCommand(…) when the serial port is not open or the device is lost.
- Fixed wrong brightness and contrast values for the values from -1 to 0 and from 100 to 101. NaN, infinity and values outside of the int range are rejected.
- Init string: baud rate must be a decimal number from 1 to 2147483647, serial port name with the NUL character is rejected.
- Serial port access is protected by the mutex. NUC interval is measured with the monotonic clock.
- decodeAndExecuteCommand(…) rejects nullptr and follows the log mode.
- Compiler warnings fixed, exploit mitigation compiler and linker flags added.
- Test application rewritten: terminal only, input is checked, end of input is handled.
- Documentation updated.

Library files

The library supplied by source code only. The user would be given a set of files in the form of a CMake project (repository). The repository structure is shown below:

CMakeLists.txt ---------------- Main CMake file of the library.
README.md --------------------- This document.
static ------------------------ Folder with the images of the documentation.
src --------------------------- Folder with source code of the library.
    CMakeLists.txt ------------ CMake file of the library.
    IRayFtCamera.cpp ---------- C++ implementation file.
    IRayFtCamera.h ------------ Header file which includes IRayFtCamera class declaration.
    IRayFtCameraVersion.h ----- Header file which includes version of the library.
    IRayFtCameraVersion.h.in -- CMake service file to generate version file.
test -------------------------- Folder with test application source code.
    CMakeLists.txt ------------ CMake file of the test application.
    main.cpp ------------------ Source code file of the test application.

IRayFtCamera class description

IRayFtCamera Class declaration

The IRayFtCamera interface class declared in IRayFtCamera.h file. The IRayFtCamera class inherits from Camera interface class. All methods of the class are thread-safe. A method which exchanges data with the camera (setParam(…), executeCommand(…)) holds the object until the exchange is finished (up to 300 ms): the other methods of the same object wait for it. An object must not be destroyed while another thread calls its methods. Class declaration:

class IRayFtCamera : public rapidpixel::Camera
{
public:

  /// Class constructor. The camera is closed after construction.
  IRayFtCamera();

  /// Class destructor. Closes the serial port if it is open.
  ~IRayFtCamera() override;

  /// Copy and move operations are deleted: the object owns a serial port.
  IRayFtCamera(const IRayFtCamera&) = delete;
  IRayFtCamera(IRayFtCamera&&) = delete;
  IRayFtCamera& operator= (const IRayFtCamera&) = delete;
  IRayFtCamera& operator= (IRayFtCamera&&) = delete;

  /// Get Camera class version.
  static std::string getVersion();

  /// Open the serial port of the camera.
  bool openCamera(std::string initString) override;

  /// Open the serial port and set the camera params.
  bool initCamera(CameraParams& params) override;

  /// Close the serial port.
  void closeCamera() override;

  /// Get serial port open status.
  bool isCameraOpen() override;

  /// Get camera connection status.
  bool isCameraConnected() override;

  /// Set the camera controller param.
  bool setParam(CameraParam id, float value) override;

  /// Get the camera controller param.
  float getParam(CameraParam id) override;

  /// Get the camera controller params.
  void getParams(CameraParams& params) override;

  /// Execute camera controller action command.
  bool executeCommand(CameraCommand id) override;

  /// Decode and execute command.
  bool decodeAndExecuteCommand(uint8_t* data, int size) override;
};

getVersion method

The getVersion() returns string of IRayFtCamera class version. Method declaration:

static std::string getVersion();

Method can be used without IRayFtCamera class instance:

std::cout << "IRayFtCamera class version: " << rapidpixel::IRayFtCamera::getVersion() << std::endl;

Console output:

IRayFtCamera class version: 2.0.7

openCamera method

The openCamera(…) opens serial port to communicate with camera. The method does not send data to the camera: the connection status (isCameraConnected()) is known after the first command. If the serial port is already open the method returns TRUE and does not check the init string. Method declaration:

bool openCamera(std::string initString) override;
Parameter Value
initString Initialization string. Format: “serial port name;baud rate”, for example “/dev/ttyUSB0;57600”. The baud rate is a decimal number from 1 to 2147483647 (spaces and tabs around the number are ignored). The serial port name must not contain the ‘;’ and the NUL characters. Empty parts of the string are ignored.

Returns: TRUE if the serial port is open or FALSE if not (the init string has invalid format or the serial port can not be opened).

initCamera method

The initCamera(…) initializes controller and sets camera params (Camera interface). The method sets the log mode, calls openCamera(…) method with initString of the given params and after will set AGC mode, brightness, contrast, palette, NUC mode and auto NUC interval (in this order) with setParam(…) method. The method takes 1.2 seconds (the time to wait for the responses of the camera). Method declaration:

bool initCamera(CameraParams& params) override;
Parameter Value
params CameraParams class object.

Returns: TRUE if the serial port is open or FALSE if not. The result of setting of each camera param is not included in the returned value: a param with an invalid value or without the camera response is not set. Use getParam(…) and isCameraConnected() to check the result.

closeCamera method

The closeCamera() method closes serial port. The method does nothing if the serial port is not open. Method declaration:

void closeCamera() override;

isCameraOpen method

The isCameraOpen() method returns serial port open status. Method declaration:

bool isCameraOpen() override;

Returns: TRUE is the controller initialized (serial port open) or FALSE if not.

isCameraConnected method

The isCameraConnected() method returns camera connection status. Method declaration:

bool isCameraConnected() override;

Returns: TRUE if the last command was answered by the camera or FALSE if not (no command was sent yet or the last command was not answered).

setParam method

The setParam(…) method sets new camera controller parameter value. The method waits for the response of the camera: 100 ms for BRIGHTNESS, CONTRAST and AGC_MODE, 300 ms for NUC_MODE, AUTO_NUC_INTERVAL_MSEC and PALETTE. The supported parameters and their values are described in Table 3. The range of a value is checked for its integer part (the fractional part is discarded) and the integer part is stored. Brightness and contrast are sent to the camera with the fractional part. BRIGHTNESS, CONTRAST and AGC_MODE are stored if the value is valid even if the camera does not respond (the camera confirmation is not checked for them). The other parameters are stored only if the camera confirmed the command. Method declaration:

bool setParam(CameraParam id, float value) override;
Parameter Description
id Camera controller parameter ID according to CameraParam enum.
value Parameter value. Value depends on parameter ID.

Returns: TRUE is the parameter was set or FALSE if not: the parameter is not supported, the value is invalid (outside of the range, NaN, infinity), the serial port is not open or the camera did not respond or responded with an invalid message.

getParam method

The getParam(…) method intended to obtain Camera parameter value. Method declaration:

float getParam(CameraParam id) override;
Parameter Description
id Camera controller parameter ID according according to CameraParam enum.

Returns: parameter value or -1 if the parameter is not supported.

getParams method

The getParams(…) method intended to obtain Camera parameters structure. Method declaration:

void getParams(CameraParams& params) override;
Parameter Description
params Reference to CameraParams class object.

executeCommand method

The executeCommand(…) method intended to execute Camera action command. Only the NUC command is supported. The camera accepts the NUC command not more often than once in 3 seconds: the method rejects the command if less than 3 seconds passed since the previous NUC command or since the creation of the object. The method waits 100 ms for the response of the camera. Method declaration:

bool executeCommand(CameraCommand id) override;
Parameter Description
id Camera controller command ID according to CameraCommand enum.

Returns: TRUE is the command was executed or FALSE if not (the command is not supported, the NUC command is too early, the serial port is not open or the camera did not respond).

decodeAndExecuteCommand method

The decodeAndExecuteCommand(…) method decodes and executes command on controller side. Method will decode commands which encoded by encodeCommand(…) and encodeSetParamCommand(…) methods of Camera interface class. If command decoded the method will call setParam(…) or executeCommand(…) methods for camera interfaces. This method is thread-safe. This means that the method can be safely called from any thread. Method declaration:

bool decodeAndExecuteCommand(uint8_t* data, int size) override;
Parameter Description
data Pointer to input command data. Must not be nullptr.
size Size of command. Must be 11 bytes for SET_PARAM and 7 bytes for COMMAND.

Returns: TRUE if command decoded (SET_PARAM or COMMAND) and executed (action command or set param command) or FALSE if not (data is nullptr, the command is invalid or it was not executed).

encodeSetParamCommand method of Camera class

encodeSetParamCommand(…) static method of Camera interface class encodes command to change any remote camera parameter value. To control a camera remotely, the developer has to design his own protocol and according to it encode the command and deliver it over the communication channel. To simplify this, the Camera class contains static methods for encoding the control command. The Camera class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeSetParamCommand(…) designed to encode SET_PARAM command. Method declaration:

static void encodeSetParamCommand(uint8_t* data, int& size, CameraParam id, float value);
Parameter Description
data Pointer to data buffer for encoded command. Must not be nullptr and must have size >= 11.
size Size of encoded data. Will be 11 bytes (0 if data is nullptr).
id Parameter ID according to CameraParam enum.
value Parameter value.

SET_PARAM command format:

Byte Value Description
0 0x01 SET_PARAM command header value.
1 Major Major version of Camera class.
2 Minor Minor version of Camera class.
3 id Parameter ID int32_t in Little-endian format.
4 id Parameter ID int32_t in Little-endian format.
5 id Parameter ID int32_t in Little-endian format.
6 id Parameter ID int32_t in Little-endian format.
7 value Parameter value float in Little-endian format.
8 value Parameter value float in Little-endian format.
9 value Parameter value float in Little-endian format.
10 value Parameter value float in Little-endian format.

encodeSetParamCommand(…) is static and used without Camera class instance. This method used on client side (control system). Command encoding example:

// Buffer for encoded data.
uint8_t data[11];
// Size of encoded data.
int size = 0;
// Encode command.
rapidpixel::Camera::encodeSetParamCommand(
    data, size, rapidpixel::CameraParam::BRIGHTNESS, 50.0f);

encodeCommand method of Camera class

encodeCommand(…) static method of Camera interface class encodes command for camera remote control. To control a camera remotely, the developer has to design his own protocol and according to it encode the command and deliver it over the communication channel. To simplify this, the Camera class contains static methods for encoding the control command. The Camera class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeCommand(…) designed to encode COMMAND command (action command). Method declaration:

static void encodeCommand(uint8_t* data, int& size, CameraCommand id);
Parameter Description
data Pointer to data buffer for encoded command. Must not be nullptr and must have size >= 7.
size Size of encoded data. Will be 7 bytes (0 if data is nullptr).
id Command ID according to CameraCommand enum.

COMMAND format:

Byte Value Description
0 0x00 COMMAND header value.
1 Major Major version of Camera class.
2 Minor Minor version of Camera class.
3 id Command ID int32_t in Little-endian format.
4 id Command ID int32_t in Little-endian format.
5 id Command ID int32_t in Little-endian format.
6 id Command ID int32_t in Little-endian format.

encodeCommand(…) is static and used without Camera class instance. This method used on client side (control system). Command encoding example:

// Buffer for encoded data.
uint8_t data[7];
// Size of encoded data.
int size = 0;
// Encode command.
rapidpixel::Camera::encodeCommand(data, size, rapidpixel::CameraCommand::NUC);

decodeCommand method of Camera class

decodeCommand(…) static method of Camera interface class decodes command on camera controller side. Method declaration:

static int decodeCommand(uint8_t* data, int size, CameraParam& paramId, CameraCommand& commandId, float& value);
Parameter Description
data Pointer to input command. Must not be nullptr.
size Size of command. Must be 11 bytes for SET_PARAM and 7 bytes for COMMAND.
paramId Camera parameter ID according to CameraParam enum. After decoding SET_PARAM command the method will return parameter ID.
commandId Camera command ID according to CameraCommand enum. After decoding COMMAND the method will return command ID.
value Camera parameter value (after decoding SET_PARAM command).

Returns: 0 - in case decoding COMMAND, 1 - in case decoding SET_PARAM command or -1 in case errors (data is nullptr, the size, the version or the data type is wrong, the ID is outside of the enum).

Data structures

CameraCommand enum

Enum declaration:

/// Camera controller commands enum. The values are consecutive: the first
/// value is RESTART and the last one is DEFREEZE. Camera::decodeCommand(...)
/// uses them to check the command ID.
enum class CameraCommand
{
    /// Restart camera controller.
    RESTART = 1,
    /// Do NUC.
    NUC,
    /// Apply settings.
    APPLY_PARAMS,
    /// Save params.
    SAVE_PARAMS,
    /// Menu on.
    MENU_ON,
    /// Menu off.
    MENU_OFF,
    /// Menu set.
    MENU_SET,
    /// Menu up.
    MENU_UP,
    /// Menu down.
    MENU_DOWN,
    /// Menu left.
    MENU_LEFT,
    /// Menu right.
    MENU_RIGHT,
    /// Freeze image.
    FREEZE,
    /// Disable freeze. The last value of the enum.
    DEFREEZE
};

Table 2 - Camera commands description.

Command Description
RESTART Not supported by IRayFtCamera library.
NUC NUC command. The camera accepts it not more often than once in 3 seconds, see executeCommand(…).
APPLY_PARAMS Not supported by IRayFtCamera library.
SAVE_PARAMS Not supported by IRayFtCamera library.
MENU_ON Not supported by IRayFtCamera library.
MENU_OFF Not supported by IRayFtCamera library.
MENU_SET Not supported by IRayFtCamera library.
MENU_UP Not supported by IRayFtCamera library.
MENU_DOWN Not supported by IRayFtCamera library.
MENU_LEFT Not supported by IRayFtCamera library.
MENU_RIGHT Not supported by IRayFtCamera library.
FREEZE Not supported by IRayFtCamera library.
DEFREEZE Not supported by IRayFtCamera library.

CameraParam enum

Enum declaration:

/// Camera controller params. The values are consecutive: the first value is
/// WIDTH and the last one is CUSTOM_3. Camera::decodeCommand(...) uses them to
/// check the param ID.
enum class CameraParam
{
    /// Video frame width. Value from 0 to 16384.
    WIDTH = 1,
    /// Video frame height Value from 0 to 16384.
    HEIGHT,
    /// Display menu mode.
    DISPLAY_MODE,
    /// Video output type.
    VIDEO_OUTPUT,
    /// Logging mode.
    LOG_MODE,
    /// Exposure mode.
    EXPOSURE_MODE,
    /// Exposure time of the camera sensor.
    EXPOSURE_TIME,
    /// White balance mode.
    WHITE_BALANCE_MODE,
    /// White balance area.
    WHITE_BALANCE_AREA,
    /// White dynamic range mode.
    WIDE_DYNAMIC_RANGE_MODE,
    /// Image stabilization mode.
    STABILIZATION_MODE,
    /// ISO sensitivity.
    ISO_SENSITIVITY,
    /// Scene mode.
    SCENE_MODE,
    /// FPS.
    FPS,
    /// Brightness mode.
    BRIGHTNESS_MODE,
    /// Brightness. Value 0 - 100%.
    BRIGHTNESS,
    /// Contrast. Value 1 - 100%.
    CONTRAST,
    /// Gain mode.
    GAIN_MODE,
    /// Gain. Value 1 - 100%.
    GAIN,
    /// Sharpening mode.
    SHARPENING_MODE,
    /// Sharpening. Value 1 - 100%.
    SHARPENING,
    /// Palette.
    PALETTE,
    /// Analog gain control mode.
    AGC_MODE,
    /// Shutter mode.
    SHUTTER_MODE,
    /// Shutter position. 0 (full close) - 65535 (full open).
    SHUTTER_POSITION,
    /// Shutter speed. Value: 0 - 100%.
    SHUTTER_SPEED,
    /// Digital zoom mode.
    DIGITAL_ZOOM_MODE,
    /// Digital zoom. Value 1.0 (x1) - 20.0 (x20).
    DIGITAL_ZOOM,
    /// Exposure compensation mode.
    EXPOSURE_COMPENSATION_MODE,
    /// Exposure compensation position.
    EXPOSURE_COMPENSATION_POSITION,
    /// Defog mode.
    DEFOG_MODE,
    /// Dehaze mode.
    DEHAZE_MODE,
    /// Noise reduction mode.
    NOISE_REDUCTION_MODE,
    /// Black and white filter mode.
    BLACK_WHITE_FILTER_MODE,
    /// Filter mode.
    FILTER_MODE,
    /// NUC mode for thermal cameras.
    NUC_MODE,
    /// Auto NUC interval for thermal cameras.
    AUTO_NUC_INTERVAL_MSEC,
    /// Image flip mode.
    IMAGE_FLIP,
    /// DDE mode.
    DDE_MODE,
    /// DDE level.
    DDE_LEVEL,
    /// ROI top-left horizontal position, pixels.
    ROI_X0,
    /// ROI top-left vertical position, pixels.
    ROI_Y0,
    /// ROI bottom-right horizontal position, pixels.
    ROI_X1,
    /// ROI bottom-right vertical position, pixels.
    ROI_Y1,
    /// Camera temperature, degree.
    TEMPERATURE,
    /// ALC gate.
    ALC_GATE,
    /// Sensor sensitivity.
    SENSITIVITY,
    /// Changing mode (day / night).
    CHANGING_MODE,
    /// Changing level (day / night).
    CHANGING_LEVEL,
    /// Chroma level. Values: 0 - 100%.
    CHROMA_LEVEL,
    /// Details, enhancement. Values: 0 - 100%.
    DETAIL,
    /// Camera settings profile.
    PROFILE,
    /// Connection status (read only). Shows if we have response from camera.
    /// Value: 0 - not connected, 1 - connected.
    IS_CONNECTED,
    /// Open status (read only):
    /// 1 - camera control port open, 0 - not open.
    IS_OPEN,
    /// Camera type.
    TYPE,
    /// Camera custom param.
    CUSTOM_1,
    /// Camera custom param.
    CUSTOM_2,
    /// Camera custom param. The last value of the enum.
    CUSTOM_3
};

Table 3 - Camera params description.

Parameter Access Description
WIDTH read / write Not supported by IRayFtCamera library.
HEIGHT read / write Not supported by IRayFtCamera library.
DISPLAY_MODE read / write Not supported by IRayFtCamera library.
VIDEO_OUTPUT read / write Not supported by IRayFtCamera library.
LOG_MODE read / write Logging mode. Values:
0 - Disable,
1 - Only file,
2 - Only terminal (console),
3 - File and terminal.
The log is written by the Logger library.
EXPOSURE_MODE read / write Not supported by IRayFtCamera library.
EXPOSURE_TIME read / write Not supported by IRayFtCamera library.
WHITE_BALANCE_MODE read / write Not supported by IRayFtCamera library.
WHITE_BALANCE_AREA read / write Not supported by IRayFtCamera library.
WIDE_DYNAMIC_RANGE_MODE read / write Not supported by IRayFtCamera library.
STABILIZATION_MODE read / write Not supported by IRayFtCamera library.
ISO_SENSITIVITY read / write Not supported by IRayFtCamera library.
SCENE_MODE read / write Not supported by IRayFtCamera library.
FPS read / write Not supported by IRayFtCamera library.
BRIGHTNESS_MODE read / write Not supported by IRayFtCamera library.
BRIGHTNESS read / write Brightness. Value 0 - 100%. A value is sent to the camera in the range 0 - 65535 (the percent value multiplied by 655.35).
CONTRAST read / write Contrast. Value 0 - 100%. A value is sent to the camera in the range 0 - 255 (the percent value multiplied by 2.55).
GAIN_MODE read / write Not supported by IRayFtCamera library.
GAIN read / write Not supported by IRayFtCamera library.
SHARPENING_MODE read / write Not supported by IRayFtCamera library.
SHARPENING read / write Not supported by IRayFtCamera library.
PALETTE read / write Palette index from 0 to 19.
AGC_MODE read / write Analog gain control mode. Value: 0 - Manual, 1 - Auto.
SHUTTER_MODE read / write Not supported by IRayFtCamera library.
SHUTTER_POSITION read / write Not supported by IRayFtCamera library.
SHUTTER_SPEED read / write Not supported by IRayFtCamera library.
DIGITAL_ZOOM_MODE read / write Not supported by IRayFtCamera library.
DIGITAL_ZOOM read only Not supported by IRayFtCamera library.
EXPOSURE_COMPENSATION_MODE read only Not supported by IRayFtCamera library.
EXPOSURE_COMPENSATION_POSITION read / write Not supported by IRayFtCamera library.
DEFOG_MODE read / write Not supported by IRayFtCamera library.
DEHAZE_MODE read / write Not supported by IRayFtCamera library.
NOISE_REDUCTION_MODE read / write Not supported by IRayFtCamera library.
BLACK_WHITE_FILTER_MODE read only Not supported by IRayFtCamera library.
FILTER_MODE read / write Not supported by IRayFtCamera library.
NUC_MODE read / write NUC mode for thermal cameras. Value: 0 - Manual, 1 - Auto (the camera confirms the command).
AUTO_NUC_INTERVAL_MSEC read / write Auto NUC interval for thermal cameras. Value in milliseconds from 0 to 100000. The camera takes whole minutes: the values below 60000 are sent as 0 minutes and the values from 60000 as 1 minute.
IMAGE_FLIP read / write Not supported by IRayFtCamera library.
DDE_MODE read / write Not supported by IRayFtCamera library.
DDE_LEVEL read / write Not supported by IRayFtCamera library.
ROI_X0 read / write Not supported by IRayFtCamera library.
ROI_Y0 read / write Not supported by IRayFtCamera library.
ROI_X1 read / write Not supported by IRayFtCamera library.
ROI_Y1 read / write Not supported by IRayFtCamera library.
TEMPERATURE read only Not supported by IRayFtCamera library.
ALC_GATE read / write Not supported by IRayFtCamera library.
SENSITIVITY read / write Not supported by IRayFtCamera library.
CHANGING_MODE read / write Not supported by IRayFtCamera library.
CHANGING_LEVEL read / write Not supported by IRayFtCamera library.
CHROMA_LEVEL read / write Not supported by IRayFtCamera library.
DETAIL read / write Not supported by IRayFtCamera library.
PROFILE read / write Not supported by IRayFtCamera library.
IS_CONNECTED read only Connection status. Value: 0 - no camera responses, 1 - connected.
IS_OPEN read only Open status (read only): 1 - camera control port open, 0 - not open.
TYPE read / write Not supported by IRayFtCamera library.
CUSTOM_1 read / write Not supported by IRayFtCamera library.
CUSTOM_2 read / write Not supported by IRayFtCamera library.
CUSTOM_3 read / write Not supported by IRayFtCamera library.

CameraParams class description

CameraParams class used for camera controller initialization or to get all actual params. Also CameraParams provide structure to write/read params from JSON files (JSON_READABLE macro) and provide method to encode and decode params.

CameraParams Class declaration

CameraParams class declared in Camera.h file. The class is not thread-safe: an object must not be accessed from several threads at the same time without external synchronization. Class declaration:

class CameraParams
{
public:
    /// Initialization string. Formats depends on implementation.
    std::string initString{"/dev/ttyUSB0;9600;20"};
    /// Video frame width. Value from 0 to 16384.
    int width{0};
    /// Video frame height Value from 0 to 16384.
    int height{0};
    /// Display menu mode.
    int displayMode{0};
    /// Video output type.
    int videoOutput{0};
    /// Logging mode.
    int logMode{0};
    /// Exposure mode.
    int exposureMode{1};
    /// Exposure time of the camera sensor.
    int exposureTime{0};
    /// White balance mode.
    int whiteBalanceMode{1};
    /// White balance area.
    int whiteBalanceArea{0};
    /// White dynamic range mode.
    int wideDynamicRangeMode{0};
    /// Image stabilization mode.
    int stabilizationMode{0};
    /// ISO sensitivity.
    int isoSensitivity{0};
    /// Scene mode.
    int sceneMode{0};
    /// FPS.
    float fps{0.0f};
    /// Brightness mode.
    int brightnessMode{1};
    /// Brightness. Value 0 - 100%.
    int brightness{0};
    /// Contrast. Value 1 - 100%.
    int contrast{0};
    /// Gain mode.
    int gainMode{1};
    /// Gain. Value 1 - 100%.
    int gain{0};
    /// Sharpening mode.
    int sharpeningMode{0};
    /// Sharpening. Value 1 - 100%.
    int sharpening{0};
    /// Palette.
    int palette{0};
    /// Analog gain control mode.
    int agcMode{1};
    /// Shutter mode.
    int shutterMode{1};
    /// Shutter position. 0 (full close) - 65535 (full open).
    int shutterPos{0};
    /// Shutter speed. Value: 0 - 100%.
    int shutterSpeed{0};
    /// Digital zoom mode.
    int digitalZoomMode{0};
    /// Digital zoom. Value 1.0 (x1) - 20.0 (x20).
    float digitalZoom{1.0f};
    /// Exposure compensation mode.
    int exposureCompensationMode{0};
    /// Exposure compensation position.
    int exposureCompensationPosition{0};
    /// Defog mode.
    int defogMode{0};
    /// Dehaze mode.
    int dehazeMode{0};
    /// Noise reduction mode.
    int noiseReductionMode{0};
    /// Black and white filter mode.
    int blackAndWhiteFilterMode{0};
    /// Filter mode.
    int filterMode{0};
    /// NUC mode for thermal cameras.
    int nucMode{0};
    /// Auto NUC interval for thermal cameras.
    int autoNucIntervalMsec{0};
    /// Image flip mode.
    int imageFlip{0};
    /// DDE mode.
    int ddeMode{0};
    /// DDE level.
    float ddeLevel{0};
    /// ROI top-left horizontal position, pixels.
    int roiX0{0};
    /// ROI top-left vertical position, pixels.
    int roiY0{0};
    /// ROI bottom-right horizontal position, pixels.
    int roiX1{0};
    /// ROI bottom-right vertical position, pixels.
    int roiY1{0};
    /// Camera temperature, degree.
    float temperature{0.0f};
    /// ALC gate.
    int alcGate{0};
    /// Sensor sensitivity.
    float sensitivity{0};
    /// Changing mode (day / night).
    int changingMode{0};
    /// Changing level (day / night).
    float changingLevel{0.0f};
    /// Chroma level. Values: 0 - 100%.
    int chromaLevel{0};
    /// Details, enhancement. Values: 0 - 100%.
    int detail{0};
    /// Camera settings profile.
    int profile{0};
    /// Connection status (read only).
    bool isConnected{false};
    /// Open status (read only).
    bool isOpen{false};
    /// Camera type.
    int type{0};
    /// Camera custom param.
    float custom1{0.0f};
    /// Camera custom param.
    float custom2{0.0f};
    /// Camera custom param.
    float custom3{0.0f};

    JSON_READABLE(CameraParams, initString, width, height, displayMode,
                  videoOutput, logMode, exposureMode, exposureTime,
                  whiteBalanceMode, whiteBalanceArea, wideDynamicRangeMode,
                  stabilizationMode, isoSensitivity, sceneMode, fps,
                  brightnessMode, brightness, contrast, gainMode, gain,
                  sharpeningMode, sharpening, palette, agcMode, shutterMode,
                  shutterPos, shutterSpeed, digitalZoomMode, digitalZoom,
                  exposureCompensationMode, exposureCompensationPosition,
                  defogMode, dehazeMode, noiseReductionMode,
                  blackAndWhiteFilterMode, filterMode, nucMode,
                  autoNucIntervalMsec, imageFlip, ddeMode, ddeLevel,
                  roiX0, roiY0, roiX1, roiY1, alcGate, sensitivity,
                  changingMode, changingLevel, chromaLevel, detail,
                  profile, type, custom1, custom2, custom3)

    /// Default constructor, copy and move operations: all are defaulted.
    CameraParams() = default;
    CameraParams(const CameraParams& src) = default;
    CameraParams(CameraParams&& src) = default;
    CameraParams& operator= (const CameraParams& src) = default;
    CameraParams& operator= (CameraParams&& src) = default;

    /// Encode (serialize) params. The method doesn't encode initString.
    bool encode(uint8_t* data, int bufferSize, int& size,
                CameraParamsMask* mask = nullptr);

    /// Decode (deserialize) params. The method doesn't decode initString.
    bool decode(uint8_t* data, int dataSize);
};

Table 4 - CameraParams class fields description is equivalent to CameraParam enum description.

Field type Description
initString string Init string of the serial port: “serial port name;baud rate”, see openCamera(…). It is used by initCamera(…) and contains the string of the last successful openCamera(…) call in the params returned by getParams(…).
width int Not supported by IRayFtCamera library.
height int Not supported by IRayFtCamera library.
displayMode int Not supported by IRayFtCamera library.
videoOutput int Not supported by IRayFtCamera library.
logMode int Logging mode. Values:
0 - Disable
1 - Only file
2 - Only terminal (console)
3 - File and terminal
exposureMode int Not supported by IRayFtCamera library.
exposureTime int Not supported by IRayFtCamera library.
whiteBalanceMode int Not supported by IRayFtCamera library.
whiteBalanceArea int Not supported by IRayFtCamera library.
wideDynamicRangeMode int Not supported by IRayFtCamera library.
stabilizationMode int Not supported by IRayFtCamera library.
isoSensitivity int Not supported by IRayFtCamera library.
sceneMode int Not supported by IRayFtCamera library.
fps float Not supported by IRayFtCamera library.
brightnessMode int Not supported by IRayFtCamera library.
brightness int Brightness. Value 0 - 100%.
contrast int Contrast. Value 0 - 100%.
gainMode int Not supported by IRayFtCamera library.
gain int Not supported by IRayFtCamera library.
sharpeningMode int Not supported by IRayFtCamera library.
sharpening int Not supported by IRayFtCamera library.
palette int Palette value in range 0 and 19.
agcMode int Analog gain control mode. Value: 0 - Manual, 1 - Auto.
shutterMode int Not supported by IRayFtCamera library.
shutterPos int Not supported by IRayFtCamera library.
shutterSpeed int Not supported by IRayFtCamera library.
digitalZoomMode int Not supported by IRayFtCamera library.
digitalZoom float Not supported by IRayFtCamera library.
exposureCompensationMode int Not supported by IRayFtCamera library.
exposureCompensationPosition int Not supported by IRayFtCamera library.
defogMode int Not supported by IRayFtCamera library.
dehazeMode int Not supported by IRayFtCamera library.
noiseReductionMode int Not supported by IRayFtCamera library.
blackAndWhiteFilterMode int Not supported by IRayFtCamera library.
filterMode int Not supported by IRayFtCamera library.
nucMode int NUC mode for thermal cameras. Value: 0 - Manual, 1 - Auto.
autoNucIntervalMsec int Auto NUC interval for thermal cameras. Value in milliseconds from 0 to 100000.
imageFlip int Not supported by IRayFtCamera library.
ddeMode int Not supported by IRayFtCamera library.
ddeLevel float Not supported by IRayFtCamera library.
roiX0 int Not supported by IRayFtCamera library.
roiY0 int Not supported by IRayFtCamera library.
roiX1 int Not supported by IRayFtCamera library.
roiY1 int Not supported by IRayFtCamera library.
temperature float Not supported by IRayFtCamera library.
alcGate int Not supported by IRayFtCamera library.
sensitivity float Not supported by IRayFtCamera library.
changingMode int Not supported by IRayFtCamera library.
changingLevel float Not supported by IRayFtCamera library.
chromaLevel int Not supported by IRayFtCamera library.
detail int Not supported by IRayFtCamera library.
profile int Not supported by IRayFtCamera library.
isConnected bool Connection status. Value: 0 - no camera responses, 1 - connected.
isOpen bool Open status (read only): 1 - camera control port open, 0 - not open.
type int Not supported by IRayFtCamera library.
custom1 float Not supported by IRayFtCamera library.
custom2 float Not supported by IRayFtCamera library.
custom3 float Not supported by IRayFtCamera library.

None: CameraParams class fields listed in above reflect params set/get by methods setParam(…) and getParam(…).

Serialize camera params

CameraParams class provides method encode(…) to serialize camera params. Serialization of camera params necessary in case when you have to send camera params via communication channels. Method doesn’t encode initString field. The encoded data contains the data type, the version of the Camera library (major and minor), the binary mask (8 bytes) and the values of the selected fields (in the byte order of the host). Method provides options to exclude particular parameters from serialization. To do this method inserts binary mask where each bit represents particular parameter and decode(…) method recognizes it. Method declaration:

bool encode(uint8_t* data, int bufferSize, int& size, CameraParamsMask* mask = nullptr);
Parameter Value
data Pointer to data buffer. Must not be nullptr. Buffer size must be >= 237 bytes.
bufferSize Data buffer size. Buffer size must be >= 237 bytes.
size Size of encoded data. Set to 0 if the method returns FALSE.
mask Parameters mask - pointer to CameraParamsMask structure. CameraParamsMask (declared in Camera.h file) determines flags for each field (parameter) declared in CameraParams class. All flags are TRUE by default and the field with TRUE flag is encoded. If the user wants to exclude a particular parameter from serialization, he should set the corresponding flag in the CameraParamsMask structure to FALSE and put a pointer to the mask. If the pointer is nullptr all fields are encoded.

Returns: TRUE if params encoded (serialized) or FALSE if not (data is nullptr or bufferSize is too small).

CameraParamsMask structure declaration:

struct CameraParamsMask
{
    bool width{true};
    bool height{true};
    bool displayMode{true};
    bool videoOutput{true};
    bool logMode{true};
    bool exposureMode{true};
    bool exposureTime{true};
    bool whiteBalanceMode{true};
    bool whiteBalanceArea{true};
    bool wideDynamicRangeMode{true};
    bool stabilizationMode{true};
    bool isoSensitivity{true};
    bool sceneMode{true};
    bool fps{true};
    bool brightnessMode{true};
    bool brightness{true};
    bool contrast{true};
    bool gainMode{true};
    bool gain{true};
    bool sharpeningMode{true};
    bool sharpening{true};
    bool palette{true};
    bool agcMode{true};
    bool shutterMode{true};
    bool shutterPos{true};
    bool shutterSpeed{true};
    bool digitalZoomMode{true};
    bool digitalZoom{true};
    bool exposureCompensationMode{true};
    bool exposureCompensationPosition{true};
    bool defogMode{true};
    bool dehazeMode{true};
    bool noiseReductionMode{true};
    bool blackAndWhiteFilterMode{true};
    bool filterMode{true};
    bool nucMode{true};
    bool autoNucIntervalMsec{true};
    bool imageFlip{true};
    bool ddeMode{true};
    bool ddeLevel{true};
    bool roiX0{true};
    bool roiY0{true};
    bool roiX1{true};
    bool roiY1{true};
    bool temperature{true};
    bool alcGate{true};
    bool sensitivity{true};
    bool changingMode{true};
    bool changingLevel{true};
    bool chromaLevel{true};
    bool detail{true};
    bool profile{true};
    bool isConnected{true};
    bool isOpen{true};
    bool type{true};
    bool custom1{true};
    bool custom2{true};
    bool custom3{true};
};

Example without parameters mask:

// Encode data.
rapidpixel::CameraParams in;
in.profile = 10;
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size))
{
    std::cout << "Can't encode data" << std::endl;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

Example with parameters mask:

// Prepare params.
rapidpixel::CameraParams in;
in.profile = 3;

// Prepare mask.
rapidpixel::CameraParamsMask mask;
mask.profile = false; // Exclude profile. Others by default.

// Encode.
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size, &mask))
{
    std::cout << "Can't encode data" << std::endl;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

Deserialize camera params

CameraParams class provides method decode(…) to deserialize camera params (fields of CameraParams class, see Table 4). Deserialization of camera params necessary in case when you need to receive params via communication channels. Method automatically recognizes which parameters were serialized by encode(…) method. Method checks the data type, the version and the size of the data before it reads each field. A field which was not serialized is set to zero (FALSE) and initString is set to an empty string. Values of the fields are not checked against any range. Method doesn’t decode initString field. Method declaration:

bool decode(uint8_t* data, int dataSize);
Parameter Value
data Pointer to data buffer with serialized camera params. Must not be nullptr.
dataSize Size of the serialized data. Must be >= 11 (the size of the data without fields).

Returns: TRUE if params decoded (deserialized) or FALSE if not. If the method returns FALSE the object is not changed.

Example:

// Encode data.
rapidpixel::CameraParams in;
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size))
{
    std::cout << "Can't encode data" << std::endl;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

// Decode data.
rapidpixel::CameraParams out;
if (!out.decode(data, size))
{
    std::cout << "Can't decode data" << std::endl;
}

Read and write camera params to JSON file

Camera library depends on ConfigReader library which provides method to read params from JSON file and to write params to JSON file. The fields temperature, isConnected and isOpen are not stored in the JSON file. Example of writing and reading params to JSON file:

// Write params to file.
rapidpixel::CameraParams in;
in.initString = "/dev/ttyUSB0;57600";
in.brightness = 50;
in.contrast = 60;
in.palette = 3;
in.nucMode = 1;
in.autoNucIntervalMsec = 60000;
rapidpixel::ConfigReader inConfig;
inConfig.set(in, "cameraParams");
if (!inConfig.writeToFile("TestCameraParams.json"))
{
    std::cout << "Can't write config file" << std::endl;
    return false;
}

// Read params from file.
rapidpixel::ConfigReader outConfig;
if (!outConfig.readFromFile("TestCameraParams.json"))
{
    std::cout << "Can't open config file" << std::endl;
    return false;
}
rapidpixel::CameraParams out;
if (!outConfig.get(out, "cameraParams"))
{
    std::cout << "Can't read params from config file" << std::endl;
    return false;
}

TestCameraParams.json will look like (the fields which are not set in the example have default values):

{
    "cameraParams": {
        "initString": "/dev/ttyUSB0;57600",
        "width": 0,
        "height": 0,
        "displayMode": 0,
        "videoOutput": 0,
        "logMode": 0,
        "exposureMode": 1,
        "exposureTime": 0,
        "whiteBalanceMode": 1,
        "whiteBalanceArea": 0,
        "wideDynamicRangeMode": 0,
        "stabilizationMode": 0,
        "isoSensitivity": 0,
        "sceneMode": 0,
        "fps": 0.0,
        "brightnessMode": 1,
        "brightness": 50,
        "contrast": 60,
        "gainMode": 1,
        "gain": 0,
        "sharpeningMode": 0,
        "sharpening": 0,
        "palette": 3,
        "agcMode": 1,
        "shutterMode": 1,
        "shutterPos": 0,
        "shutterSpeed": 0,
        "digitalZoomMode": 0,
        "digitalZoom": 1.0,
        "exposureCompensationMode": 0,
        "exposureCompensationPosition": 0,
        "defogMode": 0,
        "dehazeMode": 0,
        "noiseReductionMode": 0,
        "blackAndWhiteFilterMode": 0,
        "filterMode": 0,
        "nucMode": 1,
        "autoNucIntervalMsec": 60000,
        "imageFlip": 0,
        "ddeMode": 0,
        "ddeLevel": 0.0,
        "roiX0": 0,
        "roiY0": 0,
        "roiX1": 0,
        "roiY1": 0,
        "alcGate": 0,
        "sensitivity": 0.0,
        "changingMode": 0,
        "changingLevel": 0.0,
        "chromaLevel": 0,
        "detail": 0,
        "profile": 0,
        "type": 0,
        "custom1": 0.0,
        "custom2": 0.0,
        "custom3": 0.0
    }
}

Build and connect to your project

Build stand alone

The repository does not contain sub-repositories. The libraries IRayFtCamera depends on (ConfigReader, Camera, SerialPort and Logger) must be placed in the same folder as IRayFtCamera: copy their folders, for example from the folder modules of the RapidPixel SDK. The folder structure must be:

<work folder>
    IRayFtCamera
    ConfigReader
    Camera
    SerialPort
    Logger

Typical commands to build the library and the test application:

cd IRayFtCamera
mkdir build
cd build
cmake ..
make

On Windows use cmake --build . --config Release instead of make. If IRayFtCamera is the top-level CMake project, the main CMakeLists.txt file adds the folders ../ConfigReader, ../Camera, ../SerialPort and ../Logger (in this order) before the library itself. If a folder does not exist CMake stops with an error.

CMake options

Table 5 - CMake options of the repository. In the options below ${PARENT} is the prefix defined by the top-level project (empty if IRayFtCamera is the top-level project).

Option Default Description
${PARENT}_IRAY_FT_CAMERA ON Build the library.
${PARENT}_IRAY_FT_CAMERA_TEST ON (stand alone), OFF (included in other project) Build the test application.
${PARENT}_SUBMODULE_CACHE_OVERWRITE ON Forced rewriting of the options above in the CMake cache. The top-level project sets it to OFF when it includes IRayFtCamera as a sub-repository.
CMAKE_BUILD_TYPE Release (if not specified) Build type.

Connect to your project

If you want to connect IRayFtCamera library to your CMake project as source code you can make follow. IRayFtCamera does not add its dependencies when it is included in another project: your project must add ConfigReader, Camera, SerialPort and Logger (in this order) before IRayFtCamera. For example, if your repository has structure:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp

Create folder 3rdparty in your repository and copy the folders of the libraries ConfigReader, Camera, SerialPort, Logger and IRayFtCamera there (for example from the folder modules of the RapidPixel SDK). New structure of your repository:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp
3rdparty
    ConfigReader
    Camera
    SerialPort
    Logger
    IRayFtCamera

Create CMakeLists.txt file in 3rdparty folder. CMakeLists.txt should contain:

cmake_minimum_required(VERSION 3.13)

################################################################################
## 3RD-PARTY
## dependencies for the project
################################################################################
project(3rdparty LANGUAGES CXX)

################################################################################
## SETTINGS
## basic 3rd-party settings before use
################################################################################
# To inherit the top-level architecture when the project is used as a submodule.
SET(PARENT ${PARENT}_YOUR_PROJECT_3RDPARTY)
# Disable self-overwriting of parameters inside included subdirectories.
SET(${PARENT}_SUBMODULE_CACHE_OVERWRITE OFF CACHE BOOL "" FORCE)

################################################################################
## CONFIGURATION
## 3rd-party submodules configuration
################################################################################
SET(${PARENT}_SUBMODULE_CONFIG_READER                   ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_CONFIG_READER)
    SET(${PARENT}_CONFIG_READER                         ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_CONFIG_READER_EXAMPLES                OFF CACHE BOOL "" FORCE)
    SET(${PARENT}_CONFIG_READER_TESTS                   OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_CAMERA                          ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_CAMERA)
    SET(${PARENT}_CAMERA                                ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_CAMERA_TEST                           OFF CACHE BOOL "" FORCE)
    SET(${PARENT}_CAMERA_EXAMPLE                        OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_SERIAL_PORT                     ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_SERIAL_PORT)
    SET(${PARENT}_SERIAL_PORT                           ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_SERIAL_PORT_EXAMPLES                  OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_LOGGER                          ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_LOGGER)
    SET(${PARENT}_LOGGER                                ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_LOGGER_EXAMPLE                        OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_IRAY_FT_CAMERA                  ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_IRAY_FT_CAMERA)
    SET(${PARENT}_IRAY_FT_CAMERA                        ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_IRAY_FT_CAMERA_TEST                   OFF CACHE BOOL "" FORCE)
endif()

################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
if (${PARENT}_SUBMODULE_CONFIG_READER)
    add_subdirectory(ConfigReader)
endif()

if (${PARENT}_SUBMODULE_CAMERA)
    add_subdirectory(Camera)
endif()

if (${PARENT}_SUBMODULE_SERIAL_PORT)
    add_subdirectory(SerialPort)
endif()

if (${PARENT}_SUBMODULE_LOGGER)
    add_subdirectory(Logger)
endif()

if (${PARENT}_SUBMODULE_IRAY_FT_CAMERA)
    add_subdirectory(IRayFtCamera)
endif()

File 3rdparty/CMakeLists.txt adds the dependencies and the folder IRayFtCamera to your project and excludes the test application from compiling (by default the test application is excluded from compiling if IRayFtCamera is included as sub-repository). The new structure of your repository:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp
3rdparty
    CMakeLists.txt
    ConfigReader
    Camera
    SerialPort
    Logger
    IRayFtCamera

Next you need include folder 3rdparty in main CMakeLists.txt file of your repository. Add string at the end of your main CMakeLists.txt:

add_subdirectory(3rdparty)

Next you have to include IRayFtCamera library in your src/CMakeLists.txt file:

target_link_libraries(${PROJECT_NAME} IRayFtCamera)

If a dependency is not added by your project, the compilation stops with the error that a header of the dependency is not found (for example “SerialPort.h: No such file or directory”).

Done!

Portability

The library uses C++17 and the SerialPort library, which supports Linux and Windows. The library does not contain code for a particular CPU and does not use SIMD instructions. The requests to the camera are built byte by byte: the brightness is sent with the low byte first on any host. The library was built with GCC 9, 11 and 12 for x86-64 Linux and with GCC 11 for aarch64 Linux (run under qemu user-mode emulation) with the same results.

Simple example

Following example demonstrates how to use IRayFtCamera library to control camera params via Camera interface.

#include <iostream>
#include <string>
#include "IRayFtCamera.h"

int main()
{
    // Serial port name and baud rate.
    const std::string portName = "/dev/ttyUSB0";
    const int baudrate = 57600;

    // Init camera controller.
    rapidpixel::IRayFtCamera controller;
    rapidpixel::Camera& camera = controller;

    // Open camera.
    if (!camera.openCamera(portName + ";" + std::to_string(baudrate)))
    {
        std::cout << "ERROR: Camera controller not init. Exit..." << std::endl;
        return 1;
    }

    // Set logging mode.
    if (!camera.setParam(rapidpixel::CameraParam::LOG_MODE, 2.0f))
    {
        std::cout << "ERROR: Can't set logging mode" << std::endl;
    }

    // Set brightness.
    if (!camera.setParam(rapidpixel::CameraParam::BRIGHTNESS, 50.0f))
    {
        std::cout << "ERROR: Can't set brightness" << std::endl;
    }

    // Set contrast.
    if (!camera.setParam(rapidpixel::CameraParam::CONTRAST, 50.0f))
    {
        std::cout << "ERROR: Can't set contrast" << std::endl;
    }

    // Get camera params.
    rapidpixel::CameraParams params;
    camera.getParams(params);

    // Get brightness.
    std::cout << "Brightness: " <<
        camera.getParam(rapidpixel::CameraParam::BRIGHTNESS) << std::endl;

    camera.closeCamera();

    return 0;
}

Test application

IRayFtCamera/test folder contains test application which demonstrates how to use IRayFtCamera library. Test application is a terminal application: it has no graphical interface and does not show video. Test application allows to connect to camera, set and get camera params and execute the NUC command. It can be used to test camera controller and to set/get camera params. The test application does not create files.

Test application takes the serial port name and the baud rate (57600 by default) from the command line: IRayFtCameraTest [serial port name [baud rate]]. If the serial port name is not given, the test application asks to enter it. After that test application will connect to camera, set the logging mode to the terminal and will show main menu. Main menu allows to set and get camera params and execute commands. The test application checks the entered values and the end of the input: it exits at the end of the input (for example Ctrl+D in Linux terminal) or when the option -1 is chosen. The exit code is 0 after the work and 1 if the arguments are wrong or the camera port cannot be opened.

Test application output will look like:

========================================
IRayFtCamera v2.0.7 test.
========================================
Enter serial port name:
Choose option:
1 - Set camera param
2 - Get camera param
3 - Execute camera command
4 - Show all camera params
-1 - Exit
  • If you enter 1, test application will show list of camera params and will ask to enter param number and value. The value must be inside of the range shown in the list (the fractional part is allowed only for BRIGHTNESS and CONTRAST). Output will look like:
Camera params:
16 - BRIGHTNESS (0 - 100 %)
17 - CONTRAST (0 - 100 %)
23 - AGC_MODE (0 - manual, 1 - auto)
36 - NUC_MODE (0 - manual, 1 - auto)
37 - AUTO_NUC_INTERVAL_MSEC (0 - 100000 ms)
22 - PALETTE (0 - 19)
5 - LOG_MODE (0 - disable, 1 - file, 2 - terminal, 3 - file and terminal)

Choose param (-1 to exit to main menu):
  • If you enter 2, test application will show list of camera params to read and then it will print the value of this param returned by getParam(…) (the value stored by the library, the camera is not asked). Output will look like:
Camera params:
16 - BRIGHTNESS (0 - 100 %)
17 - CONTRAST (0 - 100 %)
23 - AGC_MODE (0 - manual, 1 - auto)
36 - NUC_MODE (0 - manual, 1 - auto)
37 - AUTO_NUC_INTERVAL_MSEC (0 - 100000 ms)
22 - PALETTE (0 - 19)
5 - LOG_MODE (0 - disable, 1 - file, 2 - terminal, 3 - file and terminal)

Choose param (-1 to exit to main menu):
  • If you enter 3, test application will show list of camera commands to execute. Output will look like:
Camera commands:
2 - NUC
Choose command (-1 to exit to main menu):
  • If you enter 4, test application will print the values of all camera params, including the status params IS_OPEN and IS_CONNECTED.

Table of contents