"""
Inscoper API Example Script: Capture Image
==========================================
This script demonstrates how to load a configuration, initialize devices, and snap an image.

Configuration Prerequisites:
---------------------------
1. Environment Variable: Ensure 'InscoperConfigsPath' is defined in your environment
   and points to your Inscoper configurations folder.
2. Configuration Name: This script assumes a hardware configuration named "singleCamera".
   Change it below if your configuration is named differently.
3. Device Names: Change target camera names (e.g., "MyCamera") to match your setup.
"""
# --8<-- [start:main_logic]

import os
import inscoper_api

# Macro to all Inscoper configurations
CONFIG_PATH = os.environ['InscoperConfigsPath']

my_bridge = inscoper_api.Bridge()

# Load a specific configuration file
my_bridge.loadConfigFile(os.sep.join([CONFIG_PATH, "singleCamera"]))

# Initialize all the devices that were loaded from the configuration file
my_bridge.initDevices()

# Retrieve a list of the names of all successfully loaded and initialized devices
devices = my_bridge.getLoadedDevices()
print("Loaded devices: ", my_bridge.getLoadedDevices())

# Retrieve the specific camera object from the bridge using its configured name ("Camera")
my_camera = my_bridge.getCamera("MyCamera")

# Command the camera to take a single picture (snap an image)
# The argument '0' is the camera channel index (0 for mono)
image = my_camera.snapImage(0)

my_bridge.close()

# --8<-- [end:main_logic]