Skip to main content

Camera

Struct Camera 

Source
pub struct Camera<T: RegisterIo> { /* private fields */ }
Expand description

Camera facade combining a nodemap with a transport implementing RegisterIo.

Implementations§

Source§

impl<T: RegisterIo> Camera<T>

Source

pub fn restore_events( &mut self, saved: EventConfiguration, ) -> EventRestoreReport

Restore event settings from this same camera session, best-effort.

No writes occur for a different camera, a monitor, lost/released control, or a disconnected USB transport. The transport also checks ownership on every write, so a refusal stops later writes as soon as loss is known. This is blocking register I/O; call on a blocking thread.

Source§

impl Camera<GigeRegisterIo>

Source

pub async fn configure_events_restorable( &mut self, local_ip: Ipv4Addr, port: u16, selectors: &[&str], ) -> Result<EventConfiguration, EventSetupError>

Configure event notification with an explicit restoration token.

Bind Self::open_event_stream first (port 0 is supported), then use its actual port here. Requested event choices are validated before message-channel writes. A setup error includes rollback results. No configuration is automatically replayed on a replacement camera.

Source§

impl<T: UsbTransfer + 'static> Camera<U3vRegisterIo<T>>

Source

pub fn configure_events_restorable( &mut self, selectors: &[&str], ) -> Result<EventConfiguration, EventSetupError>

Enable named USB3 Vision events, retaining only changed settings for explicit restoration. Open the event reader separately; it preserves the EventEnable word it found when opened.

Source§

impl<T: RegisterIo> Camera<T>

The helpers for standard features. Each looks its feature up by the names cameras declare it under (StandardFeature::names), in that order, and takes the first of a kind it can drive; one the camera has under none of them is GenicamError::MissingFeature, naming them all.

The lookup is by declaration: a feature declared but not implemented on this device reports so when it is used, rather than being skipped for the next name.

Source

pub fn resolve( &self, feature: StandardFeature, ) -> Result<ResolvedFeature, GenicamError>

Find the node feature goes by on this camera.

Source

pub fn exposure_time(&self) -> Result<f64, GenicamError>

The exposure time, in the unit of the feature that holds it: microseconds for ExposureTime and ExposureTimeAbs, the device’s own for ExposureTimeRaw (StandardFeature::ExposureTime says which this camera has, and its declared unit).

Source

pub fn set_exposure_time( &mut self, value: f64, ) -> Result<ResolvedFeature, GenicamError>

Write the exposure time, in the unit of the feature that holds it — rounded to the nearest integer for ExposureTimeRaw — and say which feature that was.

Source

pub fn gain(&self) -> Result<f64, GenicamError>

The gain of the selected gain control, in the unit of the feature that holds it: decibels for SFNC’s Gain, the device’s own for GainRaw.

Source

pub fn set_gain(&mut self, value: f64) -> Result<ResolvedFeature, GenicamError>

Write the gain of the selected gain control (Camera::select_gain), in the unit of the feature that holds it — rounded to the nearest integer for an integer GainRaw — and say which feature that was.

Source

pub fn gain_selectors(&self) -> Result<Vec<String>, GenicamError>

The gain controls GainSelector offers, such as All or Tap1, in the XML’s order. 26 of the 38 vendor-corpus documents declare one.

Source

pub fn select_gain(&mut self, selector: &str) -> Result<(), GenicamError>

Select the gain control Camera::gain and Camera::set_gain act on. Without a call, they act on whichever the camera has selected.

Source

pub fn acquisition_mode(&self) -> Result<String, GenicamError>

The acquisition mode: Continuous, SingleFrame, MultiFrame, or one of a vendor’s own.

Source

pub fn set_acquisition_mode(&mut self, mode: &str) -> Result<(), GenicamError>

Write the acquisition mode by entry name.

Source

pub fn enable_trigger( &mut self, selector: &str, source: &str, ) -> Result<(), GenicamError>

Make trigger selector — FrameStart, most often — wait for source: Software, Line1, … It is selected, given its source, then turned on: the source first, since a camera may refuse to change it while the trigger is on. It stays selected, for Camera::trigger_software.

Source

pub fn disable_trigger(&mut self, selector: &str) -> Result<(), GenicamError>

Turn trigger selector off: the camera runs free again.

Source

pub fn trigger_software(&mut self) -> Result<(), GenicamError>

Fire the selected trigger once (TriggerSoftware). It acts on a trigger whose source is Software (Camera::enable_trigger).

Source

pub fn roi(&self) -> Result<Roi, GenicamError>

The region of interest. A camera without offsets reads as one at the origin.

Source

pub fn set_roi(&mut self, roi: Roi) -> Result<(), GenicamError>

Move and size the region of interest.

A size’s maximum shrinks as its offset grows, and an offset’s as the size grows, so the order of writes decides whether a region can be reached at all: the offsets go to zero first, which only widens the sizes’ range, then the sizes, then the offsets. Every value is checked against its feature’s increment before anything is written.

A camera without offsets accepts only a region at the origin.

Source

pub fn binning(&self) -> Result<(i64, i64), GenicamError>

The binning, horizontal and vertical.

Source

pub fn set_binning( &mut self, horizontal: i64, vertical: i64, ) -> Result<(), GenicamError>

Combine horizontal × vertical pixels into one.

An <Integer> is written the factor. An <Enumeration>, as the Hikrobot MV-CS050-10GC declares its binning, is written the entry whose name ends in the factor (BinningHorizontal2); one whose entries name no factor — SVS’s Off/On — is refused with its entries listed. Both directions are checked before either is written.

Source

pub fn frame_rate(&self) -> Result<f64, GenicamError>

The acquisition frame rate, in frames per second.

Source

pub fn set_frame_rate( &mut self, hz: f64, ) -> Result<ResolvedFeature, GenicamError>

Fix the acquisition frame rate at hz, and say which feature holds it. Where the camera has a switch for it (StandardFeature::FrameRateEnable) it is turned on first: until then the rate is often unavailable, or not applied.

Source

pub fn disable_frame_rate(&mut self) -> Result<(), GenicamError>

Let the camera choose its frame rate again: turn StandardFeature::FrameRateEnable off. A camera without one has nothing to turn off, which is an error.

Source

pub fn user_sets(&self) -> Result<Vec<String>, GenicamError>

The user sets UserSetSelector offers, Default among them, in the XML’s order.

Source

pub fn load_user_set(&mut self, set: &str) -> Result<(), GenicamError>

Load user set set into the camera’s settings, waiting on the calling thread for the camera to finish (up to COMMAND_TIMEOUT).

A load changes features the XML need not name, so every cached value is forgotten afterwards.

Source

pub fn save_user_set(&mut self, set: &str) -> Result<(), GenicamError>

Save the camera’s current settings into user set set, waiting on the calling thread for the camera to finish (up to COMMAND_TIMEOUT). A camera refuses to overwrite Default.

Source

pub fn set_default_user_set( &mut self, set: &str, ) -> Result<ResolvedFeature, GenicamError>

Make user set set the one the camera loads at power-up, and say which feature holds that: SFNC 2’s UserSetDefault, or the older UserSetDefaultSelector.

Source§

impl<T: UsbTransfer + 'static> Camera<U3vRegisterIo<T>>

Source

pub fn open_stream( &mut self, options: U3vStreamOptions, ) -> Result<U3vFrameStream, GenicamError>

Open the camera’s stream, ready for acquisition_start: the recipe Camera::open_stream is for GigE Vision, with the camera’s PayloadSize as the hint when the device’s SIRM gives none, and its time sync.

Without PayloadSize, the hint is computed from Width, Height and PixelFormat; a camera that has the feature and cannot answer it is an error, since a computed size misses padding and chunk data.

Source§

impl Camera<GigeRegisterIo>

Source

pub fn open_stream( &mut self, options: StreamOptions, ) -> Result<FrameStream, GenicamError>

Open a GVSP stream from this camera, ready for acquisition_start.

The one recipe every consumer uses (API-17), as GigeRegisterIo::open_stream describes it, with the camera’s PayloadSize and time sync. A camera without a readable PayloadSize still streams: buffers are then sized from each leader.

StreamOptions::monitor instead watches a multicast stream another application configured, claiming and writing nothing; it is the only stream a camera opened with Access::Monitor can open.

Source§

impl<T: RegisterIo> Camera<T>

Source

pub fn new(transport: T, nodemap: NodeMap) -> Self

Create a new camera wrapper from a transport and a nodemap.

Source

pub fn transport(&self) -> &T

Return a reference to the underlying transport.

Source

pub fn transport_mut(&mut self) -> &mut T

Return a mutable reference to the underlying transport.

Source

pub fn nodemap(&self) -> &NodeMap

Access the nodemap metadata.

Source

pub fn nodemap_mut(&mut self) -> &mut NodeMap

Mutable access to the nodemap.

Source

pub fn invalidate(&self, name: &str)

Forget name’s cached value, and those of the registers it is read through and of everything that depends on it, so the next read asks the camera: for a value the camera changed in a way its XML does not describe. See NodeMap::invalidate.

A value the XML declares NoCache needs none of this, and one with a <PollingTime> is read again once that has passed (ADR-0029).

Source

pub fn invalidate_all(&self)

Forget every cached value, after something that may have changed the camera wholesale. Camera::load_user_set does this itself.

Source

pub fn generation(&self) -> u64

The nodemap’s current generation, advanced by every write and every invalidation: where a viewer starts Camera::changed_since from.

Source

pub fn changed_since(&self, since: u64) -> (Vec<String>, u64)

The features — and the nodes behind them — that changed after generation since, in document order, and the generation now. A viewer re-reads the ones it shows. See NodeMap::changed_since.

Source

pub fn poll(&self) -> Vec<String>

Invalidate the values whose <PollingTime> has passed since they were read, and return their names with those of everything read through them: what a viewer should read again. Call it as often as the shortest polling time a viewer shows. See NodeMap::poll.

Source

pub fn enum_entries(&self, name: &str) -> Result<Vec<String>, GenicamError>

List available entries for an enumeration feature.

Source

pub fn feature_state(&self, name: &str) -> Result<FeatureState, GenicamError>

Read everything a viewer needs about a feature at once: its typed value, what it permits now, whether it is implemented and available, its range, the enumeration entries it accepts, and its unit.

See NodeMap::feature_state.

Source

pub fn get_integer(&self, name: &str) -> Result<i64, GenicamError>

Read an integer feature: an <Integer>, an <IntConverter>, an integer <IntSwissKnife>, or a <Converter> rounded to the nearest integer. See NodeMap::get_integer.

Source

pub fn set_integer( &mut self, name: &str, value: i64, ) -> Result<(), GenicamError>

Write an integer feature, within its bounds and increment.

Source

pub fn get_float(&self, name: &str) -> Result<f64, GenicamError>

Read a float feature: a <Float>, a <Converter>, a float <SwissKnife>, or an <IntConverter>. An <Integer> is not a float: read it with Camera::get_integer.

Source

pub fn set_float(&mut self, name: &str, value: f64) -> Result<(), GenicamError>

Write a float feature, within its bounds.

Source

pub fn get_bool(&self, name: &str) -> Result<bool, GenicamError>

Read a boolean feature.

Source

pub fn set_bool(&mut self, name: &str, value: bool) -> Result<(), GenicamError>

Write a boolean feature.

Source

pub fn get_enum(&self, name: &str) -> Result<String, GenicamError>

Read an enumeration: the name of its current entry.

Source

pub fn set_enum(&mut self, name: &str, entry: &str) -> Result<(), GenicamError>

Write an enumeration by entry name.

Source

pub fn get_string(&self, name: &str) -> Result<String, GenicamError>

Read a <StringReg>.

Source

pub fn set_string( &mut self, name: &str, value: &str, ) -> Result<(), GenicamError>

Write a <StringReg>, NUL-padded to its length.

Source

pub fn get_register(&self, name: &str) -> Result<Vec<u8>, GenicamError>

Read a <Register>’s bytes. See NodeMap::get_register.

Source

pub fn set_register( &mut self, name: &str, data: &[u8], ) -> Result<(), GenicamError>

Write a <Register>’s bytes, exactly its length. See NodeMap::set_register.

Source

pub fn get(&self, name: &str) -> Result<String, GenicamError>

Read a feature as text, formatted by its type: for a program that does not know the type in advance, such as a command line. The typed accessors (Camera::get_integer and the like) read without the round trip. See NodeMap::get_text.

A category has no value and a command none to read: both are errors.

Source

pub fn set(&mut self, name: &str, value: &str) -> Result<(), GenicamError>

Write a feature from text, parsed by its type: the counterpart of Camera::get. Text that does not parse as the feature’s type is GenApiError::InvalidText (in GenicamError::GenApi), and nothing is written.

A command is not set but executed, with Camera::execute_command or Camera::execute_and_wait: setting one is an error, and nothing is written. So is setting a category.

Source

pub fn save_features( &mut self, out: &mut impl Write, ) -> Result<Configuration, GenicamError>

Save the camera’s configuration — every feature its XML marks <Streamable> — to out, in the GenApi feature-file layout (ADR-0028). A feature behind a selector is saved under each of the selector’s entries, and the selector is put back; behind a selector that cannot be set now — not implemented, not available, locked — it has one value, saved once.

Returns what was saved, and in Configuration::omitted what was left out and why; the file carries the same as comments. Save while the camera is not acquiring: what TLParamsLocked locks is left out otherwise.

Source

pub fn load_features( &mut self, input: &mut impl Read, ) -> Result<LoadReport, GenicamError>

Restore a configuration Camera::save_features wrote, or another GenApi-based tool did in the same layout.

Values are written in the order the camera’s dependencies require, a write that fails is tried once more after the others, and the report lists every value that still could not be written, with the reason. A file saved from another camera model, or another major version of its XML, is loaded too, with a warning in the report. Only a file that cannot be read at all is an error.

Source

pub fn load_configuration( &mut self, configuration: &Configuration, ) -> LoadReport

Restore a configuration already read, such as the one Camera::save_features returned: Camera::load_features without the file.

Source

pub async fn time_calibrate( &mut self, samples: usize, interval_ms: u64, ) -> Result<(), GenicamError>

Capture device/host timestamp pairs and fit a mapping model.

Source

pub fn map_dev_ts(&self, dev_ticks: u64) -> Option<SystemTime>

Map device tick counters to host time using the fitted model; None before time_calibrate has fitted one.

Source

pub fn time_sync(&self) -> &TimeSync

Inspect the timestamp synchroniser state.

Source

pub fn time_reset(&mut self) -> Result<(), GenicamError>

Reset the device timestamp counter when supported by the camera.

Source

pub fn execute_command(&mut self, name: &str) -> Result<(), GenicamError>

Execute a command feature by name.

Camera::set already dispatches to this for Node::Command, but only from a &str value; callers that hold a command name directly would otherwise have to reach through Camera::nodemap_mut and Camera::transport at once, which the borrow checker rejects from outside the struct. Splitting the two fields here is the same thing Camera::acquisition_start does.

Source

pub async fn execute_and_wait( &mut self, name: &str, timeout: Duration, ) -> Result<(), GenicamError>

Execute a command and wait until the camera reports it finished.

GenICam Standard v2.1.1 §2.8.8: “the state of other nodes can depend on the completion of the Command therefore applications … should always wait for the command completion by calling IsDone immediately after the Execute”. This polls NodeMap::is_done at the command’s <PollingTime> — every COMMAND_POLL_INTERVAL when it declares none — until it answers true or timeout passes.

A command whose register path is write-only — most of them — is done as soon as the write is acknowledged, so this returns as quickly as Camera::execute_command does. A self-clearing command (its register reads back the command value until the device has finished) is waited on. Reads made afterwards see the state the command left.

Returns GenicamError::CommandNotDone when the camera has not finished by timeout; the command was still executed.

Source

pub fn execute_and_wait_blocking( &mut self, name: &str, timeout: Duration, ) -> Result<(), GenicamError>

Camera::execute_and_wait on the calling thread, for a program without an async runtime; it sleeps between polls.

Source

pub fn is_done(&self, name: &str) -> Result<bool, GenicamError>

Whether the command name has finished: GenICam’s IsDone.

See NodeMap::is_done; Camera::execute_and_wait polls it.

Source

pub fn acquisition_start(&mut self) -> Result<(), GenicamError>

Start acquisition: set TLParamsLocked, then execute AcquisitionStart.

TLParamsLocked is how the transport layer tells the camera’s XML a stream is running, so that features which would change the payload — Width, PixelFormat — are locked until it stops (33 of the 38 vendor-corpus documents declare it). A camera without it is started all the same; one that refuses it is started with a warning. If the start fails, the lock is cleared again.

Source

pub fn acquisition_stop(&mut self) -> Result<(), GenicamError>

Stop acquisition: execute AcquisitionStop, then clear TLParamsLocked — cleared even when the stop fails, so the features it locked can be written again.

Source

pub fn configure_chunks( &mut self, cfg: &ChunkConfig, ) -> Result<(), GenicamError>

Configure chunk mode and enable the requested selectors.

Source

pub fn with_chunks<R>(&mut self, frame: &Frame, f: impl FnOnce(&Self) -> R) -> R

Read features from a frame’s chunks: attach them to the nodemap’s chunk ports, run f, and detach them again.

Inside f, cam.get("ChunkExposureTime") reads the value this frame carried — from the chunk whose ID the camera’s XML names, at the offset and in the byte order the XML declares (ADR-0026). Nothing is read from the device for it. A frame without chunks attaches none, and chunk features then fail with GenApiError::NotAttached.

let exposure = camera.with_chunks(frame, |cam| cam.get("ChunkExposureTime"))?;
Source

pub fn chunk_features( &mut self, frame: &Frame, ) -> Vec<(String, Result<String, GenicamError>)>

Every feature frame’s chunks feed, with its value or the error that kept it from being read, sorted by name.

The features are the ones the camera’s XML lists in a category and derives from a chunk port whose chunk the frame carries — ChunkTimestamp, not the ChunkTimestamp_Val register behind it. Empty for a frame without chunks.

Source

pub fn with_event<R>(&mut self, event: &Event, f: impl FnOnce(&Self) -> R) -> R

Read features from a received event: attach it to the ports whose <EventID> is the event’s, run f, and detach events again.

Inside f, cam.get("EventExposureEndTimestamp") reads the event’s own bytes at the offset the camera’s XML declares — 0x8 for the timestamp on every corpus document, which is where the event header has it.

Source

pub fn event_features( &mut self, event: &Event, ) -> Vec<(String, Result<String, GenicamError>)>

Every feature event feeds, with its value or the error that kept it from being read, sorted by name: the category features derived from a port whose <EventID> is the event’s. Empty when the XML declares no port for it.

Source

pub fn event_name(&self, event_id: u16) -> Option<String>

The EventSelector entry an event with event_id belongs to, when the XML says.

SFNC names an event’s data features Event<Entry> and Event<Entry>Timestamp, so an entry with either feature on the port whose <EventID> is event_id names the event. Otherwise an entry whose literal <Value> is the ID does, as Basler’s do. None when neither matches, or the camera has no EventSelector.

Source§

impl Camera<GigeRegisterIo>

What only a GigE Vision camera has: a GVCP message channel for events and a stream channel that can go to a multicast group. Streams and control privilege are here too (Camera::open_stream, GigeRegisterIo::control_state). A USB3 Vision camera has none of them, so none of this compiles against one.

Source

pub async fn configure_events( &mut self, local_ip: Ipv4Addr, port: u16, enable_ids: &[&str], ) -> Result<(), GenicamError>

Configure the GVCP message channel and enable delivery of the requested events.

GigE Vision only:

ⓘ
let _ = camera.configure_events(std::net::Ipv4Addr::LOCALHOST, 10020, &[]).await;
Source

pub fn configure_stream_multicast( &mut self, stream_idx: u32, group: Ipv4Addr, port: u16, ) -> Result<(), GenicamError>

Configure the stream channel for multicast delivery: point GevSCDA at group and GevSCPHostPort at port.

A multicast destination address is all it takes; SFNC has no separate enable. Without the SFNC nodes the bootstrap registers are written directly. Camera::open_stream with StreamOptions::multicast does this and starts receiving too.

GigE Vision only:

ⓘ
let _ = camera.configure_stream_multicast(0, std::net::Ipv4Addr::new(239, 0, 0, 1), 5000);
Source

pub async fn open_event_stream( &self, local_ip: Ipv4Addr, port: u16, ) -> Result<EventStream, GenicamError>

Open a GVCP event stream bound to the provided local endpoint.

GigE Vision only:

ⓘ
let _ = camera.open_event_stream(std::net::Ipv4Addr::LOCALHOST, 10020).await;
Source§

impl<T: UsbTransfer + 'static> Camera<U3vRegisterIo<T>>

What only a USB3 Vision camera has: an event interface, whose events arrive on a USB endpoint rather than a GVCP message channel (backlog TC-27 (4)). Its stream is Camera::open_stream too.

Source

pub fn configure_events( &mut self, enable_ids: &[&str], ) -> Result<(), GenicamError>

Turn on notification of the events named — "ExposureEnd", say — through SFNC’s EventSelector and EventNotification. They arrive on a stream from open_event_stream.

Source

pub fn open_event_stream(&self) -> Result<U3vEventStream, GenicamError>

Set the event interface’s EventEnable and read its endpoint on a thread of its own. Events carry their device time in ns, mapped to host time once time_calibrate has fitted a clock; dropping the stream restores the previous EventEnable word.

Trait Implementations§

Source§

impl<T: Debug + RegisterIo> Debug for Camera<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for Camera<T>

§

impl<T> !RefUnwindSafe for Camera<T>

§

impl<T> !Sync for Camera<T>

§

impl<T> !UnwindSafe for Camera<T>

§

impl<T> Send for Camera<T>
where T: Send,

§

impl<T> Unpin for Camera<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Camera<T>
where T: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more