![]() |
IDS peak genericC++ v1.14.0
|
To use IDS peak genericAPI in dotnet, the IDSImaging.Peak.API package can be installed directly from NuGet via dotnet:
The package targets .NET Standard 2.0, making it compatible with:
The IDSImaging.Peak.API relies on native (unmanaged) DLLs that are distributed inside the referenced NuGet packages.
Because native binaries are involved, you must specify the target architecture via -p:Platform=<arch> when building. This ensures that your application is built for an architecture that can correctly load the required native libraries.
If no RuntimeIdentifier (-r) is specified, all available native runtimes from the packages will be copied to your build output. This would normally maximize compatibility but increase the application size. However, when the Platform parameter is specified, other architectures are not supported (except for x86 on x64).
You may optionally specify -r <rid> to reduce the size of the build output by including only the native libraries for a single runtime.
Required (correct architecture selection):
Optional (smaller output):
You can substitute another architecture/runtime pair if needed, e.g.:
Use Visual Studio or build from the command line:
msbuild exampleProjectFramework.csproj /t:Restore
msbuild exampleProjectFramework.csproj /p:Platform=x64
The .NET API works much like the C++ API. The same principles, class and method names apply. For example, listing all available devices:
It is possible to convert the content of a Buffer into an image by directly employing Buffer::BasePtr alongside a custom conversion routine to ensure compatibility with any image processing library. However, the recommended method is to use the BufferToImage function. This function is included in the supplementary assembly IDSImaging.Peak.API.IPLExtension.dll. BufferToImage is specifically engineered to simplify the conversion process of raw memory data stored within a Buffer into an peak::ipl::Image that can be used for further processing.
In order to make use of this functionality, an assembly reference must be added to the project and the IDSImaging.Peak.API.IPLExtension.dll needs to be available. See the Prerequisites section above for further instructions or use one of the provided samples that are shipped with the SDK as a starting template.
An example usage could look like as follows:
There are a few differences between the C++ API and the .NET 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.
By default, C# uses garbage collection to manage memory and resources. As a result, an object without any active references is not immediately closed or deleted. Instead, it will be removed by the garbage collector at an unspecified point in the future.
However, many peak objects hold resources that are not managed by the garbage collector, known as unmanaged resources. When working with unmanaged resources, it is essential to release them as soon as they are no longer needed. This can be achieved using one of the following methods:
Call Dispose() explicitly:
Or let a using statement handle calling Dispose() at the end of the scope:
It is important to release unmanaged resources in the reverse order in which they were acquired:
To be notified when certain events happen, the C++ API employs callbacks that you have to register and unregister. C# has the concept of events built-in and similarly to C++ you have to register a delegate as an event handler:
While C# supports optional parameters as well, the current C# API provides an overload for each default parameter instead:
C# also supports function templates (i.e. generic methods), which can be used as follows:
However, some IDE's and/or .NET implementations might not support such generic methods (e.g. NI Labview). Therefore all template specifications have been made available separately: