#include "baslercamera.h"
#include <algorithm> // for std::find_if
#include <iostream>
#include <thread>

Pylon::DeviceInfoList_t BaslerCamera::devices;

BaslerCamera::BaslerCamera()
{

}


BaslerCamera::~BaslerCamera()
{
	Pylon::PylonTerminate();
}


int BaslerCamera::Enumerate()
{
	int n_basler_cam = 0;

	// Before using any pylon methods, the pylon runtime must be initialized.
	Pylon::PylonInitialize();
	try
	{
		// Get the transport layer factory.
		Pylon::CTlFactory& tlFactory = Pylon::CTlFactory::GetInstance();

		// Get all attached devices and exit application if no device is found.
		if (tlFactory.EnumerateDevices(devices) == 0)
		{
			return 0;
		}
		n_basler_cam = min(devices.size(), c_maxCamerasToUse);
	}
	catch (const Pylon::GenericException& e)
	{
		// Error handling
		cerr << "An exception occurred." << endl
			<< e.GetDescription() << endl;
	}
	return n_basler_cam;
}