To associate a user supplied buffer with this request, you have to do the following:
Finally, if you press [ENTER], the image window will be destroyed and the device will be closed.
using System;
using System.Collections.Generic;
using System.Threading;
#if USE_DISPLAY
#endif
using mv.impact.acquire.examples.helper;
namespace mv.impact.acquire.examples
{
class CaptureToUserMemory
{
public class ThreadParameters
{
#if USE_DISPLAY
#endif
public bool terminated = false;
public bool userSuppliedMemoryUsed = false;
public List<UserSuppliedHeapBuffer> buffers = new List<UserSuppliedHeapBuffer>();
public ThreadParameters(
Device d)
{
pDev = d;
}
}
static void CaptureThread(object data)
{
ThreadParameters parameters = (ThreadParameters)data;
if (result !=
TDMR_ERROR.DEV_NO_FREE_REQUEST_AVAILABLE)
{
}
DeviceAccess.manuallyStartAcquisitionIfNeeded(parameters.pDev, parameters.fi);
int timeout_ms = 500;
int cnt = 0;
while (!parameters.terminated)
{
requestNr = parameters.fi.imageRequestWaitFor(timeout_ms);
pRequest = parameters.fi.isRequestNrValid(requestNr) ? parameters.fi.getRequest(requestNr) : null;
if (pRequest != null)
{
{
++cnt;
if (cnt % 100 == 0)
{
Console.WriteLine("Info from {0}: {1}: {2}, {3}: {4}, {5}: {6}", parameters.pDev.serial.read(),
}
#if USE_DISPLAY
# if CLR_AT_LEAST_3_DOT_5
parameters.window.imageDisplay.SetImage(pRequest);
# else
# endif
parameters.window.imageDisplay.Update();
#endif
UserSuppliedMemory.checkCaptureBufferAddress(pRequest, parameters.userSuppliedMemoryUsed, parameters.buffers);
}
else
{
}
if (pPreviousRequest != null)
{
}
pPreviousRequest = pRequest;
parameters.fi.imageRequestSingle();
}
}
DeviceAccess.manuallyStopAcquisitionIfNeeded(parameters.pDev, parameters.fi);
#if USE_DISPLAY
parameters.window.imageDisplay.RemoveImage();
#endif
if (pRequest != null)
{
}
parameters.fi.imageRequestReset(0, 0);
}
public static void runThread(ThreadParameters captureParams)
{
captureParams.terminated = false;
Thread thread = new Thread(CaptureToUserMemory.CaptureThread);
thread.Start(captureParams);
Console.ReadLine();
captureParams.terminated = true;
thread.Join();
}
public static void exitOnError(String message)
{
Console.WriteLine(message);
Console.WriteLine("Press [ENTER] to exit the application.");
Console.ReadLine();
System.Environment.Exit(1);
}
static void Main(string[] args)
{
Device pDev = DeviceAccess.getDeviceFromUserInput();
if (pDev == null)
{
exitOnError("Unable to continue!");
}
Console.WriteLine("Initialising the device. This might take some time...");
try
{
}
{
exitOnError(String.Format(
"An error occurred while opening device " + pDev.
serial +
"(error code: " + e.Message + ")."));
}
ThreadParameters captureParams = new ThreadParameters(pDev);
#if USE_DISPLAY
#endif
Console.WriteLine("The device will try to capture continuously into memory automatically allocated be the device driver.");
Console.WriteLine("This is the default behaviour.");
Console.WriteLine("Press [ENTER] to end the continuous acquisition.");
runThread(captureParams);
Console.WriteLine("The device will now try to capture continuously into user supplied memory.");
int bufferSize = 0;
int bufferAlignment = 0;
TDMR_ERROR result = (
TDMR_ERROR)captureParams.fi.getCurrentCaptureBufferLayout(captureParams.irc, out bufferSize, out bufferAlignment);
{
exitOnError(String.Format(
"An error occurred while querying the current capture buffer layout for device {0}(error code: {1}). Press [ENTER] to end the application...", captureParams.pDev.serial.read(),
ImpactAcquireException.
getErrorCodeAsString(result)));
}
result = UserSuppliedMemory.createCaptureBuffers(captureParams.fi, captureParams.buffers, bufferSize, bufferAlignment);
{
exitOnError(String.Format(
"An error occurred while setting up the user supplied buffers for device {0}(error code: {1}). Press [ENTER] to end the application...", captureParams.pDev.serial.read(),
ImpactAcquireException.
getErrorCodeAsString(result)));
}
captureParams.userSuppliedMemoryUsed = true;
runThread(captureParams);
UserSuppliedMemory.freeCaptureBuffers(captureParams.fi, captureParams.buffers);
captureParams.userSuppliedMemoryUsed = false;
Console.WriteLine("The device will try to capture continuously into memory automatically allocated be the device driver again.");
Console.WriteLine("This is the default behaviour.");
runThread(captureParams);
Console.WriteLine("Now the device will try to capture one frame into a specific user supplied buffer");
const int REQUEST_TO_USE = 2;
Request pRequest = captureParams.fi.getRequest(REQUEST_TO_USE);
try
{
{
}
}
{
exitOnError(String.Format(
"An error occurred while attaching a user buffer to request number {0}: {1}.", REQUEST_TO_USE, e.
errorCodeAsString));
}
captureParams.irc.requestToUse.write(REQUEST_TO_USE);
result = (
TDMR_ERROR)captureParams.fi.imageRequestSingle(captureParams.irc, out requestUsed);
{
}
if (requestUsed != REQUEST_TO_USE)
{
Console.WriteLine("ERROR! An acquisition into buffer {0} was requested, but the driver did use {1} for this acquisition.", REQUEST_TO_USE, requestUsed);
}
{
{
}
}
int requestNr = captureParams.fi.imageRequestWaitFor(-1);
{
{
}
}
pRequest = captureParams.fi.getRequest(requestNr);
{
exitOnError(String.Format(
"Error: {0}", pRequest.
requestResult.readS()));
}
Console.WriteLine("Capture into specific user supplied buffer done.");
#if USE_DISPLAY
# if CLR_AT_LEAST_3_DOT_5
captureParams.window.imageDisplay.SetImage(pRequest);
# else
# endif
captureParams.window.imageDisplay.Update();
#endif
Console.WriteLine("Press [ENTER] to end the application.");
Console.ReadLine();
#if USE_DISPLAY
captureParams.window.Dispose();
#endif
captureParams.fi.imageRequestUnlock(requestNr);
captureParams.fi.imageRequestReset(0, 0);
}
}
}
This class and its functions represent an actual device detected by this interface in the current sys...
Definition Device.cs:91
const int INVALID_ID
A symbolic constant to define an invalid handle.
Definition Device.cs:178
readonly EnumPropertyI< TAcquisitionStartStopBehaviour > acquisitionStartStopBehaviour
An enumerated integer property defining the start/stop behaviour during acquisition of this driver in...
Definition Device.cs:731
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
EnumPropertyI< T > write(T value)
Writes one value to the property.
Definition EnumPropertyI.cs:449
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
A helper class to control the way an image request will be processed.
Definition ImageRequestControl.cs:8
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
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
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
int attachUserBuffer(IntPtr pBuf, int bufSize)
Convenience function to attach a user supplied buffer to a mv.impact.acquire.Request object.
Definition Request.cs:674
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
int unlock()
Unlocks the request for the driver again.
Definition Request.cs:619
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 for accessing general settings that control the overall behaviour of a device driver.
Definition SystemSettings.cs:6
readonly PropertyI requestCount
An integer property defining the number of requests allocated by the driver.
Definition SystemSettings.cs:60
A class that can be used to display images in a window.
Definition ImageDisplayWindow.cs:15
A small helper class to create a user supplied buffer on the heap.
Definition UserSuppliedHeapBuffer.cs:13
int size
Returns the size in bytes of the user buffer.
Definition UserSuppliedHeapBuffer.cs:53
IntPtr pointer
Returns an System.IntPtr instance pointing to the aligned memory location.
Definition UserSuppliedHeapBuffer.cs:51
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
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