![]() |
IDS peak genericC++ v1.7.3
|
To use IDS peak genericAPI in Python, there is a separate Python wheel for each supported Python version and CPU architecture. A Python wheel is a package file (with .whl file ending) which can be installed via pip, Python's package manager. Just call pip install <Path-To-Python-Wheel> to install your chosen Python wheel.
To finally use IDS peak genericAPI in your Python script, just add import ids_peak.ids_peak or import ids_peak.ids_peak as some_alias at the top of your Python script. The latter should be preferred.
The Python API works much like the C++ API. Nearly the same principles, class and method names apply. For example, listing all available devices:
There are only a few differences between the C++ API and the Python API. The most important ones are listed here:
The C++ API utilizes smart pointers for deterministic memory management, where the last smart pointer that holds a reference to the object destroys it when the smart pointer goes out of scope.
To close a module (e.g. the Device), you have to release all its shared_ptr instances (out-of-scope, call reset(), set to nullptr), then the module closes immediately.
Since Python uses garbage collection, when an object is released in Python, it won't be closed and deleted immediately. Instead, it will be deleted at some point in the future, when the garbage collection deems it necessary. Often, that's no problem. But if it is, you could do the following:
Since Python had no native concept of enumeration types, the values are mapped to individual constants. A rule of thumb is that each scope resolution operator :: in C++ is replaced with an underscore in Python:
To be notified when certain events happen, the C++ API employs callbacks that you have to register and unregister. This concept exists almost equivalently in the Python API. Likewise it's necessary to store the callback handle for subsequent unregistering of the callback.