# Using Chunk Data in CVB

**URL:** <https://forum.commonvisionblox.com/t/using-chunk-data-in-cvb/1895>\
**Category:** Python API\
**Created:** [January 24, 2023, 9:44am UTC](https://forum.commonvisionblox.com/t/using-chunk-data-in-cvb/1895 "2023-01-24T09:44:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/simon/32/847_2.png) [@Simon](https://forum.commonvisionblox.com/u/Simon)\
**Post date:** [January 24, 2023, 9:44am UTC](https://forum.commonvisionblox.com/t/using-chunk-data-in-cvb/1895/1 "2023-01-24T09:44:37Z")

</div>

There are multiple ways to use _Chunk Data_ in CVB. First of all it is depending on the device(s) that you are using and the options they are supporting.  
In the following example a Teledyne Dalsa Genie Nano GigE Vision camera is used to acquire _Chunk Timestamps_ from every image frame transmitted.

Generally there are the following preconditions required.

1. The used Device needs to support _Chunk Data_:  
For the Teledyne Dalsa Genie Nano, the acailable _Chunk Nodes_ can be read from the NodeMap. Available _Chunk Data_ are regularly described in the device manual.  
 ![grafik](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/2X/9/9bd25498a50b3d4f9d688c3a5318cc0c40e886da.png)

2. On the camera side _Chunk Data_ need to be enabled to be attached to the image buffer. For the Teledyne Dalsa Genie Nano the displayed name is _Metadata Mode_ while the node can be reached by _Std::ChunkModeActive_ as the standard determines.  
 ![grafik](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/2X/0/0459216162404e377cefb9354fc34db3bbcca1df.png)

3. Last condition to receive _Chunk Data_ is that on the software side CVB is set to acqire Chunk Data as well. This can be done in the driver settings.  
 ![grafik](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/2X/e/e60bfe13bd67875ba6f9fba6327099ccf39ab626.png)

The following post will show how to acquire Chunk Data in CVB using the API without having to access the raw buffer memory as described for example [here](https://forum.commonvisionblox.com/t/working-with-3d-cameras-of-automation-technology-in-cvb/532/16). Using different devices may result in slight changes to the examples.

---

<div class="post-metadata">

**Author:** ![Simon](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/simon/32/847_2.png) [@Simon](https://forum.commonvisionblox.com/u/Simon)\
**Post date:** [January 24, 2023, 9:49am UTC](https://forum.commonvisionblox.com/t/using-chunk-data-in-cvb/1895/2 "2023-01-24T09:49:03Z")

</div>

Here is an example on using _Chunk Data_ in Python. Using the _Chunk Timestamp_ from the Nodemap is valid as this statement is part of the buffer until the stream.wait() stement ends.  
All requirements for enabling _ChunkMode_ on the camera and the driver settings can be performed from code.

```auto
import cvb

devices = cvb.DeviceFactory.discover_from_root(cvb.DiscoverFlags.IgnoreVins)
devices[0].set_parameter("AttachChunk","1")

with cvb.DeviceFactory.open(devices[0].access_token, cvb.AcquisitionStack.GenTL) as device:
    stream = device.stream(cvb.ImageStream)    
    device_nodemap = device.node_maps["Device"]
    
    ChunkModeActive = device_nodemap["Std::ChunkModeActive"]
    ChunkModeActive.value = True       
    TimestampPrevious = 0
    stream.start()
    for i in range(10):        
        image, status, node_maps = stream.wait()        
        # this is valid, well defined until new wait returns
        Chunk_Timestamp = device_nodemap["Std::ChunkTimestamp"]        
        TSP_Diff = Chunk_Timestamp.value - TimestampPrevious
        TimestampPrevious = Chunk_Timestamp.value
        with image:
            print("Acquired image: {0} | Timestamp: {1} | Chunk Timestamp: {2} | Difference to previous Frame: {3}".format(i, image.raw_timestamp, Chunk_Timestamp.value, TSP_Diff))
    stream.abort()   

```

---

<div class="post-metadata">

**Author:** ![Simon](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/simon/32/847_2.png) [@Simon](https://forum.commonvisionblox.com/u/Simon)\
**Post date:** [January 24, 2023, 9:50am UTC](https://forum.commonvisionblox.com/t/using-chunk-data-in-cvb/1895/3 "2023-01-24T09:50:24Z")

</div>

The same example in .NET:

```auto
using System;
using Stemmer.Cvb;
using Stemmer.Cvb.Driver;
using Stemmer.Cvb.GenApi;

namespace CVB_UsingChunkDataFromNodemap
{
  internal class Program
  {
    static void Main(string[] args)
    {
      DiscoveryInformationList discoveryList = DeviceFactory.Discover(DiscoverFlags.IgnoreVins);
      //Enable ChunkMode on Driver
      discoveryList[0].SetParameter("AttachChunk", "1");
      using (Device device = DeviceFactory.Open(discoveryList[0].AccessToken))
      {
        Stream stream = device.Stream;
        NodeMap deviceNodeMap = device.NodeMaps[NodeMapNames.Device];

        //Enable ChunkMode in device NodeMap
        BooleanNode ChunkModeActive = deviceNodeMap["Std::ChunkModeActive"] as BooleanNode;
        ChunkModeActive.Value = true;

        long TimestampPrevious = 0;
        stream.Start();
        for (int i = 0; i < 10; i++)
        {
          using (var image = stream.Wait(out WaitStatus status))
          {
            //this is valid, well defined until new wait returns
            IntegerNode ChunkTimestampNode = deviceNodeMap["Std::ChunkTimestamp"] as IntegerNode;
            long Chunk_Timestamp = ChunkTimestampNode.Value;
            long TSP_Diff = Chunk_Timestamp - TimestampPrevious;
            TimestampPrevious = Chunk_Timestamp;
            Console.WriteLine("FrameID: " + i + " Timestamp: " + image.RawTimestamp + " Chunk Timestamp: " + Chunk_Timestamp + " Difference to previous Frame: " + TSP_Diff);
          }
        }
        stream.Stop();
      }

      Console.ReadLine();
    }
  }
}

```
