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.
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 device manager object vardeviceManager=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();
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++
autodevices=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++
autodeviceCount=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".
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.
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_tipAddress=0xC0A80A01; std::shared_ptr<peak::core::Device>device=nullptr; auto&deviceManager=peak::DeviceManager::Instance(); deviceManager.Update(); for(constauto&descriptor:deviceManager.Devices()) { autonodemapParentInterface=descriptor->ParentInterface()->NodeMaps().at(0); // Get node to select the device autonodeDeviceSelector=nodemapParentInterface->FindNode<peak::core::nodes::IntegerNode>("DeviceSelector"); // Get node with the device IP address autonodeDeviceIp=nodemapParentInterface->FindNode<peak::core::nodes::IntegerNode>("GevDeviceIPAddress"); // Iterate through all selectors and find specified IP address for(inti=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: Opening a camera with a specific name
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.
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.
// Include IDS peak #include <ids_peak_comfort_c.h> peak_boolcheckForSuccess(peak_statuscheckStatus); intmain() { // Initialize IDS peak library peak_statusstatus=peak_Library_Init(); if(!checkForSuccess(status)) { // Return, if the initialization of the library failed returnstatus; } // Create camera handle peak_camera_handlehCam=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); returnstatus; } // 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); returnstatus; } // ... Do something with the camera here statuspeak_Camera_Close(hCam); if(!checkForSuccess(status)) { printf("Warning: Closing camera failed! Proceeding...\n"); } statuspeak_Library_Exit(hCam); if(!checkForSuccess(status)) { printf("Warning: Exiting library failed! Closing program...\n"); } } peak_boolcheckForSuccess(peak_statuscheckStatus) { if(PEAK_ERROR(checkStatus)) { peak_statuslastErrorCode=PEAK_STATUS_SUCCESS; size_tlastErrorMessageSize=0; // Get size of error message peak_statusstatus=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); returnPEAK_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); returnPEAK_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); returnPEAK_FALSE; } printf("Last-Error: %s | Code: %#06x\n",lastErrorMessage,lastErrorCode); free(lastErrorMessage); returnPEAK_FALSE; } returnPEAK_TRUE; }
// Include IDS peak #include <peak/peak.hpp> intmain() { // 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 autodevice=deviceManager.Devices().at(0)->OpenDevice(peak::core::DeviceAccessType::Control); // ... Do something with the device here } catch(conststd::exception&e) { std::cout<<"EXCEPTION: "<<e.what()<<std::endl; peak::Library::Close(); return-2; } // Close library peak::Library::Close(); return0; }
classProgram { staticvoidMain(string[]args) { // Initialize library peak.Library.Initialize(); // Create a DeviceManager object vardeviceManager=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 vardevice=deviceManager.Devices()[0].OpenDevice(peak.core.DeviceAccessType.Control); // ... Do something with the device here } catch(Exceptione) { 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()