Commit 385b9ce7 authored by Yuelong Yu's avatar Yuelong Yu
Browse files

bug fix on data acquisiton

parent 1c1be666
......@@ -43,9 +43,15 @@ namespace SLLoaderNS
bool OpenLib(string& libpath)
{
m_handle = dlopen(libpath.c_str(),RTLD_LAZY|RTLD_NOW);
//cout<<"openlib"<<libpath<<m_handle<<endl;
if(!m_handle)
{
cerr<<dlerror()<<endl;
return false;
}
return true;
}
......@@ -59,6 +65,7 @@ namespace SLLoaderNS
shared_ptr<T> GetInstance()
{
//cout<<"get instance"<<m_handle<<endl;
using allocClass = T *(*)();
using deleteClass = void (*)(T *);
......@@ -71,7 +78,6 @@ namespace SLLoaderNS
if (!allocFunc || !deleteFunc)
{
CloseLib();
std::cerr << dlerror() << std::endl;
}
return std::shared_ptr<T>(
......
......@@ -41,25 +41,22 @@ extern "C"
}
}
namespace PcoNS
{
{
int PcoCLHSImpl::OpenCamera()
{
int nRet = 0;
unsigned short ushCameraType = 0;
unsigned int unSerialNumber = 0;
// init pco camera object
m_sptrCamera = shared_ptr<CPco_com>(new CPco_com_clhs());
// open camera;
nRet = m_sptrCamera->Open_Cam(0);
if(nRet != OK)
{
return OPEN_ERROR;
}
// check camera type
nRet = m_sptrCamera->PCO_GetCameraType(&ushCameraType,&unSerialNumber);
......@@ -79,7 +76,7 @@ namespace PcoNS
m_uptrPcoCamera = uptrCameraFactory->CreateProduct();
uptrCameraFactory.reset();
if(!(m_uptrPcoCamera->SetCamera(m_sptrCamera)))
{
m_sptrCamera->Close_Cam();
......@@ -94,36 +91,34 @@ namespace PcoNS
}
return OK;
}
int PcoCLHSImpl::CloseCamera()
{
m_uptrPcoCamera.reset();
return OK;
}
const string PcoCLHSImpl::GetModuleName()
{
return m_uptrPcoCamera->GetModuleName();
}
int PcoCLHSImpl::GetCameraMaxSize(int& x, int& y)
{
x=0;
y=0;
return DOES_NOT_SUPPORT;
return m_uptrPcoCamera->GetCameraMaxSize(x,y);
}
int PcoCLHSImpl::GetRecordingState(short& shRecordingState)
{
return m_uptrPcoCamera->GetRecordingState(shRecordingState);
}
int PcoCLHSImpl::SetRecordingState(short shRecordingState)
{
return m_uptrPcoCamera->SetRecordingState(shRecordingState);
}
int PcoCLHSImpl::GetTemperature(short& shCCDTemperature,
short& shCameraTemperature,
short& shPowerDeviceTemperature)
......@@ -132,12 +127,12 @@ namespace PcoNS
shCameraTemperature,
shPowerDeviceTemperature);
}
int PcoCLHSImpl::GetCoolingSetpointTemperature(short& shTemperature)
{
return m_uptrPcoCamera->GetCoolingSetpointTemperature(shTemperature);
}
int PcoCLHSImpl::SetCoolingSetpointTemperature(short shTemperature)
{
return m_uptrPcoCamera->SetCoolingSetpointTemperature(shTemperature);
......@@ -147,7 +142,7 @@ namespace PcoNS
{
return m_uptrPcoCamera->GetBinning(shBinHorz,shBinVert);
}
int PcoCLHSImpl::SetBinning(short shBinHorz,short shBinVert)
{
return m_uptrPcoCamera->SetBinning(shBinHorz,shBinVert);
......@@ -157,47 +152,47 @@ namespace PcoNS
{
return m_uptrPcoCamera->GetROI(shX0,shY0,shX1,shY1);
}
int PcoCLHSImpl::SetROI(short shX0,short shY0,short shX1,short shY1)
{
return m_uptrPcoCamera->SetROI(shX0,shY0,shX1,shY1);
}
int PcoCLHSImpl::GetROIStep(short& shXstep,short& shYstep)
{
return m_uptrPcoCamera->GetROIStep(shXstep,shYstep);
}
int PcoCLHSImpl::GetLUT(short& shIdentifier,short& shParam)
{
return m_uptrPcoCamera->GetLUT(shIdentifier,shParam);
}
int PcoCLHSImpl::SetLUT(short shIdentifier,short shParam)
{
return m_uptrPcoCamera->SetLUT(shIdentifier,shParam);
}
int PcoCLHSImpl::GetSizes(short& shX,short& shY)
{
return m_uptrPcoCamera->GetSizes(shX,shY);
}
int PcoCLHSImpl::GetTriggerMode(short& shTriggerMode)
{
return m_uptrPcoCamera->GetTriggerMode(shTriggerMode);
}
int PcoCLHSImpl::SetTriggerMode(short shTriggerMode)
{
return m_uptrPcoCamera->SetTriggerMode(shTriggerMode);
}
int PcoCLHSImpl::GetPixelRate(int& nPixelRate)
{
return m_uptrPcoCamera->GetPixelRate(nPixelRate);
}
int PcoCLHSImpl::SetPixelRate(int nPixelRate)
{
return m_uptrPcoCamera->SetPixelRate(nPixelRate);
......@@ -207,7 +202,7 @@ namespace PcoNS
{
return m_uptrPcoCamera->GetADCOperation(shADCNum);
}
int PcoCLHSImpl::SetADCOperation(short shADCNum)
{
return m_uptrPcoCamera->SetADCOperation(shADCNum);
......@@ -217,7 +212,7 @@ namespace PcoNS
{
return m_uptrPcoCamera->GetTimestampMode(shMode);
}
int PcoCLHSImpl::SetTimestampMode(short shMode)
{
return m_uptrPcoCamera->SetTimestampMode(shMode);
......@@ -227,17 +222,17 @@ namespace PcoNS
{
return m_uptrPcoCamera->GetExposureTime(dExpTime);
}
int PcoCLHSImpl::SetExposureTime(double dExpTime)
{
return m_uptrPcoCamera->SetExposureTime(dExpTime);
}
int PcoCLHSImpl::GetDelayTime(double& dDelayTime)
{
return m_uptrPcoCamera->GetDelayTime(dDelayTime);
}
int PcoCLHSImpl::SetDelayTime(double dDelayTime)
{
return m_uptrPcoCamera->SetDelayTime(dDelayTime);
......@@ -247,12 +242,12 @@ namespace PcoNS
{
return m_uptrPcoCamera->GetCOCRuntime();
}
int PcoCLHSImpl::GetCameraBusyStatus(short& shCameraBusyStatus)
{
return m_uptrPcoCamera->GetCameraBusyStatus(shCameraBusyStatus);
}
int PcoCLHSImpl::ForceTrigger(short& shTrigger)
{
return m_uptrPcoCamera->ForceTrigger(shTrigger);
......@@ -262,7 +257,7 @@ namespace PcoNS
{
return m_uptrPcoCamera->SetStorageMode(shStorageMode);
}
int PcoCLHSImpl::GetRecorderMode(short& shRecorderMode)
{
shRecorderMode = 0;
......@@ -270,7 +265,7 @@ namespace PcoNS
}
int PcoCLHSImpl::SetRecorderMode(short shRecorderMode)
{
return DOES_NOT_SUPPORT;
return DOES_NOT_SUPPORT;
}
int PcoCLHSImpl::ClearRAMSegment()
......@@ -282,12 +277,12 @@ namespace PcoNS
{
return m_uptrPcoCamera->StartAcq(nFrameNumbers);
}
int PcoCLHSImpl::StopAcq()
{
return m_uptrPcoCamera->StopAcq();
}
int PcoCLHSImpl::GetImageData(vector<short>& vImg,int& nX,int& nY)
{
return m_uptrPcoCamera->GetImageData(vImg,nX,nY);
......
......@@ -27,14 +27,14 @@
namespace PcoNS
{
PcoEdgeCLHS::PcoEdgeCLHS()
{
m_isroi_y_symmetric = true;
}
bool PcoEdgeCLHS::SetCamera(shared_ptr<CPco_com>& sptrCamera)
{
m_sptrCamera = sptrCamera;
m_uptrGrabber = unique_ptr<CPco_grab_clhs>(
new CPco_grab_clhs((CPco_com_clhs*)sptrCamera.get()));
if(m_uptrGrabber->Open_Grabber(0) != OK)
if(!PcoProduct::SetCamera(sptrCamera))
return false;
//10s timeout
......
......@@ -27,6 +27,7 @@ namespace PcoNS
class PcoEdgeCLHS : public PcoProduct
{
public:
PcoEdgeCLHS();
bool SetCamera(shared_ptr<CPco_com>& sptrCamera);
int GetLUT(short& shIdentifier,short& shParam);
int SetLUT(short shIdentifier,short shParam);
......
......@@ -22,6 +22,13 @@
namespace PcoNS
{
PcoProduct::PcoProduct()
:m_isroi_x_symmetric(false),
m_isroi_y_symmetric(false)
{
}
PcoProduct::~PcoProduct()
{
m_uptrGrabber->Close_Grabber();
......@@ -29,14 +36,29 @@ namespace PcoNS
m_sptrCamera->Close_Cam();
}
bool PcoProduct::SetCamera(shared_ptr<CPco_com>& /* sptrCamera */)
bool PcoProduct::SetCamera(shared_ptr<CPco_com>& sptrCamera)
{
// m_sptrCamera = sptrCamera;
m_sptrCamera = sptrCamera;
m_uptrGrabber = unique_ptr<CPco_grab_clhs>(
new CPco_grab_clhs((CPco_com_clhs*)sptrCamera.get()));
// m_uptrGrabber = unique_ptr<CPco_grab_cl_me4>(
// new CPco_grab_cl_me4_camera((CPco_com_cl_me4*)sptrCamera.get()));
if(m_uptrGrabber->Open_Grabber(0) != OK)
return false;
if(m_sptrCamera->PCO_GetCameraDescription(&m_camera_desc) != 0)
return GET_ERROR;
return true;
}
int PcoProduct::GetCameraMaxSize(int& x, int& y)
{
x = static_cast<int>(m_camera_desc.wMaxHorzResStdDESC);
y = static_cast<int>(m_camera_desc.wMaxVertResStdDESC);
// m_uptrGrabber->Open_Grabber(0);
return OK;
}
const string PcoProduct::GetModuleName()
......@@ -110,6 +132,9 @@ namespace PcoNS
int PcoProduct::SetROI(short shX0,short shY0,
short shX1,short shY1)
{
if(!CalculateROI(shX0,shY0,shX1,shY1))
return SET_ERROR;
if(m_sptrCamera->PCO_SetROI((unsigned short)shX0,(unsigned short)shY0,
(unsigned short)shX1,(unsigned short)shY1) != OK)
return SET_ERROR;
......@@ -407,4 +432,71 @@ namespace PcoNS
{
return DOES_NOT_SUPPORT;
}
bool PcoProduct::CalculateROI(short& x0,short& y0,short& x1,short& y1)
{
short oldx0,oldy0,oldx1,oldy1;
short roistepx, roistepy;
short binx,biny;
int x,y;
if(GetCameraMaxSize(x,y) != OK)
return false;
//if binning is changed,size of image is changed too.
if(GetBinning(binx,biny) == OK)
{
x = x/binx;
y = y/biny;
}
if(GetROIStep(roistepx,roistepy) != OK)
return false;
if(GetROI(oldx0,oldy0,oldx1,oldy1) != OK)
return false;
vector<int> roinew={x0,y0,x1,y1};
vector<int> roiold={oldx0,oldy0,oldx1,oldy1};
int i=0;
for(i=0;i<4;++i)
if(roinew[i] != roiold[i])
break;
switch(i)
{
case 0: // x0 changed
x0 = (x0-1)/roistepx*roistepx + 1;
if(m_isroi_x_symmetric)
x1 = x - x0 + 1;
break;
case 1: // y0 changed
y0 = (y0 - 1)/roistepy*roistepy + 1;
if(m_isroi_y_symmetric)
y1 = y - y0 + 1;
break;
case 2: //x1 changed
x1 = x1/roistepx*roistepx;
if(m_isroi_x_symmetric)
x0 = x - x1 + 1;
break;
case 3: //y1 changed
y1 = y1/roistepx*roistepx;
if(m_isroi_y_symmetric)
y0 = y - y1 + 1;
break;
default:
return false;
}
//cout<<m_isroi_x_symmetric<<"-"<<m_isroi_y_symmetric<<"x0:"<<x0<<" - y0:"<<y0<<" - x1:"<<x1<<" - y1:"<<y1<<endl;
return true;
}
}
......@@ -40,6 +40,8 @@ namespace PcoNS
virtual bool SetCamera(shared_ptr<CPco_com>& sptrCamera);
virtual const string GetModuleName();
virtual int GetCameraMaxSize(int& x, int& y);
virtual int GetRecordingState(short& shRecordingState);
virtual int SetRecordingState(short shRecordingState);
......@@ -96,7 +98,7 @@ namespace PcoNS
virtual ~PcoProduct();
protected:
PcoProduct() = default;
PcoProduct();
/**
* @brief Cameralink Interface only
* @param PCO_SC2_CL_TRANSFER_PARAMS structure
......@@ -135,10 +137,15 @@ namespace PcoNS
double ConvertSecondToMicroSecond(double dTimeInSecond)
{ return dTimeInSecond*pow(10,6); }
virtual bool CalculateROI(short& x0,short& y0,short& x1,short& y1);
shared_ptr<CPco_com> m_sptrCamera;
/* unique_ptr<CPco_grab_cl_me4> m_uptrGrabber; */
unique_ptr<CPco_grab_clhs> m_uptrGrabber;
SC2_Camera_Description_Response m_camera_desc;
bool m_isroi_x_symmetric,m_isroi_y_symmetric;
};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment