|
|
|
|
@ -0,0 +1,832 @@
|
|
|
|
|
#include "CameraBaumer.h"
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
using namespace BGAPI2;
|
|
|
|
|
|
|
|
|
|
#define CATCH_EXCEPTION \
|
|
|
|
|
catch (Exceptions::IException& ex)\
|
|
|
|
|
{\
|
|
|
|
|
qCritical() << "ExceptionType: " << QString(ex.GetType()).toLocal8Bit().data() \
|
|
|
|
|
<< " - " __FUNCTION__; \
|
|
|
|
|
qCritical() << "ErrorDescription: " << QString(ex.GetErrorDescription()).toLocal8Bit().data() \
|
|
|
|
|
<< " - " __FUNCTION__; \
|
|
|
|
|
qCritical() << "in function: " << QString(ex.GetFunctionName()).toLocal8Bit().data() \
|
|
|
|
|
<< " - " __FUNCTION__; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define CATCH_EXCEPTION_EX(szOther) \
|
|
|
|
|
catch (Exceptions::IException& ex)\
|
|
|
|
|
{\
|
|
|
|
|
qCritical() << szOther \
|
|
|
|
|
<< " - " __FUNCTION__; \
|
|
|
|
|
qCritical() << "ExceptionType: " << QString(ex.GetType()).toLocal8Bit().data() \
|
|
|
|
|
<< " - " __FUNCTION__; \
|
|
|
|
|
qCritical() << "ErrorDescription: " << QString(ex.GetErrorDescription()).toLocal8Bit().data() \
|
|
|
|
|
<< " - " __FUNCTION__; \
|
|
|
|
|
qCritical() << "in function: " << QString(ex.GetFunctionName()).toLocal8Bit().data() \
|
|
|
|
|
<< " - " __FUNCTION__; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SystemList* CCameraBaumer::s_pSysList = NULL;
|
|
|
|
|
int CCameraBaumer::s_nCount = 0;
|
|
|
|
|
CCameraBaumer::CCameraBaumer(TP_CAMERA_OPTION* pCamOpt, IPoolCallback* pCb)
|
|
|
|
|
: ICameraObject(pCamOpt, pCb)
|
|
|
|
|
, m_pDevice(NULL)
|
|
|
|
|
, m_pStream(NULL)
|
|
|
|
|
, m_pBuffers(NULL)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//rtt comment - will raise exception when the second camera initializing
|
|
|
|
|
//SystemList::CreateInstanceFromPath(pCb->IGetMainPath());
|
|
|
|
|
s_pSysList = SystemList::GetInstance();
|
|
|
|
|
if (NULL != s_pSysList)
|
|
|
|
|
{
|
|
|
|
|
s_pSysList->Refresh();
|
|
|
|
|
++s_nCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_imgProcessor = BGAPI2::ImageProcessor::GetInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCameraBaumer::~CCameraBaumer()
|
|
|
|
|
{
|
|
|
|
|
if (NULL != s_pSysList)
|
|
|
|
|
{
|
|
|
|
|
--s_nCount;
|
|
|
|
|
if (0 == s_nCount)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SystemList::ReleaseInstance();
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
s_pSysList = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BGAPI2CALL FuncEventHandler(void * callBackOwner, Buffer * pBuffer)
|
|
|
|
|
{
|
|
|
|
|
CCameraBaumer* pThis = (CCameraBaumer*)callBackOwner;
|
|
|
|
|
pThis->BufferReady(pBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCameraBaumer::BufferReady(BGAPI2::Buffer * pBuffer)
|
|
|
|
|
{
|
|
|
|
|
//test
|
|
|
|
|
try{
|
|
|
|
|
qDebug() << __FUNCTION__;
|
|
|
|
|
if (pBuffer->GetPixelFormat() == "Mono8")
|
|
|
|
|
{
|
|
|
|
|
//display mono8 image
|
|
|
|
|
}
|
|
|
|
|
else if (std::string(pBuffer->GetPixelFormat()).substr(0, 4) == "Mono")
|
|
|
|
|
{
|
|
|
|
|
//convert mono10,mono12 to mono8 for displaying;
|
|
|
|
|
}
|
|
|
|
|
else if (std::string(pBuffer->GetPixelFormat()).substr(0, 4) == "RGB8")
|
|
|
|
|
{
|
|
|
|
|
//display RGB8 or RGB8Packed
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//convert Bayer to RGB8 for displaying
|
|
|
|
|
BGAPI2::Image* pImage = m_imgProcessor->CreateImage((bo_uint)pBuffer->GetWidth(), (bo_uint)pBuffer->GetHeight(), pBuffer->GetPixelFormat(), pBuffer->GetMemPtr(), pBuffer->GetMemSize());
|
|
|
|
|
BGAPI2::Image* pTranImage = NULL;
|
|
|
|
|
pImage->TransformImage("BGR8", &pTranImage);
|
|
|
|
|
QString strTmp = m_pCamOpt->uniqueName.toUtf8() + ",";
|
|
|
|
|
m_pCameraData = (BYTE*)pTranImage->GetBuffer();
|
|
|
|
|
m_nImageWidth = pBuffer->GetWidth();
|
|
|
|
|
m_nImageHeight = pBuffer->GetHeight();
|
|
|
|
|
//m_funcFreeBuffer = NULL; //myImageCleanupFunc;
|
|
|
|
|
m_nFrameNum = pBuffer->GetFrameID();//++;// = pFrame->frameID + 1;
|
|
|
|
|
m_pCb->IPushCameraData(this);
|
|
|
|
|
pImage->Release();
|
|
|
|
|
pTranImage->Release();
|
|
|
|
|
pBuffer->QueueBuffer();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//BGAPI2::Image* pImage = m_imgProcessor->CreateImage((bo_uint)pBuffer->GetWidth(), (bo_uint)pBuffer->GetHeight(), pBuffer->GetPixelFormat(), pBuffer->GetMemPtr(), pBuffer->GetMemSize());
|
|
|
|
|
//BGAPI2::Image* pTranImage = NULL;
|
|
|
|
|
//pImage->TransformImage("BGR8", &pTranImage);
|
|
|
|
|
QString strTmp = m_pCamOpt->uniqueName.toUtf8() + ",";
|
|
|
|
|
//LOG_SPIDER::LogString(strTmp.toLatin1() + "Baumer image get:", QString::number(QDateTime::currentMSecsSinceEpoch()).toLatin1());
|
|
|
|
|
m_pCameraData = (BYTE*)pBuffer->GetMemPtr();
|
|
|
|
|
m_nImageWidth = pBuffer->GetWidth();
|
|
|
|
|
m_nImageHeight = pBuffer->GetHeight();
|
|
|
|
|
//m_pCameraData = (BYTE*)pTranImage->GetBuffer();
|
|
|
|
|
//m_nImageWidth = pBuffer->GetWidth();
|
|
|
|
|
//m_nImageHeight = pBuffer->GetHeight();
|
|
|
|
|
//m_funcFreeBuffer = NULL; //myImageCleanupFunc;
|
|
|
|
|
m_nFrameNum = pBuffer->GetFrameID();//++;// = pFrame->frameID + 1;
|
|
|
|
|
m_pCb->IPushCameraData(this);
|
|
|
|
|
//pImage->Release();
|
|
|
|
|
//pTranImage->Release();
|
|
|
|
|
pBuffer->QueueBuffer();
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CCameraBaumer::IOpenCamera()
|
|
|
|
|
{
|
|
|
|
|
qWarning("start open baumer camera...");
|
|
|
|
|
if (NULL == s_pSysList)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
QStringList sKeys = m_pCamOpt->uniqueName.split(' ');
|
|
|
|
|
if (sKeys.size() < 2 || sKeys[0].toLower() != "baumer")
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
QString szSerial = sKeys[1];
|
|
|
|
|
#ifdef _USE_CAMERA_SERIAL_ENCRYPTO
|
|
|
|
|
szSerial = getSerial(sKeys[1]);
|
|
|
|
|
#endif
|
|
|
|
|
for (SystemList::iterator it = s_pSysList->begin(); it != s_pSysList->end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (!openSystem(it->second))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
InterfaceList* intfList = getSystemInterfaces(it->second);// it->second->GetInterfaces();
|
|
|
|
|
if (NULL != intfList)
|
|
|
|
|
{
|
|
|
|
|
for (InterfaceList::iterator itf = intfList->begin(); itf != intfList->end(); ++itf)
|
|
|
|
|
{
|
|
|
|
|
if (!openInterface(itf->second))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
DeviceList* deviceList = getDevices(itf->second);
|
|
|
|
|
if (NULL != deviceList)
|
|
|
|
|
{
|
|
|
|
|
m_pDevice = openDeviceBySerialNumber(deviceList, szSerial);
|
|
|
|
|
if (NULL != m_pDevice)
|
|
|
|
|
{
|
|
|
|
|
m_bOpened = true;
|
|
|
|
|
qDebug() << "Baumer camera(" << szSerial << ") open successed."
|
|
|
|
|
<< " - " << __FUNCTION__;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closeInterface(itf->second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closeSystem(it->second);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QString> CCameraBaumer::IEnumAvailableCameras()
|
|
|
|
|
{
|
|
|
|
|
QList<QString> ret;
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
if (NULL == s_pSysList){
|
|
|
|
|
s_pSysList = SystemList::GetInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NULL != s_pSysList)
|
|
|
|
|
{
|
|
|
|
|
for (SystemList::iterator it = s_pSysList->begin(); it != s_pSysList->end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (!openSystem(it->second)) continue;
|
|
|
|
|
|
|
|
|
|
InterfaceList* intfList = getSystemInterfaces(it->second);// it->second->GetInterfaces();
|
|
|
|
|
if (NULL != intfList){
|
|
|
|
|
for (InterfaceList::iterator itf = intfList->begin(); itf != intfList->end(); ++itf)
|
|
|
|
|
{
|
|
|
|
|
if (!openInterface(itf->second)) continue;
|
|
|
|
|
|
|
|
|
|
DeviceList* deviceList = getDevices(itf->second);
|
|
|
|
|
if (NULL != deviceList){
|
|
|
|
|
for (DeviceList::iterator itd = deviceList->begin(); itd != deviceList->end(); ++itd)
|
|
|
|
|
{
|
|
|
|
|
QString strSerial = QString("%1 %2").arg("baumer").arg(itd->second->GetSerialNumber().get());
|
|
|
|
|
ret.append(strSerial);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closeInterface(itf->second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closeSystem(it->second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCameraBaumer::ICloseCamera()
|
|
|
|
|
{
|
|
|
|
|
if (NULL != m_pDevice)
|
|
|
|
|
{
|
|
|
|
|
clearDeviceDataStream(m_pDevice);
|
|
|
|
|
closeDevice(m_pDevice);
|
|
|
|
|
m_pDevice = NULL;
|
|
|
|
|
}
|
|
|
|
|
m_bOpened = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CCameraBaumer::IStartCamera()
|
|
|
|
|
{
|
|
|
|
|
qDebug() << __FUNCTION__;
|
|
|
|
|
|
|
|
|
|
if (!m_bOpened || NULL == m_pDevice)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
//if (m_bHasStarted) return 1;
|
|
|
|
|
|
|
|
|
|
//if (!m_bHasStarted || m_oldTriggerMode != m_newTriggerMode)
|
|
|
|
|
if (m_oldTriggerMode != m_newTriggerMode)
|
|
|
|
|
{
|
|
|
|
|
bool bSet = false;
|
|
|
|
|
switch (m_newTriggerMode)
|
|
|
|
|
{
|
|
|
|
|
case DEV_TRIGGER_MODE_OUT:
|
|
|
|
|
bSet = setDeviceOutTrigger(m_pDevice);
|
|
|
|
|
break;
|
|
|
|
|
case DEV_TRIGGER_MODE_AUTO:
|
|
|
|
|
case DEV_TRIGGER_MODE_FIXED_AUTO:
|
|
|
|
|
bSet = setDeviceAutoTrigger(m_pDevice);
|
|
|
|
|
if (DEV_TRIGGER_MODE_FIXED_AUTO == m_newTriggerMode)
|
|
|
|
|
{
|
|
|
|
|
m_nFrameNum = 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DEV_TRIGGER_MODE_SOFT:
|
|
|
|
|
bSet = setDeviceSoftTrigger(m_pDevice);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
bSet = stopDeviceDataStream(m_pDevice);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
m_oldTriggerMode = m_newTriggerMode;
|
|
|
|
|
m_bStarted = bSet;
|
|
|
|
|
}
|
|
|
|
|
++m_nStartCount;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCameraBaumer::IStopCamera()
|
|
|
|
|
{
|
|
|
|
|
if (NULL != m_pDevice)
|
|
|
|
|
{
|
|
|
|
|
stopDeviceDataStream(m_pDevice);
|
|
|
|
|
}
|
|
|
|
|
m_bStarted = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCameraBaumer::InitProperty()
|
|
|
|
|
{
|
|
|
|
|
if (m_pDevice != nullptr&&m_pCamOpt != nullptr)
|
|
|
|
|
{
|
|
|
|
|
long iShutter, iMaxShutter, iMinShutter;
|
|
|
|
|
//set exposure
|
|
|
|
|
{
|
|
|
|
|
if (m_pDevice->GetRemoteNodeList()->GetNodePresent("ExposureTime"))
|
|
|
|
|
{
|
|
|
|
|
m_pDevice->GetRemoteNode("ExposureTime")->SetDouble(m_pCamOpt->exposure);
|
|
|
|
|
}
|
|
|
|
|
else if (m_pDevice->GetRemoteNodeList()->GetNodePresent("ExposureTimeAbs"))
|
|
|
|
|
{
|
|
|
|
|
//iShutter = (long)m_pDevice->GetRemoteNode("ExposureTimeAbs")->GetDouble();
|
|
|
|
|
iMinShutter = (long)m_pDevice->GetRemoteNode("ExposureTimeAbs")->GetDoubleMin();
|
|
|
|
|
iMaxShutter = (long)m_pDevice->GetRemoteNode("ExposureTimeAbs")->GetDoubleMax();
|
|
|
|
|
if (m_pCamOpt->exposure < iMinShutter || m_pCamOpt->exposure > iMaxShutter) {
|
|
|
|
|
qWarning() << QString("Invalid exposure time value:%1.").arg(m_pCamOpt->exposure)
|
|
|
|
|
<< " - " << __FUNCTION__;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_pDevice->GetRemoteNode("ExposureTimeAbs")->SetDouble(m_pCamOpt->exposure);
|
|
|
|
|
|
|
|
|
|
qDebug() << QString("Set exposure time value:%1 successfully.").arg(m_pCamOpt->exposure)
|
|
|
|
|
<< " - " << __FUNCTION__;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CCameraBaumer::ISendSoftTrigger()
|
|
|
|
|
{
|
|
|
|
|
if (NULL == m_pDevice)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_pDevice->GetRemoteNode("TriggerSoftware")->Execute();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emTpColorFormat CCameraBaumer::colorFormat(const QString& pixelFormat, int& nPixelSize)
|
|
|
|
|
{
|
|
|
|
|
if ("YUV422Packed" == pixelFormat ||
|
|
|
|
|
"Mono8" == pixelFormat)
|
|
|
|
|
{
|
|
|
|
|
nPixelSize = 8;
|
|
|
|
|
return TP_COLOR_Y800;
|
|
|
|
|
}
|
|
|
|
|
else if ("BayerRG12" == pixelFormat || "YUV444Packed" == pixelFormat)
|
|
|
|
|
{
|
|
|
|
|
nPixelSize = 12;
|
|
|
|
|
return TP_COLOR_Y800;
|
|
|
|
|
}
|
|
|
|
|
else if ("BayerRG8" == pixelFormat)
|
|
|
|
|
{
|
|
|
|
|
//nPixelSize = 8;
|
|
|
|
|
//return TP_COLOR_Y800;
|
|
|
|
|
|
|
|
|
|
nPixelSize = 24;
|
|
|
|
|
return TP_COLOR_RGB24;
|
|
|
|
|
}
|
|
|
|
|
else if ("RGB8Packed" == pixelFormat || "BGR8Packed" == pixelFormat || "BayerRGB8Packed" == pixelFormat)
|
|
|
|
|
{
|
|
|
|
|
nPixelSize = 24;
|
|
|
|
|
return TP_COLOR_RGB24;
|
|
|
|
|
}
|
|
|
|
|
else if ("YUV411Packed" == pixelFormat)
|
|
|
|
|
{
|
|
|
|
|
nPixelSize = 6;
|
|
|
|
|
return TP_COLOR_Y800;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nPixelSize = 0;
|
|
|
|
|
return TP_COLOR_NONE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::createStreamBuffers(BGAPI2::DataStream* pStream, int nBuffers/* = 8*/)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BufferList* bufferList = pStream->GetBufferList();
|
|
|
|
|
// 4 buffers using internal buffer mode
|
|
|
|
|
for (int i = 0; i < nBuffers; i++)
|
|
|
|
|
{
|
|
|
|
|
Buffer* pBuffer = new BGAPI2::Buffer();
|
|
|
|
|
if (NULL == pBuffer)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
bufferList->Add(pBuffer);
|
|
|
|
|
pBuffer->QueueBuffer();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool CCameraBaumer::deleteStreamBuffers(BGAPI2::DataStream* pStream)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BufferList* bufferList = pStream->GetBufferList();
|
|
|
|
|
if (NULL == bufferList)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 4 buffers using internal buffer mode
|
|
|
|
|
for (BufferList::iterator it = bufferList->begin(); it != bufferList->end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
Buffer* pBuffer = new BGAPI2::Buffer();
|
|
|
|
|
if (NULL == pBuffer)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
bufferList->Add(pBuffer);
|
|
|
|
|
pBuffer->QueueBuffer();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::openSystem(BGAPI2::System* pSystem)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (pSystem->IsOpen())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
pSystem->Open();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool CCameraBaumer::closeSystem(BGAPI2::System* pSystem)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
InterfaceList* CCameraBaumer::getSystemInterfaces(BGAPI2::System* pSystem)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
InterfaceList* intfList = pSystem->GetInterfaces();
|
|
|
|
|
if (NULL == intfList)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
intfList->Refresh(100);
|
|
|
|
|
return intfList;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::openInterface(BGAPI2::Interface* intf)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (intf->IsOpen())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
intf->Open();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool CCameraBaumer::closeInterface(BGAPI2::Interface* intf)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceList* CCameraBaumer::getDevices(BGAPI2::Interface* pInterface)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DeviceList* deviceList = NULL;
|
|
|
|
|
deviceList = pInterface->GetDevices();
|
|
|
|
|
int nCount = deviceList->size();
|
|
|
|
|
if (NULL == deviceList)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
deviceList->Refresh(100);
|
|
|
|
|
return deviceList;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Device* CCameraBaumer::openDeviceBySerialNumber(BGAPI2::DeviceList* devices, const QString& serialNumber)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
for (DeviceList::iterator itd = devices->begin(); itd != devices->end(); ++itd)
|
|
|
|
|
{
|
|
|
|
|
if (serialNumber == itd->second->GetSerialNumber())
|
|
|
|
|
{
|
|
|
|
|
if (!openDevice(itd->second))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!setDeviceProperty(itd->second) || 0 == setDeviceDataStream(itd->second))
|
|
|
|
|
{
|
|
|
|
|
closeDevice(itd->second);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return (*devices)[itd->first];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::openDevice(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (pDevice->IsOpen())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
pDevice->Open();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::closeDevice(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!pDevice->IsOpen())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
pDevice->Close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::setDeviceProperty(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_nColorFormat = colorFormat(QString(pDevice->GetRemoteNode("PixelFormat")->GetString()), m_nBitsPerPixel);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CCameraBaumer::setDeviceDataStream(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
int nStreams = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DataStreamList* streamList = pDevice->GetDataStreams();
|
|
|
|
|
streamList->Refresh();
|
|
|
|
|
for (DataStreamList::iterator its = streamList->begin(); its != streamList->end(); ++its)
|
|
|
|
|
{
|
|
|
|
|
if (!openDataStream(its->second))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!createStreamBuffers(its->second))
|
|
|
|
|
{
|
|
|
|
|
closeDataStream(its->second);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
++nStreams;
|
|
|
|
|
its->second->RegisterNewBufferEventHandler(this, (Events::NewBufferEventHandler)&FuncEventHandler);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return nStreams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CCameraBaumer::clearDeviceDataStream(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
int nStreams = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DataStreamList* streamList = pDevice->GetDataStreams();
|
|
|
|
|
streamList->Refresh();
|
|
|
|
|
for (DataStreamList::iterator its = streamList->begin(); its != streamList->end(); ++its)
|
|
|
|
|
{
|
|
|
|
|
if (!closeDataStream(its->second))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
deleteStreamBuffers(its->second);
|
|
|
|
|
++nStreams;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return nStreams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::openDataStream(BGAPI2::DataStream* pStream)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (pStream->IsOpen())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
pStream->Open();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::closeDataStream(BGAPI2::DataStream* pStream)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!pStream->IsOpen())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
pStream->Close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::startDeviceDataStream(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DataStreamList* pStreamList = pDevice->GetDataStreams();
|
|
|
|
|
pStreamList->Refresh();
|
|
|
|
|
for (DataStreamList::iterator it = pStreamList->begin(); it != pStreamList->end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (!openDataStream(it->second))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!it->second->GetIsGrabbing())
|
|
|
|
|
{
|
|
|
|
|
it->second->StartAcquisitionContinuous();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool CCameraBaumer::stopDeviceDataStream(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DataStreamList* pStreamList = pDevice->GetDataStreams();
|
|
|
|
|
pStreamList->Refresh();
|
|
|
|
|
for (DataStreamList::iterator it = pStreamList->begin(); it != pStreamList->end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (!openDataStream(it->second))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (it->second->GetIsGrabbing())
|
|
|
|
|
{
|
|
|
|
|
it->second->StopAcquisition();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::setDeviceOutTrigger(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (pDevice->GetRemoteNodeList()->GetNodePresent("AcquisitionAbort"))
|
|
|
|
|
{
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionAbort")->Execute();
|
|
|
|
|
}
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionStop")->Execute();
|
|
|
|
|
//DataStreamList* pStreamList = pDevice->GetDataStreams();
|
|
|
|
|
//pStreamList->Refresh();
|
|
|
|
|
//for (DataStreamList::iterator it = pStreamList->begin(); it != pStreamList->end(); ++it)
|
|
|
|
|
//{
|
|
|
|
|
// if (!openDataStream(it->second))
|
|
|
|
|
// {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// if (!it->second->GetIsGrabbing())
|
|
|
|
|
// {
|
|
|
|
|
// it->second->StartAcquisitionContinuous();
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
pDevice->GetRemoteNode("TriggerMode")->SetString("On");
|
|
|
|
|
pDevice->GetRemoteNode("TriggerSource")->SetString("Line0");
|
|
|
|
|
if (!startDeviceDataStream(pDevice))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionStart")->Execute();
|
|
|
|
|
qDebug() << "Set out trigger successful."
|
|
|
|
|
<< " - " << __FUNCTION__;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool CCameraBaumer::setDeviceSoftTrigger(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (pDevice->GetRemoteNodeList()->GetNodePresent("AcquisitionAbort"))
|
|
|
|
|
{
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionAbort")->Execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionStop")->Execute();
|
|
|
|
|
pDevice->GetRemoteNode("TriggerMode")->SetString("On");
|
|
|
|
|
|
|
|
|
|
if (pDevice->GetRemoteNode("TriggerSource")->GetEnumNodeList()->GetNodePresent("SoftwareTrigger"))
|
|
|
|
|
{
|
|
|
|
|
pDevice->GetRemoteNode("TriggerSource")->SetString("SoftwareTrigger");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pDevice->GetRemoteNode("TriggerSource")->SetString("Software");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!startDeviceDataStream(pDevice))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionStart")->Execute();
|
|
|
|
|
qDebug() << "Set soft trigger successful."
|
|
|
|
|
<< " - " << __FUNCTION__;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool CCameraBaumer::setDeviceAutoTrigger(BGAPI2::Device* pDevice)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (pDevice->GetRemoteNodeList()->GetNodePresent("AcquisitionAbort"))
|
|
|
|
|
{
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionAbort")->Execute();
|
|
|
|
|
}
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionStop")->Execute();
|
|
|
|
|
pDevice->GetRemoteNode("TriggerMode")->SetString("Off");
|
|
|
|
|
pDevice->GetRemoteNode("TriggerSource")->SetString("Line0");
|
|
|
|
|
if (!startDeviceDataStream(pDevice))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
pDevice->GetRemoteNode("AcquisitionStart")->Execute();
|
|
|
|
|
qDebug() << "Set auto trigger successful."
|
|
|
|
|
<< " - " << __FUNCTION__;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCameraBaumer::ISnapCamera()
|
|
|
|
|
{
|
|
|
|
|
if (!m_pDevice)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!setDeviceSoftTrigger(m_pDevice))
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
|
|
if (DEV_TRIGGER_MODE_OUT == m_oldTriggerMode)
|
|
|
|
|
{
|
|
|
|
|
ISendSoftTrigger();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::ISetProperty(TP_CAMERA_PROPERTY* pCamProperty)
|
|
|
|
|
{
|
|
|
|
|
if (!pCamProperty)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
long iShutter, iMaxShutter, iMinShutter;
|
|
|
|
|
if (pCamProperty->property == TP_CAM_PROPERTY_EXPOSURE)
|
|
|
|
|
{
|
|
|
|
|
if (m_pDevice->GetRemoteNodeList()->GetNodePresent("ExposureTime"))
|
|
|
|
|
{
|
|
|
|
|
m_pDevice->GetRemoteNode("ExposureTime")->SetDouble(pCamProperty->value);
|
|
|
|
|
}
|
|
|
|
|
else if (m_pDevice->GetRemoteNodeList()->GetNodePresent("ExposureTimeAbs"))
|
|
|
|
|
{
|
|
|
|
|
//iShutter = (long)m_pDevice->GetRemoteNode("ExposureTimeAbs")->GetDouble();
|
|
|
|
|
iMinShutter = (long)m_pDevice->GetRemoteNode("ExposureTimeAbs")->GetDoubleMin();
|
|
|
|
|
iMaxShutter = (long)m_pDevice->GetRemoteNode("ExposureTimeAbs")->GetDoubleMax();
|
|
|
|
|
if (pCamProperty->value < iMinShutter || pCamProperty->value > iMaxShutter){
|
|
|
|
|
qWarning() << QString("Invalid exposure time value:%1.").arg(pCamProperty->value)
|
|
|
|
|
<< " - " << __FUNCTION__;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
m_pDevice->GetRemoteNode("ExposureTimeAbs")->SetDouble(pCamProperty->value);
|
|
|
|
|
|
|
|
|
|
qDebug() << QString("Set exposure time value:%1 successfully.").arg(pCamProperty->value)
|
|
|
|
|
<< " - " << __FUNCTION__;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CATCH_EXCEPTION
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCameraBaumer::IGetProperty(TP_CAMERA_PROPERTY* pCamProperty)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|