eGrabber sample programs 26.05.0.4

eGrabber .NET migration guide

This document explains how to migrate from the deprecated Coaxlink_NetApi assembly to the new EGrabber.NETFramework and EGrabber.NET assemblies.

Why new assemblies?

The Coaxlink_NetApi assembly suffers from several limitations and annoyances.

The new EGrabber.NETFramework assembly fixes all those issues. It’s based on the same design as the new Python bindings but tailored to the .NET Framework runtime.

The new EGrabber.NET assembly has the same benefits as EGrabber.NETFramework but targets the new open-source and cross-platform implementation of .NET previously called .NET Core.

Updating the assembly reference

Obviously, the project files referencing the old assembly need to be updated to reference the new one.

IntelliSense and inline documentation

Visual Studio is of great help while migrating from Coaxlink_NetApi to EGrabber.NETFramework or EGrabber.NET. You can explore the Euresys.EGrabber API with the IntelliSense auto-complete feature of the IDE. In addition, the API is fully documented and the documentation is directly available in the IDE2.

.NET Framework

The new EGrabber.NETFramework requires a more recent .NET Framework.

Coaxlink_NetApi EGrabber.NETFramework
requires .NET Framework 4.0 requires .NET Framework 4.6

.NET (Core)

The new EGrabber.NET does not require .NET Framework but requires another version called .NET.

Coaxlink_NetApi EGrabber.NET
requires .NET Framework 4.0 requires .NET 6.0

Namespaces

The eGrabber classes are now in the namespace Euresys.EGrabber.

Coaxlink_NetApi EGrabber.NETFramework and EGrabber.NET
using Euresys; using Euresys.EGrabber;

Basic migration rules

Here are the basic migration rules.
  • In the Coaxlink_NetApi API, method names are written in camelCase whereas in EGrabber.NETFramework and EGrabber.NET, method names are written in CamelCase to improve consistency with .NET naming conventions; For example, the Coaxlink_NetApi method reallocBuffers becomes ReallocBuffers in EGrabber.NETFramework;

  • Some methods are now properties (e.g. EGrabber.Width, EGrabber.Height), those changes are straightforward;

  • Other differences:

    Coaxlink_NetApi EGrabber.NETFramework and EGrabber.NET
    getInfoMODULE(cmd, out ...) Module.GetInfo<TYPE>(cmd)
    getIntegerMODULE(f) Module.Get<long>(f), Module.Get<int>(f)
    (cf. note below) Module.Get<bool>(f)
    getFloatMODULE(f) Module.Get<double>(f), Module.Get<float>(f)
    getStringMODULE(f) Module.Get<string>(f)
    getStringListMODULE(f) Module.Get<string[]>(f)
    setIntegerMODULE(f, v) Module.Set<long>(f, v), Module.Set<int>(f, v)
    (cf. note below) Module.Set<bool>(f, v)
    setFloatMODULE(f, v) Module.Set<double>(f, v), Module.Set<float>(f, v)
    setStringMODULE(f, v) Module.Set<string>(f, v)
    executeMODULE(f) Module.Execute(f)
    enableEVENT_DATAEvent(f) EnableEvent(EventType.EVENT_DATA)
    disableEVENT_DATAEvent(f) DisableEvent(EventType.EVENT_DATA)

    where

    • MODULE can be replaced by SystemModule, InterfaceModule, DeviceModule, StreamModule, or RemoteModule;
    • Module can be replaced by System, Interface, Device, Stream, or Remote;
    • EVENT_DATA can be replaced by NewBufferData, DataStreamData, IoToolboxData, CicData, CxpInterfaceData, DeviceErrorData, CxpDeviceData, or RemoteDeviceData.

Note: with the Coaxlink_NetApi assembly, setting/getting bool values had to be done using methods setIntegerMODULE/getIntegerMODULE (with values 1 and 0) or using methods setStringMODULE/getStringMODULE (with values "True" and "False"). Both of these options still work, but the new EGrabber.NETFramework and EGrabber.NET assemblies improve bool support by providing explicit methods Set<bool> and Get<bool>.

Callback models

The different callback models of Coaxlink_NetApi assembly are no longer present in the new EGrabber.NETFramework and EGrabber.NET assemblies, which only expose an interface based on the “callback on demand” variant of EGrabber. The Python bindings only expose this model and this proved to be sufficient to support all the use cases as this model can be used to build the other variants.

In the table below, we show how to migrate from an old callback model to the new API.

Coaxlink_NetApi EGrabber.NETFramework and EGrabber.NET
EGrabberCallbackOnDemand EGrabber
EGrabberCallbackSingleThread EGrabber + ProcessEventsAsync(EventType.All, ct)
  • ProcessEventsAsync can be used to process events repeatedly in a background task, EventType.All indicates all event types should be processed; this is the exact same behavior as the “singe thread” model.
  • ct is a CancellationToken; this is the .NET way to cancel an operation.
EGrabberCallbackMultiThread EGrabber + many ProcessEventsAsync(EventType.<EVENT>, ct)
  • where <EVENT> are different event types to process (e.g. NewBufferData, IoToolboxData, CicData…)
  • ProcessEventsAsync can be used to process events of the same type repeatedly in a background task. Calling ProcessEventsAsync for each specific event type creates as many background tasks as event types; this is the exact same behavior as the “multi thread” model.
  • ct is a CancellationToken, this is the .NET way to cancel an operation. Depending on the application needs, different CancellationTokens or the same CancellationToken can be used for the different event types. Please note that using the same CancellationToken allows to cancel all background tasks together with the same token source.

As you can see, the ProcessEventsAsync approach is superior to the previous callback models.

Discovery

The eGrabber discovery is now part of the new EGrabber.NETFramework and EGrabber.NET assemblies, so we can easily

For example, the following piece of code creates an EGrabber object for the first discovered camera (if available):

using Euresys.EGrabber;

var gentl = new EGenTL();
var discovery = new EGrabberDiscovery(gentl);
discovery.Discover();
if (discovery.CameraCount == 0)
{
    throw new Exception("No cameras discovered");
}
var grabber = new EGrabber(discovery.Cameras[0]);

Please refer to the programmer’s guide for further details about the eGrabber discovery.

Selecting another GenTL provider

When an EGenTL object is created, the default GenTL producer is used (typically coaxlink.cti). However, it’s possible to select a specific producer in the code as follows:

var gentlCoaxlink = new EGenTL(CtiPath.Coaxlink); // loads `coaxlink.cti` -- Coaxlink cards and CoaXPress cameras
var gentlGigelink = new EGenTL(CtiPath.Gigelink); // loads `gigelink.cti` -- Network cards and GigE Vision cameras
var gentlGrablink = new EGenTL(CtiPath.Grablink); // loads `grablink.cti` -- Grablink Duo cards and Camera Link cameras

Converting buffers

The FormatConverter class is no longer present in the new EGrabber.NETFramework and EGrabber.NET assemblies but the functionality is still available.

There are three options for converting image buffers from a pixel format to another:

eGrabber Exceptions

Like in the Coaxlink_NetApi assembly, all the eGrabber exception classes are available in the new EGrabber.NETFramework and EGrabber.NET assemblies but with the CamelCase naming convention. The migration should be straightforward.

Using Open eVision EGrabberBridge

The EGrabberBridge now supports Coaxlink_NetApi and EGrabber.NETFramework assemblies (this requires Open eVision 24.02 or later).

Using EGrabber.NETFramework (and Open eVision 24.02 or later)

Similarly, to convert a buffer object (of type Euresys.EGrabber.Buffer or Euresys.EGrabber.ScopedBuffer) to an Open eVision data container, we can also use the buffer information (Euresys.EGrabber.BufferInfo object) returned by buffer.GetInfo().

using (EGrabberImageBW8 image = new EGrabberImageBW8(buffer.GetInfo()))
{
    // Use the EGrabberImageBW8 as an Open eVision EImage Object
    // Here an inversion of the image is performed
    EImageBW8 invertedImage = new EImageBW8(image.Width, image.Height);
    EasyImage.Oper(EArithmeticLogicOperation.Invert, image, invertedImage);
}

However, it is also possible to pass EGrabber.NETFramework buffer objects directly to the EGrabberBridge so that internal format conversions can be automatically performed if necessary. The code will be shorter and smarter. This is the recommended way to convert a buffer object to an Open eVision data container.

For example, below we can pass a bufferMono8 (a buffer containing a Mono8 image) to create an EGrabberImageC24 object.

using (EGrabberImageC24 image = new EGrabberImageC24(bufferMono8))
{
    // The buffer containing Mono8 data is automatically converted
    // to BGR8 data before creating the EGrabberImageC24 object
    // ...
}

Please note that the EGrabberBridge API with the FormatConverter is not applicable to EGrabber.NETFramework (but does remain applicable to Coaxlink_NetApi).

Sample programs

Please have a look at the samples in the cs and vb directories which have been adapted to use the new interface.


  1. Orignially, the size of Euresys.SizeT was 32-bit or 64-bit depending on which version of the assembly was used (x86 or x86_64).↩︎

  2. Provided that the file EGrabber.NETFramework.xml (or EGrabber.NET.xml) is in the same directory as the assembly file EGrabber.NETFramework.dll (or EGrabber.NET.dll), the eGrabber installer takes care of this.↩︎


© EURESYS S.A. - Subject to change without notice.