C

A simple C example can be found below.

#include <chronoptics/tof.h>
#include <stdio.h>
#include <stdlib.h>

#define CHECK_ERROR(error)                           \
  if (error) {                                       \
    printf("ERROR: %s\n", tof_error_message(error)); \
    tof_error_delete(error);                         \
    return -1;                                       \
  }

int main() {
  tof_error_t error = NULL;

  tof_kea_camera_t kea_cam = tof_kea_camera_new_simple("2020004", &error);
  CHECK_ERROR(error);

  tof_camera_t cam = (tof_camera_t)kea_cam;

  enum tof_frame_type frame_types[] = {TOF_FRAME_TYPE_Z};
  size_t nr_frames = tof_select_streams(cam, frame_types, 1, &error);
  CHECK_ERROR(error);

  tof_camera_start(cam, &error);
  CHECK_ERROR(error);

  tof_data_t *frames = malloc(sizeof(void *) * nr_frames);
  for (size_t n = 0; n < 100; n++) {
    tof_camera_get_frames(cam, frames, nr_frames, &error);
    CHECK_ERROR(error);

    tof_data_t z = frames[0];
    float *z_ptr = (float *)tof_data_data(z, &error);
    (void)z_ptr;

    tof_data_delete(z);
  }

  tof_camera_stop(cam, &error);
  CHECK_ERROR(error);

  tof_kea_camera_delete(kea_cam);
}

As can be seen, manually performing error checking and deletion can be quite tedious. Therefore, we recommend using any of the other supported programming languages.