OptrisOptrisDocumentation

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

simulated — functions and constants

Simulated cameras in the device list, and asking one address.

The registry

A camera from crate::Camera::open_simulated exists only as the handle that made it: it is not enumerated and no monitor reports it. register_simulated_device puts one in this process's device list, so it is found, opened and watched by the same code as a camera on the end of a cable, and crate::Camera::open_device on the resulting entry opens it with the scene registered here rather than with defaults.

That is how an integration test drives enumeration, hotplug and claim handling with no hardware at all, and it is why these are here rather than only in C.

Measured, and it decides how a caller should read enumeration: include_simulated does not simply list the registry. With the registry empty it synthesises one fallback entry, at serial "9990001", and that entry disappears as soon as anything is registered. The registry's own first assigned serial is also "9990001", so a caller that reasons about that serial cannot tell a registered camera from the fallback.

Probing one address

probe_network is the unicast counterpart of a broadcast sweep, and the only way to reach a camera a broadcast cannot: behind a router, or on a subnet this host has no interface on.

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

Forget every registered simulated camera, reporting each removal.

The teardown for register_simulated_device. Worth calling in a test's cleanup rather than unregistering by serial: the registry is process-wide, so a serial left behind by a failed test is a collision in the next one.

Errors

Returns whatever the SDK reports if it cannot answer.

pub fn probe_network(target: &NetworkTarget) -> Result<Option<DeviceInfo>>

Ask one address who is there, without opening the camera.

The unicast counterpart of crate::enumerate: the same discovery exchange, addressed to one host instead of broadcast. A unicast datagram is routed, so this reaches a camera a broadcast cannot: behind a router, or on a subnet this host has no interface on. Those cameras are invisible to a sweep however long it waits, and typing the address is the only way in.

Opens nothing and claims nothing, so probing a camera another process is streaming from does not disturb it. This is what lets a user interface list a camera, and learn its serial, before deciding to open it.

Ok(None) rather than an error when nothing answers: an operator mistyping an address is an ordinary event, and it costs the target's discovery timeout rather than an operating system connect timeout.

Errors

Returns crate::Status::Configuration if the target names no address; there is then no host to ask.

Examples

# fn main() -> optris_sdk::Result<()> {
let target = optris_sdk::NetworkTarget::new().address("10.0.0.21")?;
match optris_sdk::probe_network(&target)? {
    Some(device) => println!("{} answered", device.serial),
    None => println!("nothing there"),
}
# Ok(())
# }

pub fn register_simulated_device(config: &SimulatedConfig) -> Result<DeviceInfo>

Put a simulated camera in this process's device list.

Returns the device as it will appear in enumeration. Reports an arrival to a running crate::DeviceMonitor or crate::HotplugMonitor, so it is also how a monitor's handler can be exercised deliberately.

Clear the serial to have one assigned: the lowest free serial from 9990001 up. SimulatedConfig::new fills the serial with "9990001" rather than leaving it empty, so registering two freshly-defaulted configs is a collision and is refused rather than silently giving you one camera.

Errors

Returns crate::Status::Configuration if the serial is already registered, if the simulated serial block is exhausted, or if the config's frame-cycle step count is out of range.

Examples

# fn main() -> optris_sdk::Result<()> {
let config = optris_sdk::SimulatedConfig::new().serial("")?;
let device = optris_sdk::register_simulated_device(&config)?;
let mut camera = optris_sdk::Camera::open_device(&device)?;
camera.start()?;
# Ok(())
# }

pub fn unregister_simulated_device(serial: &str) -> Result<bool>

Remove a simulated camera from the device list.

Ok(true) if one was registered under that serial and Ok(false) if none was, not an error either way, so a teardown may run unconditionally.

Removes the list entry, not any camera opened from it: a simulated camera that is open owns its own generator and keeps producing frames until it is dropped. What changes at once is that the serial stops being enumerated and can no longer be opened.

Reports a removal to a running monitor.

Errors

Returns crate::Status::InvalidArgument if serial contains an interior NUL byte.