#include "BaslerCamer.h"
BaslerCamer::BaslerCamer(void)
{
}
BaslerCamer::~BaslerCamer(void)
{
}
//相机初始化
void BaslerCamer::CamInit()
{
Pylon::PylonInitialize();
camera.Attach(CTlFactory::GetInstance().CreateFirstDevice());//实例化第一个找到的设备
//通过SN号打开相机
//di.SetSerialNumber("20928685");
//通过相机名打开相机
//di.SetModelName("acA1300-30gm");
//通过UserID打开相机
//di.SetUserDefinedName("Cam1");
//camera.Attach(CTlFactory::GetInstance().CreateDevice(di));//实例化指定相机
nodemap = &camera.GetNodeMap();//相机属性节点赋值
camera.RegisterConfiguration(new CAcquireContinuousConfiguration,RegistrationMode_ReplaceAll,Cleanup_Delete);//注册实时模式
CData = new SampleImageEventHandler();
camera.RegisterImageEventHandler( CData, RegistrationMode_Append, Cleanup_Delete);//注册回调函数
camera.MaxNumBuffer = 5;
camera.Open();//打开相机
//如果触发是AcquisitionStart模式,则AcquisitionFrameCount值设为1,如相机触发有FrameStart模式,设为FrameStart械式
CIntegerPtr AcFrameCount(nodemap->GetNode("AcquisitionFrameCount"));
AcFrameCount->SetValue(1);
// camera.StartGrabbing(GrabStrategy_OneByOne,GrabLoop_ProvidedByInstantCamera);
}
//开始取图
void BaslerCamer::Cam_Start()
{
camera.StartGrabbing(GrabStrategy_OneByOne,GrabLoop_ProvidedByInstantCamera);
}
//停止取图
void BaslerCamer::CamStop()
{
camera.StopGrabbing();
}
//退出时关闭相机
void BaslerCamer::CamDestroy()
{
camera.StopGrabbing();
camera.DestroyDevice();
Pylon::PylonTerminate();
}
//CString BaslerCamer::CamName()//获取相机名
//{
// CStringPtr DeviceName(nodemap->GetNode("DeviceModelName"));
// return ((CString)DeviceName->ToString());
//}
//CString BaslerCamer::CamSerialNum()//获取相机SN号
//{
// CStringPtr DeviceID(nodemap->GetNode("DeviceID"));
// return ((CString)DeviceID->ToString());
//}
//CString BaslerCamer::CamFormat()//获取图像格式
//{
// CEnumerationPtr pixelFormat(nodemap->GetNode("PixelFormat"));
// return ((CString)pixelFormat->ToString());
//}
//获取相机帧率
double BaslerCamer::CamFrameRate()
{
CFloatPtr FrameRate(nodemap->GetNode("ResultingFrameRateAbs"));
return ((double)FrameRate->GetValue());
}
//Sensor宽
int BaslerCamer::CamWidth()
{
CIntegerPtr CWidth(nodemap->GetNode("SensorWidth"));
return CWidth->GetValue();
}
//Sensor高
int BaslerCamer::CamHeight()
{
CIntegerPtr CHeight(nodemap->GetNode("SensorHeight"));
return CHeight->GetValue();
}
//曝光最小值
double BaslerCamer::GetExpMin()
{
CFloatPtr ExpTimeMin(nodemap->GetNode("ExposureTimeAbs"));
return ((double)ExpTimeMin->GetMin());
}
//曝光最大值
double BaslerCamer::GetExpMax()
{
CFloatPtr ExpTimeMax(nodemap->GetNode("ExposureTimeAbs"));
return ((double)ExpTimeMax->GetMax());
}
//当前曝光值
double BaslerCamer::GetExpCur()
{
CFloatPtr ExpTimeCur(nodemap->GetNode("ExposureTimeAbs"));
return ((double)ExpTimeCur->GetValue());
}
//设置曝光值
void BaslerCamer::SetExp( double ExpTime )
{
CEnumerationPtr ExpAuto(nodemap->GetNode("ExposureAuto"));
if (IsWritable(ExpAuto))
{
ExpAuto->FromString("Off");
}
CFloatPtr SetExpTime(nodemap->GetNode("ExposureTimeAbs"));
if (ExpTime <SetExpTime->GetMin())
{
SetExpTime->SetValue(SetExpTime->GetMin());
}
else if (ExpTime > SetExpTime->GetMax())
{
SetExpTime->SetValue(SetExpTime->GetMax());
}
else
{
SetExpTime->SetValue(ExpTime);
}
}
//增益最小值
int BaslerCamer::GetGainMin()
{
CIntegerPtr GainValueMin(nodemap->GetNode("GainRaw"));
return ((int)GainValueMin->GetMin());
}
//增益最大值
int BaslerCamer::GetGainMax()
{
CIntegerPtr GainValueMax(nodemap->GetNode("GainRaw"));
return ((int)GainValueMax->GetMax());
}
//当前增益值
int BaslerCamer::GetGainCur()
{
CIntegerPtr GainValueCur(nodemap->GetNode("GainRaw"));
return ((int)GainValueCur->GetValue());
}
//设置增益值
void BaslerCamer::SetGain( int GainValue )
{
CEnumerationPtr GainAuto(nodemap->GetNode("GainAuto"));
if (IsWritable(GainAuto))
{
GainAuto->FromString("Off");
}
CIntegerPtr SetGainValue(nodemap->GetNode("GainRaw"));
if (GainValue < SetGainValue->GetMin())
{
SetGainValue->SetValue(SetGainValue->GetMin());
}
else if (GainValue > SetGainValue->GetMax())
{
SetGainValue->SetValue(SetGainValue->GetMax());
}
else
{
SetGainValue->SetValue(GainValue);
}
}
//开启软触发
void BaslerCamer::SoftTrigEnableOn()
{
CEnumerationPtr triggerSelector(nodemap->GetNode("TriggerSelector"));
CEnumerationPtr triggerMode(nodemap->GetNode("TriggerMode"));
CEnumerationPtr triggerSource(nodemap->GetNode("TriggerSource"));
triggerSelector->FromString("AcquisitionStart");//FrameStart
triggerMode->FromString("On");
triggerSource->FromString("Software");
}
//关闭软触发
void BaslerCamer::SoftTrigEnableOff()
{
// CEnumerationPtr triggerSelector(nodemap->GetNode("TriggerSelector"));
CEnumerationPtr triggerMode(nodemap->GetNode("TriggerMode"));
//CEnumerationPtr triggerSource(nodemap->GetNode("TriggerSource"));
triggerMode->FromString("Off");
}
//执行软触发
void BaslerCamer::ExecuteSoftTrig()
{
CCommandPtr SoftExecute(nodemap->GetNode("TriggerSoftware"));
SoftExecute->Execute();
}
//开启外触发
void BaslerCamer::ExtTrigEnableOn()
{
CEnumerationPtr triggerSelector(nodemap->GetNode("TriggerSelector"));
CEnumerationPtr triggerMode(nodemap->GetNode("TriggerMode"));
CEnumerationPtr triggerSource(nodemap->GetNode("TriggerSource"));
triggerSelector->FromString("AcquisitionStart");//FrameStart
triggerMode->FromString("On");
triggerSource->FromString("Line1");
}
//关闭外触发
void BaslerCamer::ExtTrigEnableOff()
{
CEnumerationPtr triggerMode(nodemap->GetNode("TriggerMode"));
triggerMode->FromString("Off");
}