Single Stream

<< Click to Display Table of Contents >>

Navigation:  Migration Guide for the Acquisition Stacks > CVB C# >

Single Stream

What has changed?

In the 2nd generation acquisition stack the stream from the device was assumed to always yield images. However, depending on the hardware, a stream can also contain point clouds or any other type of data. Therefore we provide the generic stream type composite. A composite can be an image, a multi part image or a point cloud.

From the device a data stream should be instantiated with the expected stream type or the generic stream type composite. The different stream types are described in the chapter Stream Types. The stream type composite allows for a dynamic payload interpretation as it is composed of the other interpretable object types. For example this object type can combine buffers holding both, an image and a point cloud in the same object.

Starting the stream and waiting for the result has not changed much. If this offers advantages (like synchronously starting all streams), the stream start may now be split into starting the engine and the device separately, but in most cases this won't be needed.

The next difference will be in the wait function to return the streamed objects. The result consists of three components: The actual composite, a status code, indicating the success of the wait, and optionally a node map enumerator, which can hold node maps delivering information about the received object parts. It is recommended to check the status first. If the status is not "Ok" one must assume that something went wrong and the composite does not actually hold a valid handle to newly acquired data.

Please note that with the 3rd generation acquisition stack the DeviceImage supported by the 2nd generation stack will no longer be usable and will always be null.

 

Code Examples

2nd generation stack

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))

{

using (var device = DeviceFactory.Open(devices[0], AcquisitionStack.Vin))

 {

   var stream = device.Stream;

   stream.Start();

   for (int i = 0; i < 10; i++)

   {

    using (var image = stream.Wait(out WaitStatus status))

     {

       // work with the acquired image

     }

   }

   stream.Abort();

 }

}

(5) In the 2nd generation stack the stream is always an image stream. Each device can have only one stream.

(6) The acquisition stream is started.

(9) The wait function waits until the globally set timeout for the next acquired image and (unless a timeout occurred) returns it. The function returns a result structure that combines the wait status and the acquired image. The wait status informs about the validity of the acquired image and should be checked prior to working with the image.

(13) The abort operation immediately stops the ongoing streaming. Restarting the stream will take a significant amount of time, typically in the 100 to 200 ms range.

 

With the 3rd generation acquisition stack it is also possible to access a set of buffer node maps that provide extended diagnostic information:

3rd generation stack

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))

{

using (var device = DeviceFactory.Open(devices[0], AcquisitionStack.GenTL) as GenICamDevice)

 {

  var stream = device.GetStream<CompositeStream>(0);

  stream.Start();

  for (int i = 0; i < 10; i++)

   {

using (var composite = stream.Wait(out WaitStatus status))

 {

  using (var nodeMaps = NodeMapDictionary.FromBuffer(composite))

   {

    // do something with the composite and the node map

   }

 }

   }

  stream.Abort();

 }

}

(5) A data stream is instantiated with index zero (default; when working with devices with more than one stream, the stream index could be passed as parameter). The stream type is defined by the generic parameter of the stream query function. The returned object is a shared pointer to the stream object.

(6) The stream acquisition is simplified to the combined start, which advises the driver to start the acquisition engine and stream control mechanism automatically. A user does not have to call these separate streaming components separately. How to call them separately is described in Multiple Streams. By default, infinite acquisition is triggered.

After starting the stream, the stream engine and control are running in the background until the stream is stopped, sending a continuous flow of images or composites.

(9) Each composite will need to be proactively waited for by means of a call to wait on the stream. It is possible to pass a timeout to this function, which defines the maximum time to wait for the next piece of data. The returned value is a composite, as well as the status code and a nodemap enumerator, which are described in the introduction of this chapter.

(12) The node map dictionary needs to be deleted manually. The composite is freed automatically with the using statement, bu the node map dictionary will keep the buffer locked if not deleted.

(15) The abort operation immediately stops the ongoing streaming. Restarting the stream will take a significant amount of time, typically in the 100 to 200 ms range.

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

if (composite.Purpose == CompositePurpose.Image)

Console.WriteLine("is image");

else if (composite.Purpose == CompositePurpose.ImageList)

Console.WriteLine("is image list");

else if (composite.Purpose == CompositePurpose.MultiAoi)

Console.WriteLine("is multi aoi");

else if (composite.Purpose == CompositePurpose.RangeMap)

Console.WriteLine("is range map");

else if (composite.Purpose == CompositePurpose.PointCloud)

Console.WriteLine("is point cloud");

else if (composite.Purpose == CompositePurpose.ImageCube)

Console.WriteLine("is image cube");

else if (composite.Purpose == CompositePurpose.Custom)

Console.WriteLine("is custom");

else

Console.WriteLine("is something else");

(1) The composite's purpose can be found out by the purpose function.

 

Summary

A device can be identified through a discovery information object.

Start data acquisition by the start function. This safely starts the acquisition engine, and the data stream module, in that order.

The abort operation immediately terminates the ongoing data acquisition process while the stop operation waits until the ongoing data acquisition process is completed.