Manage Devices¶
Once a configuration is loaded, the Inscoper API provides fine-grained control over the lifecycle of individual devices. This example demonstrates how to query the state of devices at each stage — loaded, initialized, and at the sub-device level — and how to selectively close and re-initialize a single device without restarting the entire system.
Overview¶
Device management in the Inscoper API distinguishes between two states:
| State | Description |
|---|---|
| Loaded | The device has been parsed from the configuration file and is known to the bridge, but communication with the hardware has not yet been established |
| Initialized | The device has been activated and the bridge has established communication with the underlying hardware |
The bridge exposes dedicated methods to query and transition between these states:
| Method | Description |
|---|---|
getLoadedDevices() |
Returns the list of device names declared in the loaded configuration |
getInitializedDevices() |
Returns the list of device names for which initialization has succeeded |
getInitializedSubDeviceIds() |
Returns the list of all initialized sub-device identifiers (device + sub-device pairs) |
initDevices() |
Initializes all loaded devices |
initDevice(name) |
Initializes a single device by name |
closeDevice(name) |
Closes a single device, releasing its hardware resources |
getDeviceDescriptionList() |
Returns the list of device descriptions available in the system, including brand, model, and description metadata |
Note
This example uses a configuration named singleCamera. Replace this value with the name defined in your own hardware configuration file.
Device management¶
import inscoper_api
import os
CONFIG_PATH = os.environ['InscoperConfigsPath']
my_bridge = inscoper_api.Bridge()
my_bridge.loadConfigFile(os.sep.join([CONFIG_PATH, "singleCamera"]))
devices = my_bridge.getLoadedDevices()
print("Loaded devices: ", my_bridge.getLoadedDevices())
print(my_bridge.getInitializedDevices())
# Initialize all the devices that were loaded from the configuration file
my_bridge.initDevices()
print(my_bridge.getInitializedDevices())
print([sd.getDeviceId()+"-"+sd.getSubDeviceId() for sd in my_bridge.getInitializedSubDeviceIds()])
# Close a device and check it is not anymore in the initialized list
my_bridge.closeDevice("Camera")
print(my_bridge.getInitializedDevices())
# Re-init a device
my_bridge.initDevice("Camera")
print(my_bridge.getInitializedDevices())
# Get a description of all devices
descriptions = my_bridge.getDeviceDescriptionList()
print([d.getDescription() for d in descriptions])
print([d.getBrand() for d in descriptions])
print([d.getModel() for d in descriptions])