Please enable JavaScript to view this site.

IDS peak 2.10.0 / uEye+ firmware 3.34

IDS Peak comfortSDK, genericSDK, IPL, and AFL developer manuals are external documents. Please contact us if you need them.

Creating buffers yourself and announcing them to the IDS peak API

1.Query the PayloadSize (required size in bytes) for a buffer.

2.Query for the minimum number of buffers required.

3.Allocate the buffer yourself.

4.Announce the buffer to the system ("AnnounceBuffer").

5.Add the buffer to the "Buffer Pool" ("QueueBuffer").

comfortC

peak_status status = PEAK_STATUS_SUCCESS;
 
size_t requiredBufferSize = 0;
status = peak_Acquisition_Buffer_GetRequiredSize(hCam, &requiredBufferSize);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
 
size_t requiredBufferCount = 0;
peak_Acquisition_Buffer_GetRequiredCount(hCam, &requiredBufferCount);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
 
for(size_t count = 0; count < requiredBufferCount; count++)
{
  uint8_t* rawBuffer = (uint8_t*) malloc(requiredBufferSize * sizeof(uint8_t);
  status = peak_Acquisition_Buffer_Announce(hCam, rawBuffer, requiredBufferSize, NULL);
  if (PEAK_ERROR(status)) { /* Error handling ... */ }
}

genericC++

if (dataStream)
{
  int64_t payloadSize = nodemapRemoteDevice->FindNode<peak::core::nodes::IntegerNode>("PayloadSize")->Value();
 
  // Get number of minimum required buffers
  int numBuffersMinRequired = dataStream->NumBuffersAnnouncedMinRequired();
 
  // Alloc buffers
  for (size_t count = 0; count < numBuffersMinRequired ; count++)
  {
      uint8_t* rawBuffer = new uint8_t[payloadSize];
      auto buffer = dataStream->AnnounceBuffer(rawBuffer, static_cast<size_t>(payloadSize), nullptr, nullptr);
      dataStream->QueueBuffer(buffer);
  }
}

Removing buffers from the buffer pool after the end of image acquisition and deleting them yourself

1.Revoke the buffer from the "Buffer Pool" ("RevokeBuffer").

2.Delete the raw buffer you created yourself.

comfortC

peak_status status = PEAK_STATUS_SUCCESS;
status = peak_Acquisition_Buffer_RevokeAll(hCam);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
// you still have to free the buffers you allocated with malloc

genericC++

if (dataStream)
{
  dataStream->Flush(peak::core::DataStreamFlushMode::DiscardAll);
 
  for (const auto& buffer : m_dataStream->AnnouncedBuffers())
  {
      uint8_t* rawBuffer = static_cast<uint8_t*>(buffer->BasePtr());
      dataStream->RevokeBuffer(buffer);
      delete rawBuffer;
  }
}

Other solution: Create the buffer yourself, announce it to the IDS peak API and pass the function to delete it.

There is another solution. You can pass the function to delete the self-allocated buffer as lambda. This is a modern construct in C++.

1.Query the PayloadSize (required size in bytes) for a buffer.

2.Query for the minimum number of buffers required.

3.Allocate the buffer yourself.

4.Announce the buffer to the system ("AnnounceBuffer").

5.Pass the delete function as "lambda".

6.Add the buffer to the "Buffer Pool" ("QueueBuffer").

genericC++

if (dataStream)
{
  int64_t payloadSize = nodemapRemoteDevice->FindNode<peak::core::nodes::IntegerNode>("PayloadSize")->Value();
 
  // Get number of minimum required buffers
  int numBuffersMinRequired = dataStream->NumBuffersAnnouncedMinRequired();
 
  // Alloc buffers
  for (size_t count = 0; count < numBuffersMinRequired ; count++)
  {
      uint8_t* rawBuffer = new uint8_t[payloadSize];
      auto buffer = datastream->AnnounceBuffer(rawBuffer, static_cast<size_t>(payloadSize), nullptr,
      [](void* buffer, void* userPtr)
      {
          delete[] static_cast<uint8_t*>(buffer);
      });
 
      dataStream->QueueBuffer(buffer);
  }
}

Procedure: Remove and release buffers from the buffer pool at the end of image acquisition

1.Revoke the buffer from the "Buffer Pool" ("RevokeBuffer")

2.The delete function specified above is automatically called by RevokeBuffer and deletes the self-created buffer.

genericC++

if (dataStream)
{
  dataStream->Flush(peak::core::DataStreamFlushMode::DiscardAll);
 
  for (const auto& buffer : dataStream->AnnouncedBuffers())
  {
      dataStream->RevokeBuffer(buffer);
  }
}

Complete example: Before starting image acquisition, all existing buffers are deleted, released and new buffers are created

1.Specify all settings that affect the image size (Setting ROI (region of interest)).

2.Release the buffers that are already present (see above).

3.Create new buffers.

© 2024 IDS Imaging Development Systems GmbH