Multiple Streams

<< Click to Display Table of Contents >>

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

Multiple Streams

This example expands the use case of the single data stream example to multi stream devices, for example devices that potentially deliver more than just one data stream with potentially different data types per stream and potentially asynchronously delivered data. An example for such a device is a multispectral camera providing multiple streams transferring different spectral information.

 

Code Example

When working in a multi stream scenario, it often makes sense to split the stream start into its two separate steps (engine start and device start). This is because the sum of both steps is significantly longer than the DeviceStart step alone - which can lead to notable latencies between the streams: When working with Stream::Start() the first stream might already have acquired some three to five images before the next one is up and running. Coding it as follows will drastically reduce this effect:

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 streams = Enumerable.Range(0, device.StreamCount).Select(i =>

         device.GetStream<ImageStream>(i)).ToArray();

      foreach (var stream in streams)

          stream.EngineStart();

      foreach (var stream in streams)

          stream.DeviceStart();

      // your acquisition here

      foreach (var stream in streams)

          stream.DeviceAbort();

      foreach (var stream in streams)

          stream.EngineAbort();

   }

}

(5) Where previously only one data stream was accessed, now all available streams on the device are accessed. Therefore, the index based stream fetching is used. The number of available streams gets queried with the stream count function on the device - the queried streams are collected as image stream type. This enables parallel streaming over all streams.

(8) The acquisition engine on all streams is started.

(10) The device acquisition is started in all streams.

(13) The device acquisition has to be either stopped or aborted. Following the reverse order compared to starting the stream, now the stream control is stopped before the acquisition engines for each stream.

(15) Finally the acquisition engine is stopped / aborted on all streams.

 

Summary

When using multi stream devices, the sequence of actions necessary on a single stream device simply needs to be extended from 1 stream to N streams. This means that start, stop and wait for on the stream need to be called in a loop over all the required streams. When working with asynchronous streams it should be considered to put the Wait() calls into dedicated threads to make sure that the streams don't stall each other.