5.19. Structured Data Read/Write
The interfaces described here are available in Python wrapper 2.1.4. Device and firmware support still determine which properties can be accessed.
5.19.1. Choose the simplest interface
Prefer an existing typed API for everyday device operations. It accepts or
returns a Python configuration object directly, so you do not need property
IDs, bytes, to_bytes() or from_bytes() for these tasks.
Task |
Recommended read API |
Recommended write API |
|---|---|---|
Temperature |
|
Read only |
Baseline |
|
Read only |
HDR |
|
|
Multi-device synchronization |
|
|
Depth work mode |
|
|
Device state |
|
Read only |
IP configuration |
|
|
The IP information methods do not return the complete configuration flags or static IP record. See the IP special case below if you need those fields. Signatures and members are in Core, Data Structures and Stream Profile.
5.19.2. Interface at a glance
Use the generic interface when a structured property has no suitable typed
wrapper, such as color AE ROI, or when an application needs uniform access by
property ID. Device.get_structured_data(property_id) returns owned Python
bytes; Device.set_structured_data(property_id, data) writes bytes.
Convert explicitly with Config.from_bytes(data) and config.to_bytes().
The property ID selects the operation; the bytes do not carry a Python type.
The following examples explain this generic path.
5.19.3. Basic usage
In these examples, device is an opened pyorbbecsdk.Device. For example:
import pyorbbecsdk as ob
context = ob.Context()
devices = context.query_devices()
if devices.get_count() == 0:
raise RuntimeError("No device connected")
device = devices.get_device_by_index(0)
Color AE ROI is an example of a property accessed through the generic interface. Read it and decode its coordinates with the matching structure:
prop = ob.OBPropertyID.OB_STRUCT_COLOR_AE_ROI
if not device.is_property_supported(prop, ob.OBPermissionType.PERMISSION_READ):
raise RuntimeError("Color AE ROI is not readable")
roi = ob.OBRegionOfInterest.from_bytes(device.get_structured_data(prop))
print(roi.x0_left, roi.y0_top, roi.x1_right, roi.y1_bottom)
For writing AE ROI, start the corresponding stream and refresh the ROI after receiving its first frame, as described below.
5.19.4. Payload rules
Binary input must be
bytes. Convert abytearrayormemoryviewwithbytes(buffer)first. Embedded zero bytes are preserved.set_structured_data()rejects empty data and lengths aboveuint32_t.from_bytes()requires the exact structure length.to_bytes()returns an independent copy. Uselen(config.to_bytes()), notsys.getsizeof(config).Payloads use the current SDK’s native byte order and packed structure layout. They are not a portable serialization format for files or cross-platform exchange.
Supply only the structure payload: no I2C header, opcode, request ID, command version or response error code. Complete protocol packets belong to Device Binary Data.
For ordinary properties, the setter forwards bytes without validating the property/type pairing or enforcing the table’s length. The caller must match the property and layout. Equal lengths do not make two types interchangeable.
5.19.5. Check support and permission
prop = ob.OBPropertyID.OB_STRUCT_COLOR_AE_ROI
readable = device.is_property_supported(prop, ob.OBPermissionType.PERMISSION_READ)
writable = device.is_property_supported(prop, ob.OBPermissionType.PERMISSION_WRITE)
print("readable:", readable, "writable:", writable)
An enum member, a Python structure, byte conversion support and device support are separate conditions. A successful permission check does not rule out a later SDK error caused by device state, parameter limits or firmware behavior.
Invalid binary input raises TypeError; invalid lengths, unknown read layouts
and binding-level restrictions raise ValueError. Device access failures are
reported as OBError.
5.19.6. Read-only data
For temperature, the typed API already returns the structure directly:
temperature = device.get_temperature()
print(temperature.cpu_temperature, temperature.ir_left_temperature)
Temperatures may change between reads or contain NaN. Compare meaningful
fields according to the property rather than requiring identical raw bytes.
A generic getter also being available does not make the value writable.
5.19.7. Read, modify, verify and restore
AE ROI uses OBRegionOfInterest with boundary coordinates (x0_left,
y0_top, x1_right, y1_bottom). RGB crop instead uses OBRect
(x, y, width, height); the layouts are not interchangeable.
Some devices and firmware require streaming to configure AE ROI. Start the corresponding stream, wait for its first frame, then read the ROI used as the original configuration. Use coordinates within that frame’s dimensions and refresh the ROI after changing resolution. Auto exposure must be enabled for the ROI to affect exposure adjustment.
Before running this example, start a color stream using the
Blocking Polling Mode
workflow. Use that same pipeline and its device = pipeline.get_device()
here, with the import pyorbbecsdk as ob alias from Basic usage. Keep the
pipeline running until restoration finishes, then stop it when no longer needed.
prop = ob.OBPropertyID.OB_STRUCT_COLOR_AE_ROI
if not device.is_property_supported(prop, ob.OBPermissionType.PERMISSION_READ_WRITE):
raise RuntimeError("Color AE ROI is not readable/writable")
for _ in range(5):
frames = pipeline.wait_for_frames(1000)
color = frames.get_color_frame() if frames is not None else None
if color is not None:
break
else:
raise RuntimeError("No color frame received")
original = device.get_structured_data(prop) # Read after the first color frame.
config = ob.OBRegionOfInterest.from_bytes(original)
if config.x1_right - config.x0_left <= 16 or config.y1_bottom - config.y0_top <= 16:
raise RuntimeError("ROI is too small for this example")
config.x0_left += 8
config.y0_top += 8
config.x1_right -= 8
config.y1_bottom -= 8
if not (0 <= config.x0_left < config.x1_right < color.get_width()
and 0 <= config.y0_top < config.y1_bottom < color.get_height()):
raise RuntimeError("Target ROI is outside the active color frame")
try:
device.set_structured_data(prop, config.to_bytes())
actual = ob.OBRegionOfInterest.from_bytes(device.get_structured_data(prop))
fields = ("x0_left", "y0_top", "x1_right", "y1_bottom")
expected = tuple(getattr(config, field) for field in fields)
observed = tuple(getattr(actual, field) for field in fields)
if observed != expected:
raise RuntimeError("ROI readback differs; check firmware limits/update timing")
finally:
device.set_structured_data(prop, original)
if device.get_structured_data(prop) != original:
raise RuntimeError("Failed to restore original ROI")
For depth AE ROI, use OB_STRUCT_DEPTH_AE_ROI, wait for a depth frame with
frames.get_depth_frame(), and use the depth frame’s dimensions.
Some properties apply asynchronously or quantize values. Adapt the wait and comparison to the device; treat restoration failures as failures. Readback confirms the configuration round trip, not the image effect. Do not reuse this automatic restore pattern for IP settings, which can disconnect the device.
5.19.8. Supported properties
Sizes below describe the current binding’s SDK layout. “Check device” means query read and write permissions separately; the table does not promise that every camera supports either operation. “Fixed” means the generic getter knows the payload size; “Dedicated” means it calls a specialized SDK operation.
Property ( |
Python type |
Bytes |
Access |
Generic read path |
|---|---|---|---|---|
|
|
8 |
Check device |
Fixed |
|
|
44 |
Check device |
Fixed |
|
|
8 |
Check device |
Fixed |
|
|
16 |
Check device |
Fixed |
|
|
16 |
Check device; may be internal |
Fixed |
|
|
25 |
Check device |
Dedicated |
|
|
16 |
Check device |
Fixed |
|
|
14 |
Check device |
Fixed |
|
|
52 |
Check device |
Dedicated |
|
Variable-length |
Variable length |
No generic getter |
Unsupported layout |
|
|
14 |
Read only in SDK |
Fixed |
|
|
18 |
Check device |
Fixed |
|
|
8 |
Check device |
Fixed |
|
|
8 |
Check device |
Fixed |
|
|
16 |
Check device |
Fixed |
|
|
4 |
Check device |
Fixed |
|
|
12 |
Check device |
Fixed |
|
Not adapted |
— |
No generic getter |
Unsupported layout |
|
|
14 |
Check device |
Fixed |
|
|
6 |
Check device |
Fixed |
The following additional IDs expose SDK-internal layouts without changing SDK access permissions. They may be unavailable to ordinary applications.
Property ( |
ID |
Python type |
Bytes |
Access / read path |
|---|---|---|---|---|
|
1000 |
|
164 |
Check device / fixed |
|
1031 |
|
68 |
Check device / fixed |
|
1032 |
|
68 |
Check device / fixed |
|
1033 |
|
68 |
Check device / fixed |
|
1034 |
|
68 |
Check device / fixed |
|
5524 |
|
8 |
Read only / dedicated |
5.19.9. Existing APIs and special cases
Use the wrapped interfaces below for their respective tasks. This section lists the recommended methods and the remaining constraints; no manual property serialization is needed for ordinary use of those methods.
5.19.9.1. Multi-device synchronization
Use device.get_multi_device_sync_config() to obtain an
OBMultiDeviceSyncConfig, edit the required fields, then pass the object to
device.set_multi_device_sync_config(config). The SDK handles protocol
selection. See Multi-Camera Synchronization
for the hardware setup and configuration workflow.
If an application requires generic access, the corresponding property uses the
public 25-byte OBMultiDeviceSyncConfig layout. The legacy OBDeviceSyncConfig
and firmware protocol packets are different representations. The serialized
trigger_out_enable byte must be 0 or 1.
5.19.9.2. Depth work mode
Use device.get_depth_work_mode() to read the current mode and
device.get_depth_work_mode_list() to obtain valid modes. Stop all streams
before switching, select a complete item from the list, and pass it to
device.set_depth_work_mode(mode). Check the returned status against
ob.OBStatus.STATUS_OK. See
Depth Working Mode for the full example.
On SDK versions that do not populate get_depth_work_mode().tag, obtain the
mode’s tag from the corresponding supported-list item. Handle SDK errors from
the dedicated APIs; raw-property permissions alone do not establish support
for this workflow.
The public OBDepthWorkMode contains tag; the internal
OBDepthWorkModeInternal contains option_code. Both are 52 bytes but have
different meanings. Preserve the device-provided list item when switching
modes rather than constructing an internal payload.
5.19.9.3. Device error state
Use device.get_device_state() to obtain the integer state mask directly.
Interpret its bits with OBDeviceErrorCode; no byte conversion is required.
There is no setter for this read-only state, and the SDK may return cached
information.
For applications that require the structured property interface,
OB_STRUCT_DEVICE_ERROR_STATE returns OBDeviceErrorState.error_code through
the dedicated SDK state API. Writes are rejected. Error bits occupy the lower
32 bits; warning bits occupy the upper 32 bits. Bit 63,
DEVICE_WARNING_LOG_OVERFLOW, is described by the SDK as a state-info cache
flag. See the full enum table in
Data Structures.
5.19.9.5. IP configuration and other field conventions
Use device.set_ip_config(config) to write an OBNetIpConfigV2 or
OBDeviceIpAddrConfig object directly. When passed a V2 object, the wrapper
checks V2 read/write support and falls back to converted V1 configuration when
V2 is unavailable. A V1 object writes V1 directly. See
IP Configuration for the usage workflow.
To inspect the current address, obtain info = device.get_device_info() and
use info.get_device_ip_address(), info.get_device_subnet_mask() and
info.get_device_gateway(). These methods report address information; reading
full V1/V2 configuration fields or the static IP record still requires the
corresponding structured property when supported.
For those advanced reads, V1 uses dhcp; V2 uses flags (DHCP mask 0x01,
Persistent IP mask 0x02); IP address fields are dotted strings.
OB_STRUCT_DEVICE_STATIC_IP_CONFIG_RECORD uses OBDeviceIpAddrConfig and is
read only. A generic IP write targets exactly the specified property and does
not perform the typed setter’s V2-to-V1 fallback. IP changes can interrupt the
connection, so do not apply the ROI example’s automatic restore pattern.
For other structures, preserve reserved fields. HDR occupies 18 bytes in the
packed layout and already has get_hdr_config() / set_hdr_config(config).
AWB gains are ordered r_gain, b_gain, g_gain; handle automatic white
balance as required by the device before writing them. OBDeviceTime contains
time and rtt; older clock units can depend on device frequency.
5.19.10. Type aliases
Type aliases are OBSerialNumber = OBDeviceSerialNumber,
OBNetIpConfig = OBDeviceIpAddrConfig and
OBDepthWorkMode_Internal = OBDepthWorkModeInternal.
5.19.11. Limitations
Only flat, fixed-layout structures have byte conversion support. This is not general serialization of SDK objects, pointers or variable arrays. The generic setter accepting bytes does not imply that the getter knows that property’s layout, or that the device allows a write.
The SDK’s ordinary structured read copies data before reporting the returned length and does not enforce the supplied capacity. Reads therefore depend on the device and SDK respecting the registered layout. A length check after the call detects an ABI mismatch but cannot prevent an SDK buffer overrun. Do not try to discover unknown lengths with a null buffer or repeated larger buffers. Supporting arbitrary payloads safely requires a capacity-aware SDK API.