The continuous acquisition is similar to the single capture. The only major difference is, that this sample starts a separate thread that continuously requests images from the device.
static void Main(string[] args)
{
if (DeviceManager.deviceCount < 1)
{
Console.WriteLine("Unable to continue! Press any key to end the program.");
Console.Read();
Environment.Exit(1);
}
string productFilter = "";
if (args.Length == 1)
{
for (int i = 0; i < args.Length; i++)
{
string param = args[i], key, value;
int keyEnd = param.IndexOf('=');
if ((!param.Contains("=")) || (keyEnd == param.Length))
{
Console.WriteLine("Invalid command-line parameter: '{0}' (ignored).", param);
}
else
{
key = param.Substring(0, keyEnd);
value = param.Substring(keyEnd + 1);
if ((key == "product") || (key == "p"))
{
productFilter = value;
}
else
{
Console.WriteLine("Invalid command-line parameter: '{0}' (ignored).", param);
}
}
}
}
else
{
Console.WriteLine("No command-line parameters specified. Available parameters:");
Console.WriteLine(" 'product' or 'p' to specify a certain product type. All other products will be ignored then");
Console.WriteLine(" a '*' serves as a wildcard.");
Console.WriteLine();
Console.WriteLine("USAGE EXAMPLE:");
Console.WriteLine(" ContinuousCaptureAllDevices p=mvBlue* ");
Console.WriteLine();
}
List<ThreadParameters> threadParams = new List<ThreadParameters>();
for (int i = 0; i < DeviceManager.deviceCount; i++)
{
if (DeviceManager.deviceList[i].product.read().Contains(productFilter))
{
string windowtitle = String.Concat("mvIMPACT_acquire sample, Device " + DeviceManager.deviceList[i].serial.read());
threadParams.Add(new ThreadParameters(DeviceManager.deviceList[i], windowtitle));
Console.WriteLine("{0} ({1})", DeviceManager.deviceList[i].family.read(), DeviceManager.deviceList[i].serial.read());
}
}
if (threadParams.Count == 0)
{
Console.WriteLine("No device found that matches the product filter '{0}'! Unable to continue!", productFilter);
Environment.Exit(1);
}
foreach (ThreadParameters p in threadParams)
{
p.thread = new Thread(ContinuousCaptureAllDevices.liveThread);
p.thread.Start(p);
}
Console.WriteLine("Press [ENTER] to start the acquisition( the initialisation of the devices might take some time )");
Console.ReadKey();
Console.WriteLine("Terminating live threads...");
foreach (ThreadParameters p in threadParams)
{
p.terminated = true;
p.thread.Join();
}
}
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
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
Then after the device has been initialized successfully image requests will constantly be sent to the drivers request queue and the application waits for the results:
TDMR_ERROR result = TDMR_ERROR.DMR_NO_ERROR;
while ((result = (TDMR_ERROR)fi.imageRequestSingle()) == TDMR_ERROR.DMR_NO_ERROR) { };
if (result != TDMR_ERROR.DEV_NO_FREE_REQUEST_AVAILABLE)
{
Console.WriteLine("'FunctionInterface.imageRequestSingle' returned with an unexpected result: {0}", result);
Console.WriteLine("({0})", ImpactAcquireException.getErrorCodeAsString(result));
}
{
if ((result = (TDMR_ERROR)(fi.acquisitionStart())) !=
TDMR_ERROR.DMR_NO_ERROR)
{
Console.WriteLine("'FunctionInterface.acquisitionStart' returned with an unexpected result: {0}", result);
Console.WriteLine("({0})", ImpactAcquireException.getErrorCodeAsString(result));
}
}
Request pRequest = null;
int timeout_ms = 500;
int requestNr = -1;
int lastRequestNr = -1;
while (!pThreadParameter.terminated)
{
requestNr = fi.imageRequestWaitFor(timeout_ms);
if (fi.isRequestNrValid(requestNr))
{
pRequest = fi.getRequest(requestNr);
if (pRequest.isOK)
{
++cnt;
if (cnt % 100 == 0)
{
Console.WriteLine("Info from {0}: {1}: {2}, {3}: {4}, {5}: {6}", pThreadParameter.pDev.serial.read(),
statistics.framesPerSecond.name, statistics.framesPerSecond.readS(),
statistics.errorCount.name, statistics.errorCount.readS(),
statistics.captureTime_s.name, statistics.captureTime_s.readS());
}
}
else
{
Console.WriteLine("Error: {0}", pRequest.requestResult.readS());
}
if (fi.isRequestNrValid(lastRequestNr))
{
fi.imageRequestUnlock(lastRequestNr);
}
lastRequestNr = requestNr;
fi.imageRequestSingle();
}
else
{
Console.WriteLine("imageRequestWaitFor failed ({0}, {1}, device {2})", requestNr, ImpactAcquireException.getErrorCodeAsString(requestNr), pThreadParameter.pDev.serial.read());
Console.WriteLine(", timeout value too small?");
}
}
TDMR_ERROR
Errors reported by the device manager.
Definition mvDriverBaseEnums.cs:2375
TAcquisitionStartStopBehaviour
Defines valid modes for acquisition start/stop behaviour.
Definition mvDriverBaseEnums.cs:76
The image attached to the request can then be processed and/or displayed if the request does not report an error.
When the image is no longer needed you have to unlock the image buffer as otherwise the driver will refuse to use it again. This makes sure, that no image, that is still used by the user will be overwritten by the device:
using System;
using System.Collections.Generic;
using System.Threading;
#if USE_DISPLAY
#endif
using mv.impact.acquire.examples.helper;
namespace ContinuousCaptureAllDevices
{
class ContinuousCaptureAllDevices
{
public class ThreadParameters
{
public Thread thread;
#if USE_DISPLAY
#endif
public bool terminated = false;
public ThreadParameters(
Device Dev,
string windowtitle)
{
pDev = Dev;
#if USE_DISPLAY
#endif
}
public void terminateThread()
{
terminated = true;
}
}
public static void liveThread(Object pData)
{
ThreadParameters pThreadParameter = (ThreadParameters)pData;
Device pDev = pThreadParameter.pDev;
uint cnt = 0;
Console.WriteLine(
"Trying to open {0}", pDev.
serial.
read());
try
{
}
{
Console.WriteLine(
"An error occurred while opening the device {0}", pDev.
serial.
read());
Console.WriteLine("Press [ENTER] to end the application...");
return;
}
Console.WriteLine(
"Opened {0}", pDev.
serial.
read());
#if USE_DISPLAY
ImageDisplay display = pThreadParameter.window.imageDisplay;
#endif
if (result !=
TDMR_ERROR.DEV_NO_FREE_REQUEST_AVAILABLE)
{
Console.WriteLine("'FunctionInterface.imageRequestSingle' returned with an unexpected result: {0}", result);
}
DeviceAccess.manuallyStartAcquisitionIfNeeded(pDev, fi);
int timeout_ms = 500;
int requestNr = -1;
int lastRequestNr = -1;
while (!pThreadParameter.terminated)
{
{
{
++cnt;
if (cnt % 100 == 0)
{
Console.WriteLine(
"Info from {0}: {1}: {2}, {3}: {4}, {5}: {6}", pDev.
serial.
read(),
}
#if USE_DISPLAY
# if CLR_AT_LEAST_3_DOT_5
# else
# endif
#endif
}
else
{
}
{
}
lastRequestNr = requestNr;
}
}
DeviceAccess.manuallyStopAcquisitionIfNeeded(pDev, fi);
#if USE_DISPLAY
#endif
{
}
}
static void Main(string[] args)
{
{
Console.WriteLine("Unable to continue! Press any key to end the program.");
Console.Read();
Environment.Exit(1);
}
string productFilter = "";
if (args.Length >= 1)
{
for (int i = 0; i < args.Length; i++)
{
string param = args[i];
int keyEnd = param.IndexOf('=');
if ((!param.Contains("=")) || (keyEnd == param.Length))
{
Console.WriteLine("Invalid command-line parameter: '{0}' (ignored).", param);
}
else
{
string key = param.Substring(0, keyEnd);
string value = param.Substring(keyEnd + 1);
if ((key == "product") || (key == "p"))
{
productFilter = value;
}
else
{
Console.WriteLine("Invalid command-line parameter: '{0}' (ignored).", param);
}
}
}
}
else
{
Console.WriteLine("No command-line parameters specified. Available parameters:");
Console.WriteLine(" 'product' or 'p' to specify a certain product type. All other products will be ignored then");
Console.WriteLine(" a '*' serves as a wildcard.");
Console.WriteLine();
Console.WriteLine("USAGE EXAMPLE:");
Console.WriteLine(" ContinuousCaptureAllDevices p=mvBlue*");
Console.WriteLine();
}
List<ThreadParameters> threadParams = new List<ThreadParameters>();
{
{
string windowtitle = String.Concat(
"mvIMPACT_acquire sample, Device " +
DeviceManager.
deviceList[i].serial.read());
}
}
if (threadParams.Count == 0)
{
Console.WriteLine("No device found that matches the product filter '{0}'! Unable to continue!", productFilter);
Environment.Exit(1);
}
foreach (ThreadParameters p in threadParams)
{
p.thread = new Thread(ContinuousCaptureAllDevices.liveThread);
p.thread.Start(p);
}
Console.WriteLine("Press [ENTER] to start the acquisition( the initialisation of the devices might take some time )");
Console.ReadKey();
Console.WriteLine("Terminating live threads...");
foreach (ThreadParameters p in threadParams)
{
p.terminated = true;
p.thread.Join();
}
}
}
}
Grants access to devices that can be operated by this software interface.
Definition DeviceManager.cs:157
static ReadOnlyCollection< Device > deviceList
Returns a list of all devices currently detected by the device manager.
Definition DeviceManager.cs:1030
static int deviceCount
Returns the number of devices currently present in the system.
Definition DeviceManager.cs:1064
This class and its functions represent an actual device detected by this interface in the current sys...
Definition Device.cs:91
readonly EnumPropertyI< TAcquisitionStartStopBehaviour > acquisitionStartStopBehaviour
An enumerated integer property defining the start/stop behaviour during acquisition of this driver in...
Definition Device.cs:731
readonly EnumPropertyI< TDeviceInterfaceLayout > interfaceLayout
An enumerated integer property which can be used to define which interface layout shall be used when ...
Definition Device.cs:604
void open()
Opens a device.
Definition Device.cs:209
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
The function interface to devices supported by this interface.
Definition FunctionInterface.cs:21
int imageRequestSingle()
Sends an image request to the mv.impact.acquire.Device driver.
Definition FunctionInterface.cs:656
Request getRequest(int nr)
Returns a const pointer to the desired mv.impact.acquire.Request.
Definition FunctionInterface.cs:452
int imageRequestUnlock(int nr)
Unlocks the request for the driver again.
Definition FunctionInterface.cs:987
int imageRequestWaitFor(int timeout_ms)
Waits for a request object to become ready.
Definition FunctionInterface.cs:1021
int imageRequestReset(int requestCtrlNr)
Deletes all requests currently queued for the specified mv.impact.acquire.ImageRequestControl.
Definition FunctionInterface.cs:575
bool isRequestNrValid(int nr)
Check if nr specifies a valid mv.impact.acquire.Request.
Definition FunctionInterface.cs:1098
An base class for exceptions generated by Impact Acquire.
Definition Exceptions.cs:9
static String getErrorCodeAsString(int errorCode)
Returns a string representation of a error.
Definition Exceptions.cs:48
String errorCodeAsString
Returns a string representation of the error associated with the exception.
Definition Exceptions.cs:118
int errorCode
Returns a unique numerical representation for this error.
Definition Exceptions.cs:101
IntPtr read()
Reads a value from a property.
Definition PropertyPtr.cs:49
String read()
Reads a value from a property.
Definition PropertyS.cs:144
Contains information about a captured buffer.
Definition Request.cs:77
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
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
Contains statistical information.
Definition Statistics.cs:10
readonly PropertyI errorCount
An integer property (read-only) containing the overall count of image requests which returned with an...
Definition Statistics.cs:82
readonly PropertyF framesPerSecond
A float property (read-only) containing the current number of frames captured per second.
Definition Statistics.cs:98
readonly PropertyF captureTime_s
A float property (read-only) containing the average time needed to capture an image.
Definition Statistics.cs:75
A class that can be used to display images in a window.
Definition ImageDisplayWindow.cs:15
A class that can be used for displaying images within existing windows or GUI elements that can provi...
Definition ImageDisplay.cs:39
void RemoveImage()
Removes the current image from the display.
Definition ImageDisplay.cs:327
void SetImage(IntPtr pData, int width, int height, int bipp, int pitch)
Sets the next image to display.
Definition ImageDisplay.cs:282
void Update()
Immediately redraws the current image.
Definition ImageDisplay.cs:333
TDeviceInterfaceLayout
Defines valid interface layouts for the device.
Definition mvDriverBaseEnums.cs:1922
This namespace contains classes and functions that can be used to display images.
Definition Enumerations.cs:2