Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
ImageManager/Cvb.Net/SimpleStreamingWithMock

This example program is located in your CVB installation under %CVB%Tutorial/ImageManager/Cvb.Net/SimpleStreamingWithMock.

Program.cs:

// Example that demonstrates how image data acquisition can be accomplished by using a mock GenTL
// Producer, so-called CVMockTL.

using System;
using System.Linq;
namespace Multistream
{
class SimpleStreamingWithMock
{
static void Main(string[] args)
{
// Retrieve CVMockTL in the given system.
var flags = DiscoverFlags.IgnoreVins | DiscoverFlags.IncludeMockTL;
using (var deviceInfoList = DeviceFactory.Discover(flags))
{
// Terminate the program if no candidates are found.
if (deviceInfoList.Count < 1)
{
Console.WriteLine("No devices found.");
return;
}
// Make sure if CVMockTL is on the candidate list.
var deviceInfo = deviceInfoList.First();
var foundMock = false;
foreach (var info in deviceInfoList)
{
info.AccessToken.Contains("MockTL");
deviceInfo = info;
foundMock = true;
break;
}
if (!foundMock)
{
Console.WriteLine("Could not find CVMockTL.");
return;
}
// Instantiate a GenICam device from the CVMockTL.
using (var device = DeviceFactory.Open(deviceInfo, AcquisitionStack.GenTL))
{
// Get the first stream of the device and start data streaming.
var stream = ((GenICamDevice)device).GetStream<ImageStream>(0);
stream.Start();
for (int imageIndex = 0; imageIndex < 10; imageIndex++)
{
// Wait for a single deliverable with a 10-second timeout value.
WaitStatus status;
using (var image = stream.Wait(out status))
{
if (status != WaitStatus.Ok)
{
Console.Write("An unexpected error occurred.");
continue;
}
// Retrieve VIN buffer node map and get the timestamp of the delivered image.
using (var nodeMaps = NodeMapDictionary.FromImage(image))
{
var bufferNodeMap = nodeMaps["VinBuffer"];
// Timestamp (UINT64) the buffer was acquired
var timestampNode = bufferNodeMap["Timestamp"] as IntegerNode;
// The ID of the frame that is transported in the corresponding buffer
var frameIDNode = bufferNodeMap["FrameID"] as IntegerNode;
// The total number of bytes written into the buffer
var sizeFilledNode = bufferNodeMap["SizeFilled"] as IntegerNode;
// Incompleteness indicates a corrupt buffer :
var isIncompleteNode = bufferNodeMap["IsIncomplete"] as BooleanNode;
// Padding in x-direction
var xPaddingNode = bufferNodeMap["XPadding"] as IntegerNode;
// Padding in y-direction
var yPaddingNode = bufferNodeMap["YPadding"] as IntegerNode;
Console.WriteLine(
$"Image #{imageIndex}, " +
$"Timestamp: 0x{timestampNode.Value:X8}, " +
$"FrameID: {frameIDNode.Value}, " +
$"Width: {image.Size.Width}, " +
$"Height: {image.Size.Height}, " +
$"SizeFilled: {sizeFilledNode.Value}, " +
$"IsIncomplete: {isIncompleteNode.Value}, " +
$"XPadding: {xPaddingNode.Value}, " +
$"YPadding: {yPaddingNode.Value}"
);
}
}
}
// Try aborting data streaming.
stream.TryAbort();
}
}
}
}
}
static DiscoveryInformationList Discover()
AcquisitionStack
WaitStatus