Skip to content
Dan Parnham edited this page May 17, 2016 · 2 revisions

C API

Although libpsinc is primarily a C++ library, v0.1 introduces a set of C wrapper functions for both the driver and emergent Image<> classes. Although it does not contain the full functionality of the C++ API it is simpler to use from other languages, see src/psinc-cs for an example C# interop library.

Please refer to the header file for more information.

Example

#include <unistd.h>
#include "psinc.h"

int main(int argc, char *argv[])
{
    psinc_enable_logging();

    // Allocate a greyscale image to be used as a buffer for image grabbing.
    emg_image *image = emg_image_create(false);

    // Construct an instance of camera which is responsible for a single physical
    // camera. Create multiple instances to handle multiple cameras within the same
    // application.
    psinc_camera *camera = psinc_camera_create();

    // Will attempt to connect to any valid camera regardless of serial number or ID.
    psinc_camera_initialise(camera, "");

    // Wait until a camera has been connected.
    while (!psinc_camera_connected(camera))
    {
        sleep(1);
    }

    // Set an imaging chip specific feature.
    psinc_camera_set_feature(camera, "coarse_integration_time", 42);

    // Grab a single image from the camera. The C API only supports synchronous
    // grabbing even though the underlying C++ grab is asynchronous.
    if (psinc_camera_grab(camera, image) == PSINC_OK)
    {
        // Save the image to disk.
        emg_image_save(image, "grab.png", false);
    }

    // Free any allocated memory
    psinc_camera_delete(camera);
    emg_image_delete(image);

    return 0;
}
Clone this wiki locally