OptrisOptrisDocumentation

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

CsvOptions

pub struct CsvOptions

How a CSV snapshot spells its table, for a spreadsheet set to a locale other than English.

CsvOptions::default writes exactly the CSV Camera::save_snapshot writes with SnapshotFormat::Csv: , between values, . before the decimals, nan for a pixel that was not measured, and the # header lines. That is the form for programs, and it stays the default so that existing readers keep working.

A spreadsheet set to German, French or most other European locales splits on ; and reads , as the decimal separator, so it opens the default file as one text column per row. Pass this to Camera::save_csv_snapshot to write the spelling it expects:

# fn main() -> optris_sdk::Result<()> {
use optris_sdk::{Camera, CsvOptions};

let mut camera = Camera::open()?;
camera.start()?;

let csv = CsvOptions::default()
    .with_delimiter(';')
    .with_decimal_separator(',')
    .with_unmeasured_left_empty(true);
camera.save_csv_snapshot("capture.csv", &csv, None)?;
# Ok(())
# }

The file depends on these settings and on nothing else; the process locale never reaches it.

CsvOptions::with_temperature_unit writes the file in degrees Fahrenheit, and composes with the spelling:

# fn main() -> optris_sdk::Result<()> {
use optris_sdk::{Camera, CsvOptions, TemperatureUnit};

let mut camera = Camera::open()?;
camera.start()?;

let csv = CsvOptions::default().with_temperature_unit(TemperatureUnit::Fahrenheit);
camera.save_csv_snapshot("capture_f.csv", &csv, None)?;
# Ok(())
# }

The fields are private and set through the with_ methods, so a later SDK can add a setting without breaking code that builds one.

Camera::save_snapshot: crate::Camera::save_snapshot Camera::save_csv_snapshot: crate::Camera::save_csv_snapshot SnapshotFormat::Csv: crate::SnapshotFormat::Csv

CsvOptions — methods

pub fn delimiter(&self) -> char

What goes between two values on a row.

pub fn decimal_separator(&self) -> char

What goes before the decimals.

pub fn leave_unmeasured_empty(&self) -> bool

Whether a pixel that was not measured is written as an empty field rather than nan.

pub fn omit_header_lines(&self) -> bool

Whether the # header lines are left out.

pub fn temperature_unit(&self) -> TemperatureUnit

The unit every temperature in the file is written in.

pub fn with_delimiter(mut self, delimiter: char) -> Self

Set what goes between two values on a row: ',' (the default), ';' or '\t'.

Anything else is refused with Status::InvalidArgument when the snapshot is saved, and nothing is written.

pub fn with_decimal_separator(mut self, decimal_separator: char) -> Self

Set what goes before the decimals: '.' (the default) or ','.

Anything else is refused with Status::InvalidArgument when the snapshot is saved, and so is a decimal separator equal to the delimiter, because a reader could not tell 1,5 from two values. It applies to every number in the file, the # header lines included.

pub fn with_unmeasured_left_empty(mut self, leave_empty: bool) -> Self

Write a pixel that was not measured as an empty field instead of nan. Every spreadsheet reads an empty field as a blank cell; it reads nan as text.

pub fn with_header_lines_omitted(mut self, omit: bool) -> Self

Leave out the # header lines, so the file is the table and nothing else.

pub fn with_temperature_unit(mut self, unit: TemperatureUnit) -> Self

Set the unit every temperature in the file is written in, the pixels and the ambient header line: TemperatureUnit::Celsius (the default) or TemperatureUnit::Fahrenheit.

In Fahrenheit each value is converted at full precision and then rounded once to the file's two decimals, half away from zero, as crate::temperatures::format rounds; nan stays nan; the header says # Unit: degF and the ambient line is keyed AmbientTempF. Every file, Celsius too, names its unit on a # Unit: line, which goes with the other header lines when they are left out. TemperatureUnit::Other is refused with Status::InvalidArgument when the snapshot is saved.