OptrisOptrisDocumentation

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

DeviceMetadata

public static class DeviceMetadata

What the user has written down about one camera: its name above all.

A camera reports a model (PI 640i) and a serial, and neither is what an operator calls it. This is where oven inlet lives.

Metadata is stored on this machine, keyed by the camera's serial: the only stable identity a camera has, since a USB path changes when the plug moves. It survives a restart and a re-plug, and none of these calls opens or claims the camera, so naming a camera never takes it away from whatever is streaming from it.

The entries are an open key/value map rather than a fixed set of properties, so a location or an asset tag needs no new API. The one key the SDK reads itself is DeviceMetadata.NameKey, which is what DeviceInfo.Name reports.

Names are not required to be unique and the SDK does not enforce it: four cameras on one line may all be called oven. The serial stays the identity.

Text is UTF-8 end to end. A camera may be called 熔炉入口 or Ofeneinlauf as readily as oven inlet..NET strings are UTF-16 and the native SDK is UTF-8, and the conversion in both directions is lossless. Keys and values are checked for well-formed encoding and for control characters, and for nothing else about the character set.

The SDK does not normalise. Two names that look identical but differ in Unicode normal form (NFC against NFD) are two different values, and DeviceMetadata.Get(…) will not find one when given the other. Normalise on the way in if you need them folded together; silently rewriting what a user typed would be the worse behaviour.

Example

foreach (DeviceInfo device in Sdk.EnumerateDevices())
{
    Console.WriteLine($"{device.Name}: {device.Model} ({device.Serial})");
}

DeviceMetadata.SetName("21074191", "oven inlet");
DeviceMetadata.Set("21074191", "location", "hall 2");

DeviceMetadata: constants

public const int MaxKeyLength = 63

The longest key the SDK accepts, in UTF-8 bytes.

public const int MaxValueLength = 63

The longest value the SDK accepts, in UTF-8 bytes.

Bytes, not.NET characters, and the difference matters for anything but ASCII: 63 bytes is 63 Latin letters but only 21 Chinese ones. Measure with Encoding.UTF8.GetByteCount(name), not name.Length.

An over-long value is rejected rather than cut short, because cutting UTF-8 to a byte count splits a character in half.

A value this long always fits in DeviceInfo.Name, so enumeration never truncates what was stored.

public const string NameKey = "name"

The metadata key that carries the camera's name.

DeviceMetadata: methods

public static void Clear(string serial)

Forget everything recorded about one camera, name included.

  • serial: The camera's serial number.

  • Throws OptrisSdkException: The store could not be written.

Clearing a camera that has no metadata is not an error.

public static string Get(string serial, string key)

Read one metadata value.

  • serial: The camera's serial number.
  • key: The key to read.

Returns: The value, or an empty string when the key is not set. An absent key is not an error, so an optional field needs no special case.

  • Throws OptrisSdkException: The store could not be read.
public static IReadOnlyDictionary<string, string> GetAll(string serial)

Everything recorded about one camera, in key order.

  • serial: The camera's serial number.

Returns: The entries, which is empty for a camera nobody has described. A copy: changing it records nothing.

  • Throws OptrisSdkException: The store could not be read.
public static string GetName(string serial)

What the user calls this camera.

  • serial: The camera's serial number.

Returns: The name, or an empty string for a camera nobody has named.

  • Throws OptrisSdkException: The store could not be read.
public static void Set(string serial, string key, string? value)

Write one metadata value, keeping the other entries.

  • serial: The camera's serial number.

  • key: The key, 1 to DeviceMetadata.MaxKeyLength UTF-8 bytes with no control characters.

  • value: The value, at most DeviceMetadata.MaxValueLength UTF-8 bytes. null or empty removes the key.

  • Throws OptrisSdkException: The key or value is unusable, or the store could not be written.

public static void SetName(string serial, string? name)

Name a camera, keeping anything else recorded about it.

  • serial: The camera's serial number.

  • name: The name, in any script, at most DeviceMetadata.MaxValueLength UTF-8 bytes. null or empty clears it.

  • Throws OptrisSdkException: The name is too long or contains a control character, or the store could not be written.

On disk by the time this returns, so the next enumeration, in this process or the next one, reports it.