You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
604 lines
22 KiB
C++
604 lines
22 KiB
C++
#include "StdAfx.h"
|
|
#include "ThorlabsRotatoMotorCtrlMgr.h"
|
|
#include "Propertie.h"
|
|
#include "PropertieMgr.h"
|
|
#include "AuthorityMgr.h"
|
|
#include "ExceptionMsg.h"
|
|
#include "LogMgr.h"
|
|
#include "GlobalFunction.h"
|
|
#include "WorkCmdInvoker.h"
|
|
#include "CStringFuc.h"
|
|
#include "DeviceStateMgr.h"
|
|
#include "Laser.h"
|
|
#include "EncryptionMgr.h"
|
|
|
|
#include "Thorlabs.MotionControl.IntegratedStepperMotors.h"
|
|
|
|
|
|
#define DIMMER_ANG_MIN 0//衰减器的最小角度
|
|
#define DIMMER_ANG_MAX 350//衰减器的最大角度
|
|
#define DIMMER_MOVE_DLEAY 300 //等待衰减器移动的延时s
|
|
#if 1
|
|
//错误处理(抛出异常)(默认bNeedOrgDev = true)
|
|
void CRotatoDimmer::RotatoDimmerErrHandle(eAlarmType AlarmType,CString AddInfo,bool bNeedOrgDev)
|
|
{
|
|
if(bNeedOrgDev)//需要重新进行复位操作
|
|
{
|
|
m_bOpenDev = false;
|
|
m_CurAng = -1;//当前的角度值
|
|
}
|
|
//设置报警信息
|
|
{
|
|
COperateAlarmPar OperateAlarmPar;
|
|
OperateAlarmPar.m_OperateAlarmType = _OperateAlarmType_SetAlarmOn;
|
|
OperateAlarmPar.m_AlarmType = AlarmType;
|
|
OperateAlarmPar.m_AlarmAddInfo = AddInfo;
|
|
OperateAlarmPar.m_bThowException = THOW_EXCEPTION;
|
|
gWarningMgr->OperateAlarmState(OperateAlarmPar);
|
|
}
|
|
}
|
|
//初始化设备
|
|
bool CRotatoDimmer::InitK10CR1Dev()
|
|
{
|
|
try
|
|
{
|
|
CLogInfo LogInfo;
|
|
LogInfo.m_ClassName = "CRotatoDimmer";
|
|
LogInfo.m_FuncName = "InitK10CR1Dev";
|
|
LogInfo.m_LogMsg = "Start";
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
|
|
m_bOpenDev = false;
|
|
//int--->char[]
|
|
sprintf_s(m_DevSerialNo, "%d", m_SerialNoVal);
|
|
if (TLI_BuildDeviceList() == 0)
|
|
{
|
|
// get device list size
|
|
short n = TLI_GetDeviceListSize();
|
|
// get LTS serial numbers
|
|
char serialNos[100];
|
|
TLI_GetDeviceListByTypeExt(serialNos, 100, 55);
|
|
// output list of matching devices
|
|
{
|
|
char *searchContext = nullptr;
|
|
char *p = strtok_s(serialNos, ",", &searchContext);
|
|
while (p != nullptr)
|
|
{
|
|
TLI_DeviceInfo deviceInfo;
|
|
// get device info from device
|
|
TLI_GetDeviceInfo(p, &deviceInfo);
|
|
// get strings from device info structure
|
|
char desc[65];
|
|
strncpy_s(desc, deviceInfo.description, 64);
|
|
desc[64] = '\0';
|
|
char serialNo[9];
|
|
strncpy_s(serialNo, deviceInfo.serialNo, 8);
|
|
serialNo[8] = '\0';
|
|
// output
|
|
p = strtok_s(nullptr, ",", &searchContext);
|
|
}
|
|
}
|
|
static CCriticalSection sec;
|
|
CSingleLock slck(&sec, true);
|
|
if (ISC_Open(m_DevSerialNo) == 0)
|
|
{
|
|
LogInfo.m_LogMsg = "Succ";
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
//Alarm
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_InitDevErr;
|
|
if (m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_InitDevErr;
|
|
|
|
COperateAlarmPar OperateAlarmPar;
|
|
OperateAlarmPar.m_OperateAlarmType = _OperateAlarmType_SetAlarmOn;
|
|
OperateAlarmPar.m_AlarmType = AlarmType;
|
|
OperateAlarmPar.m_AlarmAddInfo = "打开衰减器异常.";
|
|
OperateAlarmPar.m_bThowException = false;
|
|
gWarningMgr->OperateAlarmState(OperateAlarmPar);
|
|
}
|
|
return false;
|
|
}
|
|
//移动到原点
|
|
void CRotatoDimmer::MoveHome()
|
|
{
|
|
CLogInfo LogInfo;
|
|
LogInfo.m_ClassName = "CRotatoDimmer";
|
|
LogInfo.m_FuncName = "MoveHome";
|
|
LogInfo.m_LogMsg = "Start";
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
|
|
int RetCode;
|
|
// start the device polling at 200ms intervals
|
|
ISC_StartPolling(m_DevSerialNo, 200);
|
|
Sleep(3000);
|
|
// Home device
|
|
ISC_ClearMessageQueue(m_DevSerialNo);
|
|
//设置原点速度
|
|
//int HomingVelocity = ISC_GetHomingVelocity(m_DevSerialNo);
|
|
int HomingVelocity = 73300775;
|
|
//ISC_SetHomingVelocity(m_DevSerialNo,HomingVelocity);
|
|
|
|
//设置home 的原点偏移值
|
|
{
|
|
CString log;
|
|
//获取当前的home 参数
|
|
MOT_HomingParameters homingParams;
|
|
RetCode = ISC_GetHomingParamsBlock(m_DevSerialNo,&homingParams);
|
|
if(RetCode!=0)
|
|
{
|
|
log.Format("Get Homing Params Err :Code = %d",RetCode);
|
|
LogInfo.m_LogMsg = log;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_GetParamsFailed;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_GetParamsFailed;
|
|
RotatoDimmerErrHandle(AlarmType,log);
|
|
}
|
|
log.Format("Read homingParams : velocity=%d,offsetDistance=%d,offsetAng=%lf",homingParams.velocity,homingParams.offsetDistance,PosToAngVal(homingParams.offsetDistance));
|
|
LogInfo.m_LogMsg = log;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
//设置原点偏移值
|
|
if(m_OrgOffsetAng>0)
|
|
{
|
|
homingParams.offsetDistance = AngToPosVal(m_OrgOffsetAng);
|
|
homingParams.velocity = 73300775;
|
|
|
|
log.Format("Set homingParams : offsetDistance=%d,offsetAng=%lf",homingParams.offsetDistance,PosToAngVal(homingParams.offsetDistance));
|
|
LogInfo.m_LogMsg = log;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
|
|
RetCode = ISC_SetHomingParamsBlock(m_DevSerialNo,&homingParams);
|
|
if(RetCode!=0)
|
|
{
|
|
log.Format("Set Homing Params Err :Code = %d",RetCode);
|
|
LogInfo.m_LogMsg = log;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_SetParamsFailed;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_SetParamsFailed;
|
|
RotatoDimmerErrHandle(AlarmType,log);
|
|
}
|
|
|
|
RetCode = ISC_GetHomingParamsBlock(m_DevSerialNo,&homingParams);
|
|
if(RetCode!=0)
|
|
{
|
|
log.Format("Get Homing Params Err :Code = %d",RetCode);
|
|
LogInfo.m_LogMsg = log;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_GetParamsFailed;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_GetParamsFailed;
|
|
RotatoDimmerErrHandle(AlarmType,log);
|
|
}
|
|
log.Format("Read homingParams : velocity=%d,offsetDistance=%d,offsetAng=%lf",homingParams.velocity,homingParams.offsetDistance,PosToAngVal(homingParams.offsetDistance));
|
|
LogInfo.m_LogMsg = log;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
}
|
|
}
|
|
|
|
RetCode = ISC_Home(m_DevSerialNo);
|
|
if(RetCode!=0)
|
|
{
|
|
CString s;
|
|
s.Format("Home Error : Code = %d",RetCode);
|
|
LogInfo.m_LogMsg = s;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_HomeFailed;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_HomeFailed;
|
|
RotatoDimmerErrHandle(AlarmType,s);
|
|
}
|
|
//等待移动到角度
|
|
WaitMoveToAngVal(0);
|
|
|
|
m_bOpenDev = true;
|
|
LogInfo.m_LogMsg = "End";
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
}
|
|
//等待移动到坐标
|
|
void CRotatoDimmer::WaitMoveToAngVal(double AngVal)
|
|
{
|
|
//通过坐标来判断移动是否完成
|
|
int WaitDelay = (DIMMER_MOVE_DLEAY)*1000;//总共等待的时间ms
|
|
int CheckDelay = 300;//每次循环延时
|
|
int CurDelay = 0;//当前的总延时
|
|
double PerPos = ISC_GetPosition(m_DevSerialNo);//上一个位置
|
|
int NoMoveTimes = 0;//没有移动的判断次数
|
|
int MoveEndTimes = 0;//移动到位的判断次数
|
|
bool bMoveErr = false;
|
|
while(1)
|
|
{
|
|
Sleep(CheckDelay);
|
|
m_CurPos = ISC_GetPosition(m_DevSerialNo);
|
|
if(IsTwoDbEqual(PerPos,m_CurPos,0.01))//没有移动
|
|
{
|
|
NoMoveTimes++;
|
|
}
|
|
else
|
|
{
|
|
NoMoveTimes = 0;
|
|
}
|
|
if(NoMoveTimes>=10)//多次检测未移动
|
|
{
|
|
bMoveErr = true;
|
|
break;
|
|
}
|
|
//坐标位置转换为角度值
|
|
m_CurAng = PosToAngVal(m_CurPos);
|
|
if(IsTwoDbEqual(AngVal,m_CurAng,0.01))//执行完成
|
|
{
|
|
MoveEndTimes++;
|
|
|
|
if(MoveEndTimes>2)
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
MoveEndTimes = 0;
|
|
}
|
|
CurDelay += CheckDelay;
|
|
if(CurDelay>WaitDelay)//检测超时
|
|
{
|
|
bMoveErr = true;
|
|
break;
|
|
}
|
|
}
|
|
if(bMoveErr)//检测超时
|
|
{
|
|
CString Str;
|
|
Str.Format("Move Over Time:Ang = %lf",AngVal);
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_MoveOverTime;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_MoveOverTime;
|
|
RotatoDimmerErrHandle(AlarmType,Str);
|
|
}
|
|
}
|
|
//移动到指定位置
|
|
void CRotatoDimmer::MoveToAngle()
|
|
{
|
|
CString s;
|
|
s.Format(" Angle = %.3f",m_ToAngVal);
|
|
|
|
CLogInfo LogInfo;
|
|
LogInfo.m_ClassName = "CThorlabsRotatoMotorCtrlMgr";
|
|
LogInfo.m_FuncName = "MoveToAngle";
|
|
LogInfo.m_LogMsg = gLaser->GetLaserDeviceName(m_LaserDeviceType);
|
|
LogInfo.m_LogMsg += s;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
|
|
if(!(m_ToAngVal>=DIMMER_ANG_MIN && m_ToAngVal<=DIMMER_ANG_MAX))
|
|
{
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_AngleOutOfRange;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_AngleOutOfRange;
|
|
RotatoDimmerErrHandle(AlarmType,"Angle Out Of Range",false);
|
|
}
|
|
double MovePosVal = AngToPosVal(m_ToAngVal);//角度转换为PosVal
|
|
int RetCode = ISC_MoveToPosition(m_DevSerialNo, MovePosVal);
|
|
if(RetCode!=0)
|
|
{
|
|
s.Format("Move Failed : Code = %d",RetCode);
|
|
LogInfo.m_LogMsg = s;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_MoveFailed;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_MoveFailed;
|
|
RotatoDimmerErrHandle(AlarmType,s);
|
|
}
|
|
//等待移动到角度
|
|
WaitMoveToAngVal(m_ToAngVal);
|
|
LogInfo.m_LogMsg = "End";
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
}
|
|
//读取当前的状态
|
|
void CRotatoDimmer::ReadDimmerState()
|
|
{
|
|
if(!m_bOpenDev)
|
|
return;
|
|
if(gDeviceStateMgr->QueryUsedFunc(_EUsedFunc_RotatoDimmer,false))
|
|
{
|
|
m_CurPos = ISC_GetPosition(m_DevSerialNo);
|
|
//坐标位置转换为角度值
|
|
m_CurAng = PosToAngVal(m_CurPos);
|
|
}
|
|
}
|
|
//角度转换为衰减器的位置值
|
|
double CRotatoDimmer::AngToPosVal(double AngVal)
|
|
{
|
|
double MovePosVal = (AngVal *m_RotatoAngScal) / 5;
|
|
return MovePosVal;
|
|
}
|
|
//衰减器的位置值转换为角度
|
|
double CRotatoDimmer::PosToAngVal(double Pos)
|
|
{
|
|
//pos 682667对应5度
|
|
double Ang360 = Pos;
|
|
Ang360 /= m_RotatoAngScal;
|
|
Ang360 *= 5;
|
|
return Ang360;
|
|
}
|
|
|
|
//步进
|
|
void CRotatoDimmer::MoveJog(bool bDir)
|
|
{
|
|
CLogInfo LogInfo;
|
|
LogInfo.m_ClassName = "CThorlabsRotatoMotorCtrlMgr";
|
|
LogInfo.m_FuncName = "MoveJog";
|
|
LogInfo.m_LogMsg = Bool2Str(bDir);
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
|
|
int RetCode = ISC_SetJogStepSize(m_DevSerialNo,AngToPosVal(m_MoveJogAng));
|
|
if(RetCode!=0)
|
|
{
|
|
CString s;
|
|
s.Format("Jog Move Failed : Code = %d",RetCode);
|
|
LogInfo.m_LogMsg = s;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_MoveFailed;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_MoveFailed;
|
|
RotatoDimmerErrHandle(AlarmType,s);
|
|
}
|
|
MOT_TravelDirection TravelDirection = (bDir)?(MOT_Forwards):(MOT_Reverse);
|
|
RetCode = ISC_MoveJog(m_DevSerialNo,TravelDirection);
|
|
if(RetCode!=0)
|
|
{
|
|
CString s;
|
|
s.Format("Jog Move Failed : Code = %d",RetCode);
|
|
LogInfo.m_LogMsg = s;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_MoveFailed;
|
|
if(m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_MoveFailed;
|
|
RotatoDimmerErrHandle(AlarmType,s);
|
|
}
|
|
}
|
|
|
|
#endif
|
|
#if 1
|
|
|
|
#endif
|
|
|
|
CThorlabsRotatoMotorCtrlMgr *gThorlabsRotatoMotorCtrlMgr = new CThorlabsRotatoMotorCtrlMgr;
|
|
CThorlabsRotatoMotorCtrlMgr::CThorlabsRotatoMotorCtrlMgr(void)
|
|
{
|
|
m_MoveOverTime = DIMMER_MOVE_DLEAY;//运动超时(s)
|
|
m_Laser1RotatoDimmerAng = 0;//激光1 使用的衰减角度(用于双激光 edi check 的时候记录laser1 的角度)
|
|
m_Laser2RotatoDimmerAng = 0;//激光2 使用的衰减角度(用于双激光 edi check 的时候记录laser2 的角度)
|
|
|
|
m_RotatoDimmer1.m_LaserDeviceType = _LaserDeviceType_MainLaser1;
|
|
m_RotatoDimmer2.m_LaserDeviceType = _LaserDeviceType_MainLaser2;
|
|
}
|
|
CThorlabsRotatoMotorCtrlMgr::~CThorlabsRotatoMotorCtrlMgr(void)
|
|
{
|
|
|
|
}
|
|
CMFCPropertyGridProperty *CThorlabsRotatoMotorCtrlMgr::CreatGridProperty()
|
|
{
|
|
CString PropertyName;//属性名称
|
|
CString Description;//描述
|
|
CString Path = GetParDirName();//存储路径
|
|
CString Name;
|
|
CString GroupName;
|
|
CString ModuleName;
|
|
//-------------------------------------------------------------------------------//
|
|
PropertyName = _T("旋转衰减器");
|
|
GroupName = PropertyName;
|
|
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
|
|
//-------------------------------------------------------------------------------//
|
|
{
|
|
CMFCPropertyGridProperty* pGroup1;
|
|
pGroup1 = CreatRotatoGridProperty(m_RotatoDimmer1,_T("衰减器1"),_T("m_RotatoDimmer1"));
|
|
pGroup->AddSubItem(pGroup1);
|
|
pGroup1 = CreatRotatoGridProperty(m_RotatoDimmer2,_T("衰减器2"),_T("m_RotatoDimmer2"));
|
|
pGroup->AddSubItem(pGroup1);
|
|
}
|
|
return pGroup;
|
|
}
|
|
//创建衰减器的属性
|
|
CMFCPropertyGridProperty* CThorlabsRotatoMotorCtrlMgr::CreatRotatoGridProperty(CRotatoDimmer &RotatoDimmer,CString RotatoDimmerName,CString ValName)
|
|
{
|
|
CPropertieMgr *pPropertieMgr = &gDevicePropertieMgr;
|
|
|
|
CString PropertyName;//属性名称
|
|
CString Description;//描述
|
|
CString Path = GetParDirName();//存储路径
|
|
CString Name;
|
|
CString GroupName = RotatoDimmerName;
|
|
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(RotatoDimmerName);
|
|
{
|
|
{
|
|
//添加属性变量映射
|
|
Name = ValName+_T("_SerialNoVal");//变量名字
|
|
CPropertie *pPropertie = new CPropertie;
|
|
pPropertie->SetpVal((void*)&RotatoDimmer.m_SerialNoVal);
|
|
pPropertie->SetType(_PROP_TYPE_INT);
|
|
pPropertie->SetpModule(this);
|
|
pPropertie->SetPath(Path);
|
|
pPropertie->SetName(Name);
|
|
pPropertie->WriteRead(true);//读取保存的属性
|
|
//添加属性显示
|
|
PropertyName = _T("设备序列号");
|
|
Description = _T("设备序列号");
|
|
pPropertie->SetGroupName(GroupName);
|
|
pPropertie->SetShowName(PropertyName);
|
|
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)RotatoDimmer.m_SerialNoVal, Description);
|
|
pGroup1->AddSubItem(p1);
|
|
pPropertieMgr->Insert(p1, pPropertie);
|
|
}
|
|
{
|
|
//添加属性变量映射
|
|
Name = ValName+_T("_RotatoAngScal");//变量名字
|
|
CPropertie *pPropertie = new CPropertie;
|
|
pPropertie->SetpVal((void*)&RotatoDimmer.m_RotatoAngScal);
|
|
pPropertie->SetType(_PROP_TYPE_DOUBLE);
|
|
pPropertie->SetpModule(this);
|
|
pPropertie->SetPath(Path);
|
|
pPropertie->SetName(Name);
|
|
pPropertie->WriteRead(true);//读取保存的属性
|
|
//添加属性显示
|
|
PropertyName = _T("旋转细分数");
|
|
Description = _T("旋转角度细分数");
|
|
pPropertie->SetGroupName(GroupName);
|
|
pPropertie->SetShowName(PropertyName);
|
|
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)RotatoDimmer.m_RotatoAngScal, Description);
|
|
pGroup1->AddSubItem(p1);
|
|
pPropertieMgr->Insert(p1, pPropertie);
|
|
}
|
|
{
|
|
//添加属性变量映射
|
|
Name = ValName+_T("_OrgOffsetAng");//变量名字
|
|
CPropertie *pPropertie = new CPropertie;
|
|
pPropertie->SetpVal((void*)&RotatoDimmer.m_OrgOffsetAng);
|
|
pPropertie->SetType(_PROP_TYPE_DOUBLE);
|
|
pPropertie->SetpModule(this);
|
|
pPropertie->SetPath(Path);
|
|
pPropertie->SetName(Name);
|
|
pPropertie->WriteRead(true);//读取保存的属性
|
|
//添加属性显示
|
|
PropertyName = _T("原点偏移角度");
|
|
Description = _T("home 后的原点偏移位置");
|
|
pPropertie->SetGroupName(GroupName);
|
|
pPropertie->SetShowName(PropertyName);
|
|
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)RotatoDimmer.m_OrgOffsetAng, Description);
|
|
pGroup1->AddSubItem(p1);
|
|
pPropertieMgr->Insert(p1, pPropertie);
|
|
}
|
|
}
|
|
return pGroup1;
|
|
}
|
|
#if 1
|
|
//执行对应指令
|
|
void CThorlabsRotatoMotorCtrlMgr::ExcuteRotatoDimmerCmd(eLaserDeviceType LaserDeviceType,eRotatoDimmerCmdType DimmerCmd)
|
|
{
|
|
if(gEncryptionMgr->IsbRunAtNoteBook())
|
|
{
|
|
Sleep(2000);
|
|
return;
|
|
}
|
|
if (!gDeviceStateMgr->QueryUsedFunc(_EUsedFunc_RotatoDimmer, false))
|
|
return;
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(LaserDeviceType);
|
|
if(DimmerCmd != _RotatoDimmerCmd_Home && !RotatoDimmer.m_bOpenDev)
|
|
{
|
|
eAlarmType AlarmType = _AlarmType_RotatoDimmer1_InitDevErr;
|
|
if(RotatoDimmer.m_LaserDeviceType == _LaserDeviceType_MainLaser2)
|
|
AlarmType = _AlarmType_RotatoDimmer2_InitDevErr;
|
|
RotatoDimmer.RotatoDimmerErrHandle(AlarmType,"Device not initialize");//需要设备初始化成功
|
|
}
|
|
switch(DimmerCmd)
|
|
{
|
|
case _RotatoDimmerCmd_Home://找原点
|
|
{
|
|
if(RotatoDimmer.InitK10CR1Dev())
|
|
{
|
|
RotatoDimmer.MoveHome();
|
|
}
|
|
}
|
|
break;
|
|
case _RotatoDimmerCmd_ToAng://移动到指定角度
|
|
{
|
|
RotatoDimmer.MoveToAngle();
|
|
}
|
|
break;
|
|
case _RotatoDimmerCmd_JogZ://步进
|
|
{
|
|
RotatoDimmer.MoveJog(true);
|
|
}
|
|
break;
|
|
case _RotatoDimmerCmd_JogF://步进
|
|
{
|
|
RotatoDimmer.MoveJog(false);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
//通过激光类型来获取衰减器对象
|
|
CRotatoDimmer &CThorlabsRotatoMotorCtrlMgr::GetRotatoDimmer(eLaserDeviceType LaserDeviceType)
|
|
{
|
|
if(LaserDeviceType==_LaserDeviceType_MainLaser1)
|
|
return m_RotatoDimmer1;
|
|
return m_RotatoDimmer2;
|
|
}
|
|
//读取Thorlabs 电机状态(坐标值)
|
|
void CThorlabsRotatoMotorCtrlMgr::ReadThorlabsMotorState()
|
|
{
|
|
{
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(_LaserDeviceType_MainLaser1);
|
|
RotatoDimmer.ReadDimmerState();
|
|
}
|
|
{
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(_LaserDeviceType_MainLaser2);
|
|
RotatoDimmer.ReadDimmerState();
|
|
}
|
|
}
|
|
|
|
bool CThorlabsRotatoMotorCtrlMgr::IsbOpenDev(eLaserDeviceType LaserDeviceType)
|
|
{
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(LaserDeviceType);
|
|
return RotatoDimmer.m_bOpenDev;
|
|
}
|
|
double CThorlabsRotatoMotorCtrlMgr::GetToAngVal(eLaserDeviceType LaserDeviceType)
|
|
{
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(LaserDeviceType);
|
|
return RotatoDimmer.m_ToAngVal;
|
|
}
|
|
double CThorlabsRotatoMotorCtrlMgr::GetRotatoAngScal(eLaserDeviceType LaserDeviceType)
|
|
{
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(LaserDeviceType);
|
|
return RotatoDimmer.m_RotatoAngScal;
|
|
}
|
|
double CThorlabsRotatoMotorCtrlMgr::GetOrgOffsetAng(eLaserDeviceType LaserDeviceType)
|
|
{
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(LaserDeviceType);
|
|
return RotatoDimmer.m_OrgOffsetAng;
|
|
}
|
|
//设置旋转角度值(Val<0的情况设置为m_Laser1RotatoDimmerAng)
|
|
void CThorlabsRotatoMotorCtrlMgr::SetToAngVal(eLaserDeviceType LaserDeviceType,double Val)
|
|
{
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(LaserDeviceType);
|
|
if(Val<0)//小于0表示使用最近一次复检的角度
|
|
{
|
|
if(LaserDeviceType==_LaserDeviceType_MainLaser1)
|
|
RotatoDimmer.m_ToAngVal = m_Laser1RotatoDimmerAng;
|
|
else
|
|
RotatoDimmer.m_ToAngVal = m_Laser2RotatoDimmerAng;
|
|
}
|
|
else//大于0 为正常设置角度
|
|
{
|
|
RotatoDimmer.m_ToAngVal = Val;
|
|
}
|
|
}
|
|
double CThorlabsRotatoMotorCtrlMgr::GetCurAng(eLaserDeviceType LaserDeviceType)
|
|
{
|
|
CRotatoDimmer &RotatoDimmer = GetRotatoDimmer(LaserDeviceType);
|
|
return RotatoDimmer.m_CurAng;
|
|
}
|
|
//保存复检后的衰减角度
|
|
void CThorlabsRotatoMotorCtrlMgr::SetLastRotatoDimmerAng(eLaserDeviceType LaserDeviceType,double Ang)
|
|
{
|
|
CLogInfo LogInfo;
|
|
LogInfo.m_ClassName = "CThorlabsRotatoMotorCtrlMgr";
|
|
LogInfo.m_FuncName = "SetLastRotatoDimmerAng";
|
|
LogInfo.m_LogMsg.Format(" Ang=%lf",Ang);
|
|
LogInfo.m_LogMsg = gLaser->GetLaserDeviceName(LaserDeviceType) + LogInfo.m_LogMsg;
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
if (Ang < 0.00001)
|
|
{
|
|
return;
|
|
}
|
|
if(LaserDeviceType==_LaserDeviceType_MainLaser1)
|
|
m_Laser1RotatoDimmerAng = Ang;
|
|
else
|
|
m_Laser2RotatoDimmerAng = Ang;
|
|
}
|
|
#endif
|