OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Rust API referencev12.0

lib — functions and constants

Safe, idiomatic Rust bindings for the Optris thermal-imaging SDK.

Built on the SDK's flat C ABI (optris/sdk_c.h), which exists so that languages other than C++ have one surface to bind against. This crate is that binding for Rust: Result-based errors, RAII for every handle, closures for every callback, and (the part that motivated the work) pixel lifetimes the compiler checks.

Getting started

use optris_sdk::Camera;

# fn main() -> optris_sdk::Result<()> {
let mut camera = Camera::open()?;
println!("{} ({})", camera.model()?, camera.serial()?);

camera.start()?;
if let Some(frame) = camera.acquire_frame(1000)? {
    let info = frame.info()?;
    println!("{:.1} C at the hottest pixel", info.max_temp_c);
}
camera.stop()?;
# Ok(())
# }

With no camera to hand, everything below works against a simulated one, see SimulatedConfig. That is what this crate's own tests use, and it is why they pass on a build machine.

The safety contract you are signing up to

Almost all of this crate is safe to use, and the compiler enforces the parts that matter. Three things are worth knowing.

Pixel data is borrowed, never copied. A Frame delivered to a callback is valid only until that callback returns; the SDK reuses the memory immediately afterwards. In C nothing stops you keeping the pointer; it stays valid-looking and quietly starts returning the next frame. Here the frame carries a lifetime, so a slice taken from it cannot escape the callback, and code that tries does not compile. To keep a frame, call Frame::to_owned.

A camera may not be used from two threads at once. The C API allows distinct handles to be used concurrently but not one handle, so Camera is Send and deliberately not Sync. Move it between threads freely; wrap it in a Mutex to share it.

Two functions are unsafe, and only two. Everything else in the public API is safe. Camera::register_external_buffer takes a pointer the SDK will write into from its own thread, and Camera::configure_surface takes a WGPUSurface belonging to another library that, as the C header says, cannot be validated. Each documents its contract.

Panics in callbacks are caught at the boundary and reported on stderr rather than unwinding into C, which would be undefined behaviour.

Errors

Every fallible call returns Result. An Error carries both the Status code and the SDK's own description of what went wrong, captured from the calling thread before it can be overwritten.

Where a failure is routine rather than exceptional the API says so in the type instead: Camera::acquire_frame returns Ok(None) when no frame has arrived yet, and Camera::region_id_by_name returns Ok(None) for a name that is not there.

Linking

This crate links libotcsdk. If the SDK is not installed system-wide, set OPTRIS_SDK_LIB_DIR to the directory holding libotcsdk.so when building. An application that does so also needs an rpath so the loader finds the same copy at run time; README.md has the three-line build script for that, and explains why linking alone is not enough.

pub const ABI_VERSION: u32 = optris_sdk_sys::OPTRIS_SDK_C_ABI_VERSION;

The C ABI version this crate was compiled against.

pub fn abi_version() -> u32

The C ABI version the loaded library implements.

Compare against ABI_VERSION, the version this crate was built against, to detect a library older than the header.

pub fn check_abi_compatible() -> Result<()>

Check that the loaded library is new enough for this crate.

The ABI is forwards-compatible by design (the SDK reads only the struct fields that fit within the size it was given), so a newer library is fine. An older one is not: it will not have the functions this crate calls.

Examples

# fn main() -> optris_sdk::Result<()> {
optris_sdk::check_abi_compatible()?;
# Ok(())
# }

Errors

Returns Status::NotSupported if the loaded library implements an older ABI than this crate was built against.

pub fn version() -> (u32, u32, u32)

The SDK's product version, as (major, minor, patch).

Examples

let (major, _minor, _patch) = optris_sdk::version();
assert!(major >= 12);

pub fn version_string() -> &'static str

The SDK's version as a display string, e.g. "12.0.0".