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.
214 lines
6.0 KiB
C++
214 lines
6.0 KiB
C++
#include "StdAfx.h"
|
|
#include "CameraKeyence.h"
|
|
#include "SocketMgr.h"
|
|
#include "LogMgr.h"
|
|
#include "Propertie.h"
|
|
#include "PropertieMgr.h"
|
|
#include "AuthorityMgr.h"
|
|
#include "GlobalFunction.h"
|
|
|
|
|
|
#define SEND_MASSAGE_TO_CCD_DELAYE_TIME 500//发送消息给CCD ,接收反馈的等待延时
|
|
|
|
CCameraKeyence *gCameraKeyence = new CCameraKeyence;
|
|
CCameraKeyence::CCameraKeyence(void)
|
|
:m_IPAddrStr("192.168.0.10")//CCD 主机的IP地址
|
|
{
|
|
}
|
|
|
|
CCameraKeyence::~CCameraKeyence(void)
|
|
{
|
|
}
|
|
#if 1
|
|
CMFCPropertyGridProperty *CCameraKeyence::CreatGridProperty()
|
|
{
|
|
CString PropertyName;//属性名称
|
|
CString Description;//描述
|
|
CString Path = _T("DaHenCCD");;//存储路径
|
|
CString Name;
|
|
//-------------------------------------------------------------------------------//
|
|
PropertyName = _T("CCD ");
|
|
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
|
|
|
|
//先把共同设定加进来
|
|
CMFCPropertyGridProperty* pBase = CCamera::CreatGridProperty();
|
|
pGroup->AddSubItem(pBase);
|
|
//-------------------------------------------------------------------------------//
|
|
PropertyName = _T("特殊设定");
|
|
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(PropertyName);
|
|
if(gAuthorityMgr->CheckAuthority(_FACTORY))
|
|
{
|
|
//添加属性变量映射
|
|
Name = _T("m_IPAddrStr");//变量名字
|
|
CPropertie *pPropertie = new CPropertie;
|
|
pPropertie->SetpVal((void*)&m_IPAddrStr);
|
|
pPropertie->SetType(_PROP_TYPE_STRING);
|
|
pPropertie->SetpModule(this);
|
|
pPropertie->SetPath(Path);
|
|
pPropertie->SetName(Name);
|
|
pPropertie->WriteRead(true);//读取保存的属性
|
|
|
|
//添加属性显示
|
|
PropertyName = _T("CCD 主机IP 地址");
|
|
Description = _T("CCD 主机的IP 地址,用来和电脑通信");
|
|
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_IPAddrStr, Description);
|
|
pGroup1->AddSubItem(p1);
|
|
gDevicePropertieMgr.Insert(p1, pPropertie);
|
|
}
|
|
|
|
pGroup->AddSubItem(pGroup1);
|
|
return pGroup;
|
|
}
|
|
void CCameraKeyence::ExportPar(ofstream *pFile)
|
|
{
|
|
CCamera::ExportPar(pFile);
|
|
|
|
(*pFile)<<"[模块] [CCameraKeyence]------------------------------------------------"<<endl;
|
|
(*pFile)<<"[CCD 主机IP 地址][m_IPAddrStr] = "<<m_IPAddrStr<<endl;
|
|
}
|
|
//返回视场中心
|
|
Dbxy CCameraKeyence::GetCoord()
|
|
{
|
|
Dbxy pt;
|
|
pt.x = m_Coord.x + m_Size.w/2;
|
|
pt.y = m_Coord.y - m_Size.h/2;
|
|
return pt;
|
|
}
|
|
|
|
#endif
|
|
#if 1
|
|
bool CCameraKeyence::CatchPoint(Dbxy &pt)
|
|
{
|
|
if(gSocketMgr->Connect(m_IPAddrStr,8500))
|
|
{
|
|
gSocketMgr->Send("T1\r",strlen("T1\r")+1);
|
|
Sleep(SEND_MASSAGE_TO_CCD_DELAYE_TIME);
|
|
char recvBuf[100];//返回结果
|
|
gSocketMgr->Receive(recvBuf,sizeof(recvBuf));
|
|
CString str = recvBuf;
|
|
gLogMgr->WriteDebugLog(str);
|
|
gSocketMgr->Close();
|
|
//提取CCD 返回结果中的数值
|
|
double arr[20];
|
|
if(GetNumFromRecvBuf(recvBuf,arr))
|
|
{
|
|
Dbxy CCDpt(arr[0],arr[1]);
|
|
if(IsDbxyZero(CCDpt))
|
|
return false;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
//提取CCD 返回结果中的数值
|
|
BOOL CCameraKeyence::GetNumFromRecvBuf(char* recvBuf,double *arr)
|
|
{
|
|
CString Str = recvBuf;
|
|
int CommaPosPer;//第一个逗号的位置
|
|
CommaPosPer = Str.Find(",",0);
|
|
if(CommaPosPer == -1)//没找到直接返回
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
int idx = 0;
|
|
int CommaPosNext = CommaPosPer;
|
|
do
|
|
{
|
|
CommaPosNext = Str.Find(",",CommaPosPer+1);//下一个逗号的位置
|
|
if(CommaPosNext==-1)//最后一个
|
|
{
|
|
CString Str1(recvBuf+CommaPosPer+1);
|
|
arr[idx] = atof(Str1);
|
|
}
|
|
else
|
|
{
|
|
CString Str1(recvBuf+CommaPosPer+1,CommaPosNext-CommaPosPer);
|
|
arr[idx] = atof(Str1);
|
|
}
|
|
CommaPosPer = CommaPosNext;
|
|
idx++;
|
|
}while(CommaPosNext!=-1);
|
|
|
|
//未检测到mark 点
|
|
if((Str[0]!= 'T' && Str[1]!='1'))
|
|
{
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
return TRUE;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if 1
|
|
//打开CCD 光源
|
|
void CCameraKeyence::OpenCCDLight()
|
|
{
|
|
if(gSocketMgr->Connect(m_IPAddrStr,8500))
|
|
{
|
|
gSocketMgr->Send("CLV,2,100\r",strlen("CLV,1,100\r")+1);
|
|
Sleep(SEND_MASSAGE_TO_CCD_DELAYE_TIME);
|
|
gSocketMgr->Close();
|
|
}
|
|
}
|
|
//关闭CCD 光源
|
|
void CCameraKeyence::CloseCCDLight()
|
|
{
|
|
if(gSocketMgr->Connect(m_IPAddrStr,8500))
|
|
{
|
|
gSocketMgr->Send("CLV,2,0\r",strlen("CLV,1,0\r")+1);
|
|
Sleep(SEND_MASSAGE_TO_CCD_DELAYE_TIME);
|
|
gSocketMgr->Close();
|
|
}
|
|
}
|
|
//切换CCD 的场景"PW," & CStr(sd) & "," & nnn & Chr(13) & Chr(10)
|
|
void CCameraKeyence::ChangeCCDScene()
|
|
{
|
|
#if 0
|
|
CGraphSoftView* pView= m_pView;
|
|
if(pView->GetDocument()->m_CurrOpenFileName=="")
|
|
return;
|
|
DEBUG_LOG_START
|
|
pView->m_DebugLogFile<< "Function :[ChangeCCDScene][自动切换CCD 场景]"<<endl;
|
|
DEBUG_LOG_END
|
|
|
|
pView->m_CommunicationManager.SocketConnect();
|
|
CString str1 = "PW,1,";
|
|
CString str2 = str1 + pView->GetDocument()->m_CurrOpenFileName+"\r";
|
|
pView->m_CommunicationManager.m_SocketClient.Send(str2,str2.GetLength()+1,0);
|
|
DEBUG_LOG_START
|
|
pView->m_DebugLogFile<< "发送命令: "<<str2<<endl;
|
|
DEBUG_LOG_END
|
|
Sleep(SEND_MASSAGE_TO_CCD_DELAYE_TIME);
|
|
pView->m_CommunicationManager.SocketClose();
|
|
#endif
|
|
}
|
|
//切换当前显示的CCD 画面idx(1~4) 为0 表示显示全部
|
|
bool CCameraKeyence::ChangeCCDScreen(int idx)
|
|
{
|
|
if(gSocketMgr->Connect(m_IPAddrStr,8500))
|
|
{
|
|
if(idx == 1)
|
|
{
|
|
gLogMgr->WriteDebugLog("ChangeCCDScreen id = 1");
|
|
gSocketMgr->Send("VW,0,1\r",strlen("VW,0,1\r")+1);
|
|
}
|
|
if(idx == 2)
|
|
{
|
|
gLogMgr->WriteDebugLog("ChangeCCDScreen id = 2");
|
|
gSocketMgr->Send("VW,0,2\r",strlen("VW,0,1\r")+1);
|
|
}
|
|
Sleep(SEND_MASSAGE_TO_CCD_DELAYE_TIME);
|
|
char recvBuf[100];//返回结果
|
|
gSocketMgr->Receive(recvBuf,sizeof(recvBuf));
|
|
CString str = recvBuf;
|
|
gLogMgr->WriteDebugLog(str);
|
|
|
|
gSocketMgr->Close();
|
|
}
|
|
return true;
|
|
}
|
|
#endif
|