Commit ce7be1e7 authored by Yuelong Yu's avatar Yuelong Yu
Browse files

working on usbcamera

parent d76955fa
......@@ -64,4 +64,5 @@ set(PKG_LIBS "-L${SISO_LIB_DIRS} -lfglib5 -lclsersis -lhaprt -lpthread")
add_subdirectory("api")
add_subdirectory("pcome4")
add_subdirectory("pcoclhs")
add_subdirectory("pcousb")
add_subdirectory("apiloader")
......@@ -45,12 +45,22 @@ namespace PcoNS
std::string libpath = lib_path+"/";
if(det_type == 0) //clhs
libpath += libname_pcoclhs;
if(det_type == 1) //me4
libpath += libname_pcome4;
switch(det_type)
{
case 0:
libpath += libname_pcoclhs;
break;
case 1:
libpath += libname_pcome4;
break;
case 2:
libpath += libname_pcousb;
break;
default:
cerr <<"det type is not specified : "<<det_type<<endl;
return nullptr;
}
if(!(pco_loader.OpenLib(libpath)))
{
......
......@@ -33,6 +33,7 @@ namespace PcoNS
const std::string libname_pcome4 = std::string("libpcome4.so");
const std::string libname_pcoclhs = std::string("libpcoclhs.so");
const std::string libname_pcousb = std::string("libpcousb.so");
class PcoAPILoader
{
......
set(PCO_USB_NAME "pcousb")
set(USB_LIBRARY_VERSION "${LIBRARY_VERSION}")
include_directories("${PROJECT_SOURCE_DIR}"
${CMAKE_CURRENT_SOURCE_DIR}
"../vendor.sdk/include/usb"
"../api")
link_directories("../vendor.sdk/lib/usb")
message(status ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB USB_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB USB_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
set(USB_SHARED_FLAGS -Wl,-Bstatic -lpcocam_usb -lreorderfunc
-lpcofile -lpcolog
-Wl,-Bdynamic
-lpthread -lusb-1.0)
add_library(${PCO_USB_NAME} SHARED ${USB_SRC})
target_link_libraries(${PCO_USB_NAME} ${USB_SHARED_FLAGS})
set_target_properties(${PCO_USB_NAME} PROPERTIES VERSION "${USB_LIBRARY_VERSION}")
#install target
install(TARGETS ${PCO_USB_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIB_PATH})
/*
* (c) Copyright 2014-2019 DESY
*
* This file is part of DESY FS-EC software.
*
* This software is free: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************
*/
#include "PcoFactory.h"
#include "PcoProduct.h"
#include "PcoUSB.h"
namespace PcoNS
{
////////////////////PCO EdgeCLHS factory///////////////
unique_ptr<PcoProduct> PcoUSBFactory::CreateProduct()
{
auto ptr = unique_ptr<PcoProduct>(new PcoUSB());
return ptr;
}
}
/*
* (c) Copyright 2014-2019 DESY
*
* This file is part of DESY FS-EC software.
*
* This software is free: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************
*/
#pragma once
#include <iostream>
#include <memory>
namespace PcoNS
{
using namespace std;
class PcoProduct;
/**
* @brief pco factory class
*/
class PcoFactory
{
public:
/**
* @brief create pco product
* @return pco product
*/
virtual unique_ptr<PcoProduct> CreateProduct() = 0;
};
class PcoUSBFactory : public PcoFactory
{
public:
unique_ptr<PcoProduct> CreateProduct();
};
}
/*
* (c) Copyright 2014-2019 DESY
*
* This file is part of DESY FS-EC software.
*
* This software is free: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************
*/
#include "PcoProduct.h"
namespace PcoNS
{
PcoProduct::PcoProduct()
:m_isroi_x_symmetric(false),
m_isroi_y_symmetric(false)
{
}
PcoProduct::~PcoProduct()
{
m_uptrGrabber->Close_Grabber();
m_uptrGrabber.reset(nullptr);
m_sptrCamera->Close_Cam();
}
bool PcoProduct::SetCamera(shared_ptr<CPco_com>& sptrCamera)
{
m_sptrCamera = sptrCamera;
m_uptrGrabber = unique_ptr<CPco_grab_usb>(
new CPco_grab_usb((CPco_com_usb*)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);
return OK;
}
const string PcoProduct::GetModuleName()
{
char chInfo[100];
if(m_sptrCamera->PCO_GetInfo(1,chInfo,sizeof(chInfo)) != 0)
return string("Unknown Camera Type");
return string(chInfo);
}
int PcoProduct::GetRecordingState(short& shRecordingState)
{
unsigned short ushTmp;
if(m_sptrCamera->PCO_GetRecordingState(&ushTmp) != OK)
return GET_ERROR;
shRecordingState = ushTmp;
return OK;
}
int PcoProduct::SetRecordingState(short shRecordingState)
{
if( m_sptrCamera->PCO_SetRecordingState((unsigned short)shRecordingState) != OK)
return SET_ERROR;
return OK;
}
int PcoProduct::GetTemperature(short& shCCDTemperature,
short& shCameraTemperature,
short& shPowerDeviceTemperature)
{
if(m_sptrCamera->PCO_GetTemperature(&shCCDTemperature,&shCameraTemperature,&shPowerDeviceTemperature) != OK )
return GET_ERROR;
return OK;
}
int PcoProduct::GetCoolingSetpointTemperature(short& /* shTemperature */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::SetCoolingSetpointTemperature(short /* shTemperature */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::GetBinning(short& /* shBinHorz */,short& /* shBinVert */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::SetBinning(short /* shBinHorz */,short /* shBinVert */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::GetROI(short& shX0,short& shY0,
short& shX1,short& shY1)
{
unsigned short ushTmp1,ushTmp2,ushTmp3,ushTmp4;
if(m_sptrCamera->PCO_GetROI(&ushTmp1,&ushTmp2,&ushTmp3,&ushTmp4) != OK)
return GET_ERROR;
shX0 = ushTmp1;
shY0 = ushTmp2;
shX1 = ushTmp3;
shY1 = ushTmp4;
return OK;
}
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;
return ArmCamera();
}
int PcoProduct::GetROIStep(short& shXstep,short& shYstep)
{
SC2_Camera_Description_Response stDesc;
if(m_sptrCamera->PCO_GetCameraDescriptor(&stDesc) != OK)
return GET_ERROR;
shXstep = stDesc.wRoiHorStepsDESC;
shYstep = stDesc.wRoiVertStepsDESC;
return OK;
}
int PcoProduct::GetLUT(short& /* shIdentifier */,short& /* shParam */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::SetLUT(short /* shIdentifier */,short /* shParam */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::GetSizes(short& shX ,short& shY)
{
unsigned int unTmp1,unTmp2;
if(m_sptrCamera->PCO_GetActualSize(&unTmp1,&unTmp2) != OK)
return GET_ERROR;
shX = unTmp1;
shY = unTmp2;
return OK;
}
int PcoProduct::GetTriggerMode(short& shTriggerMode)
{
unsigned short ushTmp;
if(m_sptrCamera->PCO_GetTriggerMode(&ushTmp) != OK)
return GET_ERROR;
shTriggerMode = ushTmp;
return OK;
}
int PcoProduct::SetTriggerMode(short shTriggerMode)
{
if(m_sptrCamera->PCO_SetTriggerMode((unsigned short)shTriggerMode) != OK)
return SET_ERROR;
return ArmCamera();
}
int PcoProduct::GetPixelRate(int& nPixelRate)
{
unsigned int unTmp;
if(m_sptrCamera->PCO_GetPixelRate(&unTmp) != OK)
return GET_ERROR;
nPixelRate = unTmp/1000000;
return OK;
}
int PcoProduct::SetPixelRate(int nPixelRate)
{
unsigned int unTemp = static_cast<unsigned int>(nPixelRate * 1000000);
if(m_sptrCamera->PCO_SetPixelRate(unTemp) != OK)
return SET_ERROR;
return ArmCamera();
}
int PcoProduct::GetADCOperation(short& /* shADCNum */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::SetADCOperation(short /* shADCNum */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::GetTimestampMode(short& shMode)
{
unsigned short ushTmp;
if(m_sptrCamera->PCO_GetTimestampMode(&ushTmp) != OK)
return GET_ERROR;
shMode = ushTmp;
return OK;
}
int PcoProduct::SetTimestampMode(short shMode)
{
if(m_sptrCamera->PCO_SetTimestampMode((unsigned short)shMode) != OK)
return SET_ERROR;
return ArmCamera();
}
int PcoProduct::GetExposureTime(double& dExpTime)
{
unsigned int unExposureTime,unDelayTime;
if(ChangeTimeBaseToUS() != OK)
return GET_ERROR;
if(m_sptrCamera->PCO_GetDelayExposure(&unDelayTime,&unExposureTime) != 0)
return GET_ERROR;
dExpTime = ConvertMicroSecondToSecond(unExposureTime*1.0);
return OK;
}
int PcoProduct::SetExposureTime(double dExpTime)
{
unsigned int unExposureTime,unDelayTime;
if(ChangeTimeBaseToUS() != OK)
return GET_ERROR;
if(m_sptrCamera->PCO_GetDelayExposure(&unDelayTime,&unExposureTime) != 0)
return GET_ERROR;
unExposureTime = (unsigned int)(ConvertSecondToMicroSecond(dExpTime));
if(m_sptrCamera->PCO_SetDelayExposure(unDelayTime,unExposureTime) != 0)
return SET_ERROR;
return ArmCamera();
}
int PcoProduct::GetDelayTime(double& dDelayTime)
{
unsigned int unExposureTime,unDelayTime;
if(ChangeTimeBaseToUS() != OK)
return GET_ERROR;
if(m_sptrCamera->PCO_GetDelayExposure(&unDelayTime,&unExposureTime) != 0)
return GET_ERROR;
dDelayTime = ConvertMicroSecondToSecond(unDelayTime*1.0);
return OK;
}
int PcoProduct::SetDelayTime(double dDelayTime)
{
unsigned int unExposureTime,unDelayTime;
if(ChangeTimeBaseToUS() != OK)
return GET_ERROR;
if(m_sptrCamera->PCO_GetDelayExposure(&unDelayTime,&unExposureTime) != 0)
return GET_ERROR;
unDelayTime = (unsigned int)(ConvertSecondToMicroSecond(dDelayTime));
if(m_sptrCamera->PCO_SetDelayExposure(unDelayTime,unExposureTime) != 0)
return SET_ERROR;
return ArmCamera();
}
double PcoProduct::GetCOCRuntime()
{
unsigned int unSecond,unNanoSecond;
//if(
m_sptrCamera->PCO_GetCOCRuntime(&unSecond,&unNanoSecond);
// != OK )
// cout<<"cannot read"<<endl;
// cout<<unSecond<<"|"<<unNanoSecond<<endl;
//cout<<(static_cast<double>(unSecond) + (static_cast<double>(unNanoSecond))/1000000000)<<endl;
return (static_cast<double>(unSecond) + (static_cast<double>(unNanoSecond))/1000000000);
}
int PcoProduct::GetCameraBusyStatus(short& shCameraBusyStatus)
{
unsigned short ushTmp;
if(m_sptrCamera->PCO_GetCameraBusyStatus(&ushTmp) != OK)
return GET_ERROR;
shCameraBusyStatus = ushTmp;
return OK;
}
int PcoProduct::ForceTrigger(short& shTrigger)
{
unsigned short ushTmp;
int nRet = m_sptrCamera->PCO_ForceTrigger(&ushTmp);
shTrigger = ushTmp;
if(nRet !=OK || shTrigger == 0)
return SET_ERROR;
return OK;
}
int PcoProduct::SetStorageMode(short /* shStorageMode */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::ClearRAMSegment()
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::StartAcq(int /* nFrameNumbers */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::StopAcq()
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::GetImageData(vector<unsigned short>& /* vImg */,
int& /* nX */,int& /* nY */)
{
return DOES_NOT_SUPPORT;
}
int PcoProduct::GetTransferParameter(stTransferParams& stTP)
{
if(m_sptrCamera->PCO_GetTransferParameter(&stTP,sizeof(stTP)) != OK )
return SET_ERROR;
return OK;
}
int PcoProduct::SetTransferParameter(stTransferParams& stTP)
{
if(m_sptrCamera->PCO_SetTransferParameter(&stTP,sizeof(stTP)) != OK )
return SET_ERROR;
return ArmCamera();
}
int PcoProduct::ArmCamera()
{
if(m_sptrCamera->PCO_ArmCamera() !=OK )
return SET_ERROR;
return OK;
}
int PcoProduct::ChangeTimeBaseToUS()
{
unsigned short ushDelayTimeBase,ushExposureTimeBase;
if(m_sptrCamera->PCO_GetTimebase(&ushDelayTimeBase,&ushExposureTimeBase) !=OK )
return GET_ERROR;
// 1:timebase microsecond
if(ushDelayTimeBase != 1 || ushExposureTimeBase != 1)
{
//get current timebase,delay time,exposure time
unsigned int unDelay,unExposure;
unsigned short ushDelayTB,ushExposureTB;
if(m_sptrCamera->PCO_GetDelayExposureTime(&unDelay,
&unExposure,
&ushDelayTB,
&ushExposureTB) != OK)
return GET_ERROR;
switch(ushExposureTB)
{
case 0: // ns
unExposure /= 1000;
break;
case 1: // us
break;
case 2: // ms
unExposure *= (pow(10,3));
break;
}
switch(ushDelayTB)
{
case 0: // ns
unDelay /= 1000;
break;
case 1: // us
break;
case 2: // ms
unDelay *= (pow(10,3));
break;
}
if(m_sptrCamera->PCO_SetDelayExposureTime(unDelay,unExposure,1,1) != OK)
return SET_ERROR;
}
return ArmCamera();
}
int PcoProduct::PreAcq()
{
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;