.NET assembly
eGrabber can be used in .NET languages (C#, VB.NET, etc.) via two .NET assemblies named EGrabber.NETFramework.dll and EGrabber.NET.dll.
● | EGrabber.NETFramework.dll assembly only works on Windows and requires .NETFramework. |
● | EGrabber.NET.dll assembly is cross-platform and works with .NET previously called .NET Core. |
8.1 A first example
This example creates a grabber and displays basic information about the interface, device, and remote device modules it contains. This is the C# version of the first C++ eGrabber example:
using System;
using Euresys.EGrabber;
namespace FirstExample {
class ExampleShowInfo {
const int CARD_IX = 0;
const int DEVICE_IX = 0;
static void ShowInfo() {
using (var gentl = new EGenTL()) { // 1
using (var grabber = new EGrabber(gentl, CARD_IX, DEVICE_IX)) { // 2
string card = grabber.Interface.Get<string>("InterfaceID"); // 3
string dev = grabber.Device.Get<string>("DeviceID"); // 4
ulong width = grabber.Remote.Get<ulong>("Width"); // 5
ulong height = grabber.Remote.Get<ulong>("Height"); // 5
System.Console.WriteLine("Interface: {0}", card);
System.Console.WriteLine("Device: {0}", dev);
System.Console.WriteLine("Resolution: {0}x{1}", width, height);
}
}
}
static void Main() {
try { // 6
ShowInfo();
} catch (System.Exception e) { // 6
System.Console.WriteLine("error: {0}", e.Message);
}
}
}
}
1. | Create an EGenTL object. This will locate, open, and initialize the GenTL producer (e.g., coaxlink.cti). |
2. | Create an EGrabber object. The constructor needs the gentl object we’ve just created. It also takes as optional arguments the indices of the interface and device to use. |
3. | Use GenApi to find out the ID of the Coaxlink card. We want an answer from the interface module, so the Get is done on grabber.Interface. Notice the <string> to indicate that we want to query the GenICam IString interface of the feature and we want to get back a string value. |
4. | Similarly, find out the ID of the device. This time, we use grabber.Device to target the device module. |
5. | Finally, read the camera resolution. This time, we use grabber.Remote since the values must be retrieved from the camera. Notice the <ulong> to indicate that we want to query the GenICam IInteger interface of the feature and we want to get back a ulong value. |
6. | eGrabber uses exceptions to report errors, so we wrap our code inside a try ... catch block. |
Example of program output:
Interface: PC1633 - Coaxlink Quad G3 (2-camera) - KQG00014
Device: Device0
Resolution: 4096x4096
8.2 Differences between C++ and .NET eGrabber
eGrabber classes
C++ | .NET |
---|---|
EGrabber<>
|
EGrabber
|
EGrabber<CallbackOnDemand>
|
EGrabber
|
EGrabber<CallbackSingleThread>
|
- |
EGrabber<CallbackMultiThread>
|
- |
Buffer
|
Buffer
|
ScopedBuffer
|
ScopedBuffer used in a using-statement |
EGrabber
methods
● | In the C++ API, method names are written in camelCase. In C#, method names are written in CamelCase. For example, the C++ reallocBuffers becomes ReallocBuffers in C#. |
● | Other differences: |
C++ | .NET |
---|---|
getInfo< MODULE , TYPE >(cmd)
|
Module .GetInfo< TYPE >(cmd)
|
getInteger< MODULE >(f)
|
Module .Get<long>(f) , Module .Get<int>(f) , … |
- | Module .Get<bool>(f)
|
getFloat< MODULE >(f)
|
Module .Get<double>(f) , Module .Get<float>(f) |
getString< MODULE >(f)
|
Module .Get<string>(f)
|
getStringList< MODULE >(f)
|
Module .Get<string[]>(f)
|
setInteger< MODULE >(f, v)
|
Module .Set<long>(f, v) , Module .Set<int>(f, v) , … |
- | Module .Set<bool>(f, v)
|
setFloat< MODULE >(f, v)
|
Module .Set<double>(f, v) , Module .Set<float>(f, v) |
setString< MODULE >(f, v)
|
Module .Set<string>(f, v)
|
execute< MODULE >(f)
|
Module .Execute(f)
|
enableEvent< EVENT_DATA >()
|
EnableEvent(EventType. EVENT_DATA )
|
disableEvent< EVENT_DATA >()
|
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. |
Callbacks
In .NET, callbacks are defined as methods with two arguments, the grabber and the actual event data:
grabber.RegisterEventCallback<NewBufferData>(OnNewBufferData);
grabber.RegisterEventCallback<DataStreamData>(OnDataStreamData);
grabber.RegisterEventCallback<IoToolboxData>(OnIoToolboxData);
grabber.RegisterEventCallback<CicData>(OnCicData);
grabber.RegisterEventCallback<CxpInterfaceData>(OnCxpInterfaceData);
grabber.RegisterEventCallback<DeviceErrorData>(OnDeviceErrorData);
grabber.RegisterEventCallback<CxpDeviceData>(OnCxpDeviceData);
grabber.RegisterEventCallback<RemoteDeviceData>(OnRemoteDeviceData);
A complete example is given in the next section.
Processing events using callbacks
This program displays basic information about CIC events generated by a grabber:
using System;
using Euresys.EGrabber;
namespace Callbacks {
class CallbackExample {
static void ShowEvents(EGrabber grabber) {
grabber.RunScript("config.js"); // 1
grabber.RegisterEventCallback<CicData>(OnCicData); // 2
grabber.EnableEvent(EventType.CicData); // 5
grabber.ReallocBuffers(3); // 6
grabber.Start(); // 6
while (true) { // 6
grabber.ProcessEvent(EventType.Any); // 6
}
}
static void OnCicData(EGrabber grabber, CicData data) { // 3
System.Console.WriteLine("Timestamp: {0} us, {1}", // 4
data.Timestamp, data.NumId);
}
static void Main() {
try {
using (var gentl = new EGenTL()) {
using (var grabber = new EGrabber(gentl)) {
ShowEvents(grabber);
}
}
} catch (System.Exception e) {
System.Console.WriteLine("error: {0}", e.Message);
}
}
}
}
1. | Run a config.js script which should: |
□ | properly configure the camera and frame grabber; |
□ | enable notifications for CIC events. |
2. | Register the callback function for handling the CIC events. |
3. | The CIC event callback has two arguments: the grabber that got the event, and the actual event data. |
4. | In the body of the callback function, simply display basic information about the event. |
5. | Enable CicData events on the grabber. |
6. | Start the grabber and enter an infinite loop to process any incoming event. CIC events will be notified in the same thread. |
Example of program output:
timestamp: 2790824897 us, EVENT_DATA_NUMID_CIC_CAMERA_TRIGGER_RISING_EDGE
timestamp: 2790824897 us, EVENT_DATA_NUMID_CIC_STROBE_RISING_EDGE
timestamp: 2790824902 us, EVENT_DATA_NUMID_CIC_CXP_TRIGGER_ACK
timestamp: 2790825897 us, EVENT_DATA_NUMID_CIC_STROBE_FALLING_EDGE
timestamp: 2790830397 us, EVENT_DATA_NUMID_CIC_CAMERA_TRIGGER_FALLING_EDGE
timestamp: 2790830401 us, EVENT_DATA_NUMID_CIC_CXP_TRIGGER_ACK
timestamp: 2790842190 us, EVENT_DATA_NUMID_CIC_ALLOW_NEXT_CYCLE
timestamp: 2790842190 us, EVENT_DATA_NUMID_CIC_CAMERA_TRIGGER_RISING_EDGE
timestamp: 2790842191 us, EVENT_DATA_NUMID_CIC_STROBE_RISING_EDGE
timestamp: 2790842195 us, EVENT_DATA_NUMID_CIC_CXP_TRIGGER_ACK