IDS Peak comfortSDK, genericSDK, IPL, and AFL developer manuals are external documents. Please contact us if you need them.
Using IDS peak API, you can open connected cameras and make them available for parameterization and image acquisition. A camera is represented as a so-called "Device". Devices are connected to the System via Interfaces. In this context, Interfaces represent the physical connections of the camera, e.g. the USB or GigE connection. The System represents the software driver. Several Interfaces can be addressed by one System, also several Devices can be connected to one Interface.
Fig. 277: System, Interface, and Device
If you want to open a camera, you must first determine which cameras (Devices) are connected and how the cameras are assigned in this structure. This task is performed by the "DeviceManager" class. The DeviceManager detects all available Systems, Interfaces and Devices. The global DeviceManager is accessible via the Instance() function.
// Create a camera manager object
auto& deviceManager = peak::DeviceManager::Instance();
|
// Create a device manager object
var deviceManager = peak.DeviceManager.Instance();
|
Further information on using the DeviceManagers under C# can be found in the IDS peak genericSDK developer manual.
Update
The DeviceManager searches the System for connected cameras using the Update() function. The DeviceManager scans for available modules and stores them in the lists Systems(), Interfaces() and Devices().
// Update the DeviceManager
deviceManager.Update();
|
// Update the DeviceManager
deviceManager.Update();
|
|
A simple example how to use the DeviceManager can be found in the sample "open_camera".
|
Devices
You can query the found cameras (Devices) in the vector Devices(). Here, the cameras are represented in the form of descriptors that allow certain information to be accessed even if the cameras are not opened yet.
genericC++
|
auto devices = deviceManager.Devices();
|
The length of the vector corresponds to the number of cameras found. A camera can be listed multiple times, e.g. if it can be opened via several transport layers.
genericC++
|
auto deviceCount = deviceManager.Devices().size();
|
Opening a camera
In the simplest case, the first camera found is opened. Do this by executing the OpenDevice() function of the Device descriptor. Here, the access type is passed, e.g. "Control", "Exclusive" or "ReadOnly".
// Open the first camera
auto device = deviceManager.Devices().at(0)->OpenDevice(peak::core::DeviceAccessType::Control);
|
// Open the selected device
var device = deviceManager.Devices()[0].OpenDevice(peak.core.DeviceAccessType.Control);
|
The selected camera is now open and can be used.
Alternatives and variations: Opening a camera with a specific serial number
First, iterate over the found cameras in the list. Then, compare the given serial number with the serial number of the camera in the list. If the serial number is found, the camera is opened and a Device object is created.
genericC++
|
std::string serNo = "123456789";
std::shared_ptr<peak::core::Device> device = nullptr;
auto& deviceManager = peak::DeviceManager::Instance();
deviceManager.Update();
for (const auto& descriptor: deviceManager.Devices())
{
if (descriptor->SerialNumber() == serNo)
{
device = descriptor->OpenDevice(peak::core::DeviceAccessType::Control);
break;
}
}
if (device)
{
// ...
}
|
Alternatives and variations: Opening a camera with a specific IP address
The IP address of the camera must be specified as an integer value. Usually, there are conversion functions in the different programming languages to convert an IP address from string representation (e.g. 192.168.10.1) into integer (0xC0A80A01 == 3232238081).
1.First determine the appropriate network adapter via the Device descriptor (descriptor->ParentInterface()).
2.Get the NodeMap of the network adapter.
3.The network adapter has a selector that can be used to select all connected cameras.
4.Iterate over all entries of the selector.
5.Check the IP address of the selector entry until you find the desired camera.
6.Open the camera.
7.Save the Device object.
genericC++
|
// 192.168.10.1
int64_t ipAddress = 0xC0A80A01;
std::shared_ptr<peak::core::Device> device = nullptr;
auto& deviceManager = peak::DeviceManager::Instance();
deviceManager.Update();
for (const auto& descriptor: deviceManager.Devices())
{
auto nodemapParentInterface = descriptor->ParentInterface()->NodeMaps().at(0);
// Get node to select the device
auto nodeDeviceSelector = nodemapParentInterface->FindNode<peak::core::nodes::IntegerNode>("DeviceSelector");
// Get node with the device IP address
auto nodeDeviceIp = nodemapParentInterface->FindNode<peak::core::nodes::IntegerNode>("GevDeviceIPAddress");
// Iterate through all selectors and find specified IP address
for (int i = 0; i <= nodeDeviceSelector->Maximum(); i++)
{
nodeDeviceSelector->SetValue(i);
// This is the correct camera
if (nodeDeviceIp->Value() == ipAddress)
{
device = descriptor->OpenDevice(peak::core::DeviceAccessType::Control);
break;
}
}
}
if (device)
{
// ...
}
|
Alternatives and variations:
You can use the UserDefinedName (DeviceUserID) to store a unique identifier for your camera in the camera memory, which you can use later to identify the camera. See Setting the camera name.
genericC++
|
std::string name = "camera1";
std::shared_ptr<peak::core::Device> device = nullptr;
auto& deviceManager = peak::DeviceManager::Instance();
deviceManager.Update();
for (const auto& descriptor: deviceManager.Devices())
{
if (descriptor->UserDefinedName() == name)
{
device = descriptor->OpenDevice(peak::core::DeviceAccessType::Control);
break;
}
}
if (device)
{
// ...
}
|
Alternatives and variations: Limiting the camera list to a specific transport layer
Normally, IDS peak searches for compatible transport layers in special folders in the installation path. The transport layers are registered in the environment variables GENICAM_GENTL32_PATH and GENICAM_GENTL64_PATH when IDS peak is installed. These default paths can be ignored. Instead, you can specify a concrete path to a transport layer. Afterwards, the DeviceManager will only list cameras that are supported and can be opened via this transport layer. To do this, you must call the DeviceManager's update command with a specific parameter.
genericC++
|
auto& deviceManager = peak::DeviceManager::Instance();
std::string pathToTransportLayer = "c:/Program Files/IDS/ids_peak/ids_u3vgentl/64/ids_u3vgentlk.cti";
deviceManager.AddProducerLibrary(pathToTransportLayer);
deviceManager.Update(peak::DeviceManager::UpdatePolicy::DontScanEnvironmentForProducerLibraries);
|
Complete code example
// Include IDS peak
#include <ids_peak_comfort_c.h>
peak_bool checkForSuccess(peak_status checkStatus);
int main()
{
// Initialize IDS peak library
peak_status status = peak_Library_Init();
if (!checkForSuccess(status))
{
// Return, if the initialization of the library failed
return status;
}
// Create camera handle
peak_camera_handle hCam = PEAK_INVALID_HANDLE;
// Update camera list
status = peak_CameraList_Update(NULL);
if (!checkForSuccess(status))
{
// Return, if the update of the camera list failed
// Exit library first
status = peak_Library_Exit();
checkForSuccess(status);
return status;
}
// Open first available camera
status = peak_Camera_OpenFirstAvailable(&hCam);
if (!checkForSuccess(status))
{
// Exit program if no camera was opened
printf("Could not open camera. Exiting program.\n");
status = peak_Library_Exit();
checkForSuccess(status);
return status;
}
// ... Do something with the camera here
status peak_Camera_Close(hCam);
if (!checkForSuccess(status))
{
printf("Warning: Closing camera failed! Proceeding...\n");
}
status peak_Library_Exit(hCam);
if (!checkForSuccess(status))
{
printf("Warning: Exiting library failed! Closing program...\n");
}
}
peak_bool checkForSuccess(peak_status checkStatus)
{
if (PEAK_ERROR(checkStatus))
{
peak_status lastErrorCode = PEAK_STATUS_SUCCESS;
size_t lastErrorMessageSize = 0;
// Get size of error message
peak_status status = peak_Library_GetLastError(&lastErrorCode, NULL, &lastErrorMessageSize);
if (PEAK_ERROR(status))
{
// Something went wrong getting the last error!
printf("Last-Error: Getting last error code failed! Status: %#06x\n", status);
return PEAK_FALSE;
}
if (checkStatus != lastErrorCode)
{
// Another error occured in the meantime. Proceed with the last error.
printf("Last-Error: Another error occured in the meantime!\n");
}
// Allocate and zero-initialize the char array for the error message
char* lastErrorMessage = (char*)calloc((lastErrorMessageSize) / sizeof(char), sizeof(char));
if (lastErrorMessage == NULL)
{
// Cannot allocate lastErrorMessage. Most likely not enough Memory.
printf("Last-Error: Failed to allocate memory for the error message!\n");
free(lastErrorMessage);
return PEAK_FALSE;
}
// Get the error message
status = peak_Library_GetLastError(&lastErrorCode, lastErrorMessage, &lastErrorMessageSize);
if (PEAK_ERROR(status))
{
// Unable to get error message. This shouldn't ever happen.
printf("Last-Error: Getting last error message failed! Status: %#06x; Last error code: %#06x\n", status,
lastErrorCode);
free(lastErrorMessage);
return PEAK_FALSE;
}
printf("Last-Error: %s | Code: %#06x\n", lastErrorMessage, lastErrorCode);
free(lastErrorMessage);
return PEAK_FALSE;
}
return PEAK_TRUE;
}
|
// Include IDS peak
#include <peak/peak.hpp>
int main()
{
// Initialize library
peak::Library::Initialize();
// Create a DeviceManager object
auto& deviceManager = peak::DeviceManager::Instance();
try
{
// Update the DeviceManager
deviceManager.Update();
// Exit program if no device was found
if (deviceManager.Devices().empty())
{
std::cout << "No device found. Exiting program." << std::endl << std::endl;
peak::Library::Close();
return -1;
}
// Open the first device
auto device = deviceManager.Devices().at(0)->OpenDevice(peak::core::DeviceAccessType::Control);
// ... Do something with the device here
}
catch (const std::exception& e)
{
std::cout << "EXCEPTION: " << e.what() << std::endl;
peak::Library::Close();
return -2;
}
// Close library
peak::Library::Close();
return 0;
}
|
class Program
{
static void Main(string[] args)
{
// Initialize library
peak.Library.Initialize();
// Create a DeviceManager object
var deviceManager = peak.DeviceManager.Instance();
try
{
// Update the DeviceManager
deviceManager.Update();
// Exit program if no device was found
if (!deviceManager.Devices().Any())
{
Console.WriteLine("No device found. Exiting program.");
peak.Library.Close();
Environment.ExitCode = -1;
return;
}
// Open the first device
var device = deviceManager.Devices()[0].OpenDevice(peak.core.DeviceAccessType.Control);
// ... Do something with the device here
}
catch (Exception e)
{
Console.WriteLine("EXCEPTION: " + e.Message);
peak.Library.Close();
Environment.ExitCode = -2;
return;
}
// Close library
peak.Library.Close();
Environment.ExitCode = 0;
return;
}
}
|
from ids_peak import ids_peak
def main():
# Initialize library
ids_peak.Library.Initialize()
# Create a DeviceManager object
device_manager = ids_peak.DeviceManager.Instance()
try:
# Update the DeviceManager
device_manager.Update()
# Exit program if no device was found
if device_manager.Devices().empty():
print("No device found. Exiting Program.")
return -1
# Open the first device
device = device_manager.Devices()[0].OpenDevice(ids_peak.DeviceAccessType_Control)
# ... Do something with the device here
except Exception as e:
print("EXCEPTION: " + str(e))
return -2
finally:
ids_peak.Library.Close()
if __name__ == '__main__':
main()
|