OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

ProcessInterface

public sealed class ProcessInterface : IDisposable

A camera's process interface: industrial I/O on the camera.

Obtained from ThermalCamera.OpenProcessInterface. Dispose it before the camera it came from. The interface belongs to the camera, and disposing the camera disposes it. Getting the order wrong is reported as an ObjectDisposedException rather than punished, but it is still the wrong order.

Threading. A PIF on a real camera is driven by the SDK's own frame thread as well as by your code: a camera reports its inputs with each frame, and the SDK decodes them, publishes them and writes the internal-temperature outputs from there. A lock of your own serialises your threads against each other and cannot serialise them against that one, which is why this paragraph exists.

Safe while the camera is streaming, and from several threads at once: ProcessInterface.Configure(…) and ProcessInterface.GetConfiguration, every per-channel read and write, ProcessInterface.ReadAll, ProcessInterface.Poll, the output block, the probe temperature, ProcessInterface.ReadFailSafeHealth and the decoded-input handler. A table applied by ProcessInterface.Configure(…) becomes visible to the frame pass on the next frame rather than part-way through the one in flight -- the alternative is a frame built from half of one table and half of another.

Not safe against the frame thread, so serialise these yourself or call them before starting the stream: declaring or re-detecting the interface's identity, setting the analog calibration, and SetFailSafe. Those are declaration-time calls rather than per-frame ones, and this list is deliberately the whole of what is covered -- do not read it as wider.

Two things deliberately do not live here. Alarms: a PIF input that should ring, or an output a ringing alarm should drive, is an alarm rule naming that channel, not a threshold on this class. Change notification: every channel's value is published on each ProcessInterface.Poll, so "tell me when this input changes" is also a rule. A second alarm model is exactly what version 12 removes.

A process interface is routinely absent or unplugged, so the read methods come in pairs: one that throws, and a Try… that returns false. A polling loop should not have to be a try block.

Example

if (!camera.TryOpenProcessInterface(out ProcessInterface? pif))
{
    Console.WriteLine("this camera has no process interface");
    return;
}

using (pif)
{
    Console.WriteLine($"{pif.Identity.Kind}, " +
                      $"{pif.Hardware.DigitalOutputCount} digital outputs");

    pif.Configure([
        new PifChannel
        {
            Index = 0,
            Direction = PifDirection.Output,
            Signal = PifSignal.Digital,
            Kind = PifChannelKind.ExternalComm,
        },
    ]);

    pif.WriteDigitalOutput(0, DigitalState.High);
}

ProcessInterface: properties

public AnalogCalibration AnalogCalibration { get; set; }

The device-wide analog calibration the camera's calibration file declared.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Reading it gives the only analog calibration an application can see. On an interface with its own EEPROM it takes part in no value the camera produces; the per-channel trim that does is reported by ProcessInterface.GetChannelTrim(…).

Setting it changes nothing on a camera. The value is stored and the channel table re-encoded with it, but the pair handed to the device is the one read from the calibration file when the interface was created. The setter is kept because it is how the layer that owns calibration data pushes these values down; the interface never reads a calibration file itself.

public Nullable<float> ExternalProbeTemperature { get; }

The external temperature probe's reading, in the SDK's temperature unit (Celsius unless Sdk.TemperatureUnit chose Fahrenheit), or null if none has arrived.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

The probe is its own measurement, not a channel: it has no index, no gain and no direction. Declaring PifDeviceKind.TemperatureProbe made ProcessInterface.Identity read it back and nothing returned a temperature: the SDK decoded the probe out of each frame and kept it where only the SDK could reach it.

null on a camera with no probe fitted, and until the first frame that carries a reading. The same value is published as SignalField.ProbeTemperature on the device domain, so an interlock on the reference probe is an ordinary alarm rule rather than a poll.

Only while the interface is declared a temperature probe (PifDeviceKind.TemperatureProbe): no camera can detect a probe, so the declaration is the only way one is known. On any other interface, and on a camera with none, this is null whatever the frame carries. Up to 12.0.20 it read 10.125 C on a PI 640 with an Industrial (mA) PIF and 34.1 C on a PI 4x0i with nothing on the connector.

Whether a frame carries a reading is decided at the frame decode, per camera family, by the probe's I2C bus answering validly: a read nothing acknowledged (the bus's all-zero or all-ones non-answer) counts as no probe, never as a temperature, so an unpopulated connector reads null rather than a full-scale 511.9375 C.

null again the moment a frame stops carrying a reading, and the signal is invalidated with it, so a rule on the probe goes AlarmState.Orphaned and an AlarmCompare.Invalid watchdog on it fires. Before v12.0 this held the last value a frame had carried, presented as current, for the life of the camera, and a stale temperature that looks live is worse than an error, because it gets used. There is no hold-off: the first frame without a reading is the one that clears it.

What a camera's firmware writes once a probe stops answering has not been measured. This reports the loss faithfully when the telemetry reports it; a firmware that latched the last value instead would be indistinguishable from a steady probe.

public FailSafeConfiguration FailSafe { get; set; }

The fail-safe watchdog's configuration.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Example

pif.FailSafe = new FailSafeConfiguration
{
    IsEnabled = true,
    ChannelIndex = 1,
    Period = TimeSpan.FromMilliseconds(100),
};

The period is bounded by PifHardwareInfo.MaxFailSafePeriod, and FailSafeConfiguration.TripOnAlarm and FailSafeConfiguration.TripOnFlagTimeout are refused. Read ProcessInterface.ReadFailSafeHealth to find out whether the line is keeping up.

public PifHardwareInfo Hardware { get; }

What the attached interface can do.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.
public PifIdentity Identity { get; }

Who is attached, and how the SDK knows.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.
public bool IsConnected { get; }

Whether the interface is reachable right now.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.
public bool OutputsBlocked { get; set; }

Whether every output is currently held at its inactive level.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Setting this holds the outputs without losing the configuration or the alarm state underneath, for use while a process is knowingly disturbed. They resume when it is released.

ProcessInterface: methods

public void Configure(IReadOnlyList<PifChannel> channels)

Apply a whole channel table, replacing whatever was configured.

  • channels: The table. An empty one clears the configuration.

  • Throws ArgumentNullException: channels is null.

  • Throws OptrisSdkException: The table was rejected. The message names the channel and the problem.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

The table is validated in full before anything is written, so a rejected configuration leaves the device exactly as it was. Every configured output is then re-asserted, even one whose settings did not change -- changing a channel's levels has to reach the pin.

Example

pif.Configure([
    new PifChannel
    {
        Index = 0,
        Direction = PifDirection.Output,
        Signal = PifSignal.Digital,
        Kind = PifChannelKind.ExternalComm,
    },
    new PifChannel
    {
        Index = 0,
        Direction = PifDirection.Input,
        Signal = PifSignal.Analog,
        Kind = PifChannelKind.UncommittedValue,
        Name = "pressure",
        Unit = "bar",
    },
]);
public void DeclareIdentity(PifDeviceKind kind, int deviceCount = 1)

State what is attached, when the camera cannot tell.

  • kind: What is attached.

  • deviceCount: How many physical devices, for a stackable interface.

  • Throws OptrisSdkException: The camera does not accept that kind at all (SdkStatus.NotSupported), or will not accept it while another interface occupies the connector (SdkStatus.InvalidState). The message says which interface is in the way.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Required on the PI 1 family, for a proprietary interface, for an external temperature probe, and on an autonomous camera whose type switch disagrees with what is physically there. On a camera that can detect its interface this overrides what it reported.

This is not how an interface connected or powered up after the camera is brought into use. ProcessInterface.RedetectIdentity is, on every camera that can detect its interface at all: it asks the camera again, and an interface that was not there at open is found. Declaring is for the kinds a camera cannot see. On a PI camera other than the PI 1 the type comes from the interface's own EEPROM, and a Standard or Industrial declaration is refused in every state, attached or not; ProcessInterface.GetSupportedDeviceKinds does not offer them, so an application that builds its choices from that list never reaches the refusal. The PI 1 family is the other way round: it cannot read the EEPROM at all, so re-detection never finds anything and declaring is the only route.

This paragraph used to say declaring was "also how an interface powered up after the camera is brought into use", which sent a PI 450i user with a late Standard interface to a call that refuses it.

This clears the channel table. A table configured against one interface does not carry over to a different one. The declared interface's channels are usable straight away; no reopen is needed in between.

All or nothing. A camera that refuses the declaration leaves this interface exactly as it was -- the same identity, the same hardware description, the same channel table, the same output levels and the same alarm rules holding them. Later calls are unaffected by the refusal.

Example

// A PI 1: the firmware cannot see its PIF, so say what is there.
pif.DeclareIdentity(PifDeviceKind.Standard);
public void Dispose()

Release this interface.

Does not reconfigure or disconnect anything: it releases the reference, nothing more. Dispose it before the camera it came from.

public PifChannelTrim GetChannelTrim(PifAnalogDirection direction, int index)

The trim one analog channel actually has, from the device.

Returns: The trim. Check PifChannelTrim.Source before believing the gain and offset.

  • Throws SdkConfigurationException: index is past the end.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.
public IReadOnlyList<PifChannel> GetConfiguration()

The channel table currently configured.

Returns: One entry per configured channel.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.
public AnalogRange GetSupportedAnalogOutputRange(int index)

One of the analog output ranges the hardware supports.

Returns: The range.

  • Throws SdkConfigurationException: index is past the end.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.
public IReadOnlyList<PifDeviceKind> GetSupportedDeviceKinds()

The interface kinds that can be declared on this camera.

Returns: The kinds that can be declared on this camera.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

A camera family accepts a subset. Offering the rest in a user interface would offer configurations that cannot be applied. Offer these, plus ProcessInterface.RedetectIdentity as "automatic".

These are not the kinds that can be attached. On a PI camera a Standard or Industrial interface is read from its own EEPROM and can never be declared, so it is absent here while being a perfectly normal value of PifIdentity.Kind. Render the attached kind from the identity; offer this list as the choice.

Example

foreach (PifDeviceKind kind in pif.GetSupportedDeviceKinds())
{
    Console.WriteLine(kind);
}
public void OnInputDecoded(Action<PifInputValue>? handler)

Be told when a configured input yields a new decoded value.

  • handler: What to call, or null to stop being told.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

This exists because emissivity, ambient temperature and named values feed the measurement pipeline, which is a data path rather than an alarm. Anything that wants to react to a value is an alarm rule, not this.

The handler runs on whichever thread calls ProcessInterface.Poll, or on the SDK's frame thread when a stream is running. Keep it short, and do not call back into this interface from it.

Observing only. Subscribing does not take the value away from the measurement. An input configured as Emissivity or Ambient Temperature still reaches the radiometry, and does so before the handler runs -- so reading Radiation.Emissivity inside the handler gives the value being handed over, not the one it replaced. Passing null, and disposing this interface, stop the notifications and nothing else.

Subscribing while the camera is running calls the handler once per configured input with its current value, rather than leaving it silent until something changes. An input sitting at a steady level is the normal case, not an unusual one.

Example

pif.OnInputDecoded(value =>
    Console.WriteLine($"channel {value.ChannelIndex}: {value.Value}"));

pif.Poll();
public void Poll()

Advance the interface: read inputs, decode them, publish signals, dispatch handlers, and step the fail-safe watchdog.

  • Throws OptrisSdkException: The poll failed.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Call it as often as the process needs; the watchdog paces itself from its own period rather than from the call rate. When a stream is running, per-frame inputs additionally arrive bound to their frame, which is the authoritative pairing.

Example

using var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(50));
while (await timer.WaitForNextTickAsync(token))
{
    pif.Poll();
}
public IOSnapshot ReadAll()

Read every channel in one transaction.

Returns: All the channel values, as of one instant.

  • Throws OptrisSdkException: The read failed.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Prefer this to a read per channel when the values are related: separate reads can straddle a change and describe a state the machine was never in.

Most process interfaces report their inputs with each frame rather than on demand. Until the camera has delivered one, the snapshot comes back with IOSnapshot.InputsKnown false and its inputs unknown; it does not throw, so polling this while a stream starts is cheap.

Example

IOSnapshot io = pif.ReadAll();
Console.WriteLine($"inputs: {string.Join(", ", io.DigitalInputs)}");
public float ReadAnalogInput(int index)

Read an analog input, in the channel's configured unit.

  • index: The flat channel index.

Returns: The value, in the channel's own unit.

  • Throws OptrisSdkException: The read failed.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

On a channel whose own unit is a temperature (see PifChannel), that unit is the SDK's temperature unit (Celsius unless Sdk.TemperatureUnit chose Fahrenheit).

Use ProcessInterface.TryReadAnalogInput(…) in a polling loop.

public float ReadAnalogOutput(int index)

Read back what an analog output is driving, as it is on the wire.

  • index: The flat channel index.

Returns: The level the pin is driving, in volts or milliamperes.

  • Throws OptrisSdkException: The read failed.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

In the unit of the channel's AnalogRange: volts in 0-10 V, milliamperes in 0-20 mA and 4-20 mA, and volts on an output with no channel configured. Answered from what this SDK last drove, because no PIF can read a pin back, so it is "what was asked for" rather than a measurement of the wire.

Single.NaN when nothing has driven it since the interface was attached or last configured. Never the reading of an input: up to 12.0.28 an undriven output answered with the analog input of the same index on a simulated interface, and threw on a camera.

The same number in Celsius and in Fahrenheit. A wire value is never a temperature, so on a channel whose own unit is a temperature this is not the number ProcessInterface.WriteAnalogOutput(…) took: 50 C written at 0.1 V per degree and 0.5 V at zero (122 F in Fahrenheit) reads back 5.5 in either unit. Up to 12.0.27 Fahrenheit answered 41.9.

public DigitalState ReadDigitalInput(int index)

Read a digital input.

  • index: The flat channel index.

Returns: The line's state.

  • Throws OptrisSdkException: No interface is attached, the channel does not exist, or the read failed.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Use ProcessInterface.TryReadDigitalInput(…) in a polling loop, where an absent interface is routine rather than exceptional.

public DigitalState ReadDigitalOutput(int index)

Read back what a digital output is driving.

  • index: The flat channel index.

Returns: The level the pin is driving, or DigitalState.Unknown.

  • Throws OptrisSdkException: The read failed.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

What this SDK last drove onto it. DigitalState.Unknown when nothing has driven it since the interface was attached or last configured, as IOSnapshot.DigitalOutputs reports that pin on a camera; a reading, not an exception. Never the level of an input: up to 12.0.28 an undriven output answered with the digital input of the same index on a simulated interface, and threw on a camera.

public FailSafeStatus ReadFailSafeHealth()

What the fail-safe line is actually doing, measured rather than asserted.

Returns: The line's health at this instant.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Answered at the moment of the call, from the time since the last edge, so a heartbeat that has stopped is reported as stopped. A status updated only when an edge arrived would go on reporting the last healthy answer for ever, which is the shape of the defect this property exists to close.

public float ReadRawAnalogInput(int index)

Read one analog input as it is on the wire, in volts, before any channel decode.

  • index: The flat channel index.

Returns: The wire reading in volts, or Single.NaN before the first reading has arrived.

  • Throws OptrisSdkException: The read failed.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

The single-read counterpart of IOSnapshot.RawAnalogInputs. ProcessInterface.ReadAnalogInput(…) answers in the channel's own unit, so on a configured channel the wire reading was unobtainable: with a gain of 0.1 and 4.0 V on the pin, ProcessInterface.ReadAnalogInput(…) answers 40.0 and nothing answered 4.0.

Always volts, whether or not a channel is configured over the pin, and in either temperature unit. A handler registered with ProcessInterface.OnInputDecoded(…) may call this for the index it was handed: the decoded value it received and the reading this returns come from the same poll.

public void RedetectIdentity()

Ask the camera again what is attached.

  • Throws OptrisSdkException: This camera cannot be asked to detect its interface again.
  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Two uses, and nothing checks which one you are in: this runs from any state.

The first is an interface connected or powered up after the camera was opened. From PifDetection.Unknown with PifDeviceKind.None, an empty socket at open, this re-runs discovery and finds it, and on a camera that reads its interface from an EEPROM it is the only route: ProcessInterface.DeclareIdentity(…) refuses the kinds such a camera can see for itself. Offer it as "detect again" on a card that is reporting no interface, not only on one reporting a declared one. Finding nothing is a result rather than an error, so it is safe to offer unconditionally.

The second is the way out of ProcessInterface.DeclareIdentity(…). A declaration overrides detection, and nothing used to undo it: a user who declared Standard to try something had to close and reopen the camera, restarting the stream and re-applying every region and rule. This asks the camera again and rebuilds the identity from the answer.

PifIdentity.Detection afterwards is PifDetection.Detected when the camera named a kind and PifDetection.Unknown when it named none. Never PifDetection.Declared. Finding nothing is a result, not an error.

On an autonomous camera a declaration is written into the camera rather than held here, so the camera then reports the declared kind as its own and a re-detection confirms it. Declare PifDeviceKind.None, or reopen the camera, to undo one of those.

This clears the channel table, and is all or nothing, exactly as a declaration is.

Example

// "Automatic (detected)" in an identity picker.
pif.RedetectIdentity();
Console.WriteLine(pif.Identity.Detection);  // Detected
public bool TryReadAnalogInput(int index, out float value)

Read an analog input, without throwing if it cannot be read.

Returns: true if the value was read.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

Example

if (pif.TryReadAnalogInput(0, out float bar))
{
    Console.WriteLine($"{bar:F2} bar");
}
public bool TryReadDigitalInput(int index, out DigitalState state)

Read a digital input, without throwing if it cannot be read.

Returns: true if the value was read.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

This is the form to use in a poll loop. An interface that is unplugged, or a channel the hardware does not have, is a routine answer here rather than an exception.

Example

while (running)
{
    if (pif.TryReadDigitalInput(0, out DigitalState state))
    {
        Console.WriteLine(state);
    }
    await Task.Delay(100);
}
public void WriteAnalogOutput(int index, float value)

Drive an analog output, in the channel's configured unit.

  • index: The flat channel index.

  • value: The value, in the channel's own unit.

  • Throws OptrisSdkException: The write failed.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.

On a channel whose own unit is a temperature (see PifChannel), that unit is the SDK's temperature unit (Celsius unless Sdk.TemperatureUnit chose Fahrenheit), and the channel's gain and offset turn it into the level on the wire. ProcessInterface.ReadAnalogOutput(…) reads back that level, not the temperature.

Otherwise the unit is the channel's AnalogRange own -- volts in 0-10 V, milliamperes in 0-20 mA and 4-20 mA, never amperes. That is the only unit any analog value above the wire is in, on every path: this call, both of an alarm output's levels, the shutter's three levels, the frame-sync pulse height, the fail-safe heartbeat and the level a blocked output holds.

SDK 11 settled the same question the other way, in amperes, because its ranges carried no unit to agree with; this one's AnalogRange carries a unit label and this is it. A value in amperes therefore reads as a thousandth of what was meant, and in 4-20 mA used to come out at full scale whatever it was.

The value is clamped into the range. A non-finite value is refused rather than clamped.

public void WriteDigitalOutput(int index, DigitalState state)

Drive a digital output.

  • index: The flat channel index.

  • state: The level to drive.

  • Throws OptrisSdkException: The write failed.

  • Throws ObjectDisposedException: This interface, or the camera it came from, has been disposed.