.NET assembly
eGrabber can be used in .NET languages (C#, VB.NET, etc.) via a .NET assembly named Coaxlink_NetApi.dll.
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;
namespace FirstExample {
class ShowInfo {
const int CARD_IX = 0;
const int DEVICE_IX = 0;
static void showInfo() {
using (Euresys.EGenTL gentl = new Euresys.EGenTL()) { // 1
using (Euresys.EGrabberCallbackOnDemand grabber =
new Euresys.EGrabberCallbackOnDemand(gentl, CARD_IX, DEVICE_IX)) { // 2
String card = grabber.getStringInterfaceModule("InterfaceID"); // 3
String dev = grabber.getStringDeviceModule("DeviceID"); // 4
long width = grabber.getIntegerRemoteModule("Width"); // 5
long height = grabber.getIntegerRemoteModule("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 a Euresys.EGenTL object. This involves the following operations: |
|
□
|
locate and dynamically load the Coaxlink GenTL producer (coaxlink.cti); |
|
□
|
retrieve pointers to the functions exported by coaxlink.cti; |
|
□
|
initialize coaxlink.cti. |
|
2.
|
Create a Euresys.EGrabberCallbackOnDemand 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. Notice the InterfaceModule suffix in getStringInterfaceModule. This indicates that we want an answer from the interface module. |
|
4.
|
Similarly, find out the ID of the device. This time, we use getStringDeviceModule to target the device module. |
|
5.
|
Finally, read the camera resolution. This time, we use getIntegerRemoteModule because values must be read from the camera. |
|
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
Differences between C++ and .NET EGrabber
Following terms are placeholders:
|
□
|
MODULE can be replaced by InterfaceModule, DeviceModule... |
|
□
|
EVENT_DATA can be replaced by NewBufferData, CicData... |
EGrabber classes
EGrabber<>
|
- |
EGrabber<CallbackOnDemand>
|
EGrabberCallbackOnDemand
|
EGrabber<CallbackSingleThread>
|
EGrabberCallbackSingleThread
|
EGrabber<CallbackMultiThread>
|
EGrabberCallbackMultiThread
|
EGrabber methods
getInfo<MODULE,TYPE>(cmd)
|
getInfoMODULE(cmd, out ...)
|
getInteger<MODULE>(f)
|
getIntegerMODULE(f)
|
getFloat<MODULE>(f)
|
getFloatMODULE(f)
|
getString<MODULE>(f)
|
getStringMODULE(f)
|
getStringList<MODULE>(f)
|
getStringListMODULE(f)
|
setInteger<MODULE>(f, v)
|
setIntegerMODULE(f, v)
|
setFloat<MODULE>(f, v)
|
setFloatMODULE(f, v)
|
setString<MODULE>(f, v)
|
setStringMODULE(f, v)
|
execute<MODULE>(f)
|
executeMODULE(f)
|
enableEvent<EVENT_DATA>()
|
enableEVENT_DATAEvent(f)
|
disableEvent<EVENT_DATA>()
|
disableEVENT_DATAEvent(f)
|
Callbacks
In .NET, callbacks are defined as delegates:
grabber.onNewBufferEvent = delegate ...
grabber.onDataStreamEvent = delegate ...
grabber.onCicEvent = delegate ...
grabber.onIoToolboxEvent = delegate ...
grabber.onCxpInterfaceEvent = delegate ...
A complete example is given in the next section.
Single thread callbacks
This program displays basic information about CIC events generated by a grabber, using the CallbackSingleThread model. This is the C# version of the C++ CallbackSingleThread example:
using System;
namespace Callbacks {
class CallbackExample {
static void showEvents(Euresys.EGrabberCallbackSingleThread grabber) {
grabber.runScript("config.js"); // 1
grabber.onCicEvent = delegate(Euresys.EGrabberCallbackSingleThread g, // 2
Euresys.CicData data) {
System.Console.WriteLine("timestamp: {0} us, {1}", // 3
data.timestamp, data.numid);
}; // 4
grabber.enableCicDataEvent(); // 5
grabber.reallocBuffers(3); // 6
grabber.start(); // 6
while (true) { // 6
}
}
static void Main() {
try {
using (Euresys.EGenTL gentl = new Euresys.EGenTL()) {
using (Euresys.EGrabberCallbackSingleThread grabber =
new Euresys.EGrabberCallbackSingleThread(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 CIC events: |
|
□
|
create a delegate that will be called by EGrabber when a CIC event occurs; this delegate will be called with two arguments: the grabber and the CicData containing information about the event; |
|
□
|
set the grabber's onDataStreamEvent to this delegate function. |
|
3.
|
In the body of the callback function, simply display basic information about the event. |
|
4.
|
This ends the definition of the onCicEvent callback function. |
|
5.
|
Enable onCicEvent callbacks. |
|
6.
|
Start the grabber and enter an infinite loop. CIC events will be notified in a dedicated 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