Working with 3D-Cameras of Automation Technology in CVB

USING CHUNK DATA MODE

The AT sensors features a Chunk Data mode for providing additional information to the acquired image data. The ChunkData generated by the camera have the following format:

  • ChunkImage
  • 1…N x ChunkAcqInfo
  • ChunkImageInfo

Depending on camera mode (image or 3D) the ChunkData block („ChunkAcqInfo“) can
be sent as follows:

  • In image mode, the camera can send only one ChunkAcqInfo block per image frame.
  • In 3D mode, the camera can send one ChunkAcqInfo block either per 3D frame (“OneChunkPerFrame”) or per 3D profile (“OneChunkPerProfile”)

The „ChunkImageInfo“ is the last ChunkData sent by the camera and contains following
data:

  • Number of valid rows in ChunkImage
  • Number of valid ChunkAcqInfo blocks
  • Flags identifying the current frame as „Start“ or „Stop“ and the buffer status in AutoStart mode

The ChunkAcqInfo block consists of totally 32 bytes containing following data:

  • 64 bit timestamp
  • 32 bit frame counter
  • 32 bit trigger coordinate
  • 8 bit Trigger status
  • 32 bit I/O Status
  • 72 bit AOI information

The data of timestamp, frame counter, trigger coordinate, trigger status and I/O status are assigned at the start of every image integration.
When ChunkMode is disabled, the camera uses the “regular“ GEV image protocol, in which the optional transfer of frames with variable height and payload is supported.
Furthermore, when ChunkMode is enabled, the camera sends the full payload, even if the ChunkImage or ChunkAcqInfo blocks contain partially valid data. The number of valid ChunkImage rows and ChunkAcqInfo blocks can be read from ChunkImageInfo. For example, when in Start/Stop mode with instant frame transmission, the camera stops the frame acquisition as soon as the stop trigger occurs and transfers the complete contents of internal image buffer. Using the ChunkImageInfo data block, it is possible to detect how many image rows and ChunkAcqInfo blocks are valid in the payload buffer. The tag of ChunkData has big endian byte order. The data of ChunkData has little endian byte order. An endian converter for ChunkData is not supported.

Payload Layout
Percent|

Code example

All credit goes to @parsd for this post.

using (var device = DeviceFactory.Open("GenICam.vin"))
{
  var nodemap = device.NodeMaps[NodeMapNames.Device];
  var chunkModeActive = nodemap["ChunkModeActive"] as BooleanNode;
  chunkModeActive.Value = true;

  var stream = device.Stream;
  stream.Start();
  try
  {
    stream.Wait();
    var deviceImage = device.DeviceImage;

    var chunks = GevChunkParser.Parse(deviceImage);
    var info = DereferenceAcqInfoOn(deviceImage, chunks.First(chunk => chunk.ID == ATC5AcqInfoChunk.ID));

    Console.WriteLine($"FrameCount: {info.FrameCount}");
  }
  finally
  {
    stream.Stop();
  }
}

With this helper method and struct:

private static unsafe ATC5AcqInfoChunk DereferenceAcqInfoOn(DeviceImage image, GevChunk chunk)
{
  Debug.Assert(chunk.ID == ATC5AcqInfoChunk.ID);
  Debug.Assert(chunk.Length >= sizeof(ATC5AcqInfoChunk));

  var chunkPtr = new IntPtr(image.GetBufferBasePtr().ToInt64() + chunk.Offset);
  return *(ATC5AcqInfoChunk*)chunkPtr;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ATC5AcqInfoChunk
{
  public const uint ID = 0x66669999;

  public uint TimeStampLow;
  public uint TimeStampHigh;
  public uint FrameCount;
  public int TriggerCoordinate;
  public byte TriggerStatus;
  public ushort DAC;
  public ushort ADC;
  public byte IntIdX;
  public byte AoiIdX;
  public ushort AoiYs;
  public ushort AoiDy;
  public ushort AoiXs;
  public ushort AoiThreshold;
  public byte AOIAlgorithm;
}

For this to work you need these three new classes @parsd put on github:

2 Likes