Impact Acquire SDK .NET
ContinuousCaptureSimple.cs

The ContinuousCaptureSimple program is a simple example for a continuous acquisition.

Program location
The source file ContinuousCaptureSimple.cs can be found under:
%INSTALLDIR%\apps\CSharp\ContinuousCaptureSimple\
Note
If you have installed the package without example applications, this file will not be available. On Windows® the sample application can be installed or removed from the target system at any time by simply restarting the installation package.
ContinuousCapture example:
  1. Opens a Balluff device.
  2. Snaps images continuously (without display using Linux).
Console Output
[0]: BF000306 (mvBlueFOX-202C, Family: mvBlueFOX, interface layout: DeviceSpecific)

Please enter the number in front of the listed device followed by [ENTER] to open it: 0
Using device number 0.
Press [ENTER] to end the application
Initialising the device. This might take some time...
Info from BF000306: FramesPerSecond: 28.655660, ErrorCount: 0, CaptureTime_s: 0.104195
Info from BF000306: FramesPerSecond: 28.655636, ErrorCount: 0, CaptureTime_s: 0.104017
Info from BF000306: FramesPerSecond: 28.655659, ErrorCount: 0, CaptureTime_s: 0.104153
Info from BF000306: FramesPerSecond: 28.655636, ErrorCount: 0, CaptureTime_s: 0.104072
Info from BF000306: FramesPerSecond: 28.655660, ErrorCount: 0, CaptureTime_s: 0.104234
How it works

In contrast to the continuous capture sample, the simple version uses functions from the mv.impact.acquire.helper namespace to simplify continuous acquisitions.

The helper namespace is included like this

using mv.impact.acquire.helper;

Afterwards, the mv.impact.acquire.helper.RequestProvider class is available and a new RequestProvider object can be created:

A helper class that can be used to create a simple continuous acquisition from a device.
Definition RequestProvider.cs:38

Now, two functions are available:

acquisitionStart() will intialize the device automatically, when starting the acquisition for the first time.

void acquisitionStart()
Starts a new continuous acquisition from the mv.impact.acquire.Device associated with this mv....
Definition RequestProvider.cs:231

By pressing [ENTER] the sample will stop and call acquisitionStop():

Console.ReadLine();
void acquisitionStop()
Stops a continuous acquisition from the mv.impact.acquire.Device associated with this mv....
Definition RequestProvider.cs:259
Source code
using System;
#if USE_DISPLAY
#endif // #if USE_DISPLAY
using mv.impact.acquire.examples.helper;
namespace mv.impact.acquire.examples
{
// A very simple listener that simply writes some information to
// the console each time a request is reported as ready.
public class MyConsoleRequestListener
{
public void requestReady(Object sender, RequestReadyEventArgs e)
{
// At the end of this scope the lock will automatically be freed.
// Never directly call mv.impact.acquire.Request.unlock, when working with
// mv.impact.acquire.hepler.RequestReadyEventArgs objects
using (RequestReadyEventData data = e.data)
{
if (data.request.isOK)
{
Console.WriteLine("Request {0} became ready. Image format: {1}({2}x{3}).", data.request.number, data.request.imagePixelFormat.readS(), data.request.imageWidth.read(), data.request.imageHeight.read());
}
else
{
Console.WriteLine("Request {0} has been reported with status '{1}'.", data.request.number, data.request.requestResult.readS());
}
}
}
}
#if USE_DISPLAY
// A more complex listener that draws the image in a display
// window each time a request is reported as ready. The message handler
// of this class will show how to handle situations, where a request cannot
// be unlocked immediately as here the display might want to redraw the image
// before a new request is reported as ready.
public class MyDisplayRequestListener : ImageDisplayWindow
{
private RequestReadyEventData data_ = null;
protected override void Dispose(bool disposing)
{
unlockData();
base.Dispose(disposing);
}
public MyDisplayRequestListener(String title) : base(title) { }
public void requestReady(Object sender, RequestReadyEventArgs e)
{
if (data.request.isOK)
{
# if CLR_AT_LEAST_3_DOT_5
// Extension methods are not supported by CLR versions smaller than 3.5 and this next function
// is therefore not available then.
imageDisplay.SetImage(data.request);
# else
// If extension methods are not available, the following function can be used instead. It is
// not as convenient and will only work for some pixel formats. For more complex pixel formats
// use other overloads of this method
imageDisplay.SetImage(data.request.imageData.read(), data.request.imageWidth.read(), data.request.imageHeight.read(), data.request.imageBytesPerPixel.read() * 8, data.request.imageLinePitch.read());
# endif
imageDisplay.Update();
if (data_ != null)
{
// now it is save to unlock the OLD request that has been attached to the display previously.
// Never directly call mv.impact.acquire.Request.unlock, when working with
// mv.impact.acquire.hepler.RequestReadyEventArgs objects
data_.Dispose();
}
data_ = data;
}
else
{
Console.WriteLine("Request {0} has been reported with status '{1}'.", data.request.number, data.request.requestResult.readS());
// Never directly call mv.impact.acquire.Request.unlock, when working with
// mv.impact.acquire.hepler.RequestReadyEventArgs objects
data.Dispose();
}
}
public void unlockData()
{
if (data_ != null)
{
imageDisplay.SetImage(IntPtr.Zero, 0, 0, 0, 0);
data_.Dispose();
data_ = null;
}
}
}
#endif // #if USE_DISPLAY
class ContinuousCaptureSimple
{
static void Main(string[] args)
{
mv.impact.acquire.LibraryPath.init(); // this will add the folders containing unmanaged libraries to the PATH variable.
Device pDev = DeviceAccess.getDeviceFromUserInput();
if (pDev == null)
{
Console.WriteLine("Unable to continue! Press any key to end the program.");
Console.Read();
Environment.Exit(1);
}
try
{
// register a very simple listener
MyConsoleRequestListener consoleListener = new MyConsoleRequestListener();
rp.onRequestReady += consoleListener.requestReady;
#if USE_DISPLAY
// register another more complex listener to demonstrate that there can be
// multiple listeners at the same time
using (MyDisplayRequestListener displayListener = new MyDisplayRequestListener(String.Format("MyRequestListener for device {0}", pDev.serial.read())))
{
rp.onRequestReady += displayListener.requestReady;
#endif // #if USE_DISPLAY
// When starting the acquisition for the first time the device will
// be intialised automatically
Console.WriteLine("Initialising the device. This might take some time...");
Console.WriteLine("Press [ENTER] to end the application");
Console.ReadLine();
#if USE_DISPLAY
}
#endif // #if USE_DISPLAY
}
{
Console.WriteLine("An error occurred while opening the device " + pDev.serial +
"(error code: " + e.Message + "). Press any key to end the application...");
Console.ReadLine();
}
}
}
}
This class and its functions represent an actual device detected by this interface in the current sys...
Definition Device.cs:91
readonly PropertyS serial
A string property (read-only) containing the serial number of this device.
Definition Device.cs:516
T read()
Reads a value from a property.
Definition EnumPropertyI.cs:342
An base class for exceptions generated by Impact Acquire.
Definition Exceptions.cs:9
A small helper class to administer various library search path related variables and paths.
Definition LibraryPath.cs:14
static void init()
Calling this method will add the folders containing unmanaged libraries to the systems library search...
Definition LibraryPath.cs:251
IntPtr read()
Reads a value from a property.
Definition PropertyPtr.cs:49
String read()
Reads a value from a property.
Definition PropertyS.cs:144
readonly PropertyPtr imageData
A pointer property (read-only) containing the start address of the image data.
Definition Request.cs:1579
readonly PropertyI imageLinePitch
An integer property (read-only) containing the offset (in bytes) to the next line of each channel bel...
Definition Request.cs:1655
readonly EnumPropertyI< TRequestResult > requestResult
An enumerated integer property (read-only) defining the result of this request.
Definition Request.cs:1211
int number
Returns the number associated with this request.
Definition Request.cs:1194
readonly PropertyI imageWidth
An integer property (read-only) containing the width of the image in pixels.
Definition Request.cs:1693
readonly PropertyI imageBytesPerPixel
An integer property (read-only) containing the number of bytes per pixel in this image.
Definition Request.cs:1679
bool isOK
Convenience function to check if a request has been processed successfully.
Definition Request.cs:1173
readonly PropertyI imageHeight
An integer property (read-only) containing the height of the image in pixels.
Definition Request.cs:1704
readonly EnumPropertyI< TImageBufferPixelFormat > imagePixelFormat
An enumerated integer property (read-only) containing the pixel format of this image.
Definition Request.cs:1540
A class that can be used to display images in a window.
Definition ImageDisplayWindow.cs:15
A class containing data generated by a request ready event fired by instances of the class mv....
Definition RequestReadyEventArgs.cs:45
RequestReadyEventData data
Locks the data associated with this event so that the data can be accessed safely while holding the l...
Definition RequestReadyEventArgs.cs:142
A class containing data stored inside a mv.impact.acquire.helper.RequestReadyEventArgs event fired by...
Definition RequestReadyEventData.cs:18
Request request
A reference to the mv.impact.acquire.Request object that just became ready.
Definition RequestReadyEventData.cs:88
void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
Definition RequestReadyEventData.cs:69
This namespace contains classes and functions that can be used to display images.
Definition Enumerations.cs:2
This namespace contains some small helper classes and convenience functions belonging to the image ac...
This namespace contains classes and functions belonging to the image acquisition module of this SDK.
Definition Enumerations.cs:2
Definition Enumerations.cs:2
Definition Enumerations.cs:2