|
|
//#include "StdAfx.h"
|
|
|
#include "LaipuVbDllMgr.h"
|
|
|
//#include "LogMgr.h"
|
|
|
//#include "SinglechipCardMgr.h"
|
|
|
//#include "Mirror.h"
|
|
|
|
|
|
|
|
|
CLaipuVbDllMgr *gLaipuVbDllMgr = new CLaipuVbDllMgr;
|
|
|
bool CLaipuVbDllMgr::m_zIsInitOk = false;
|
|
|
CLaipuVbDllMgr::CLaipuVbDllMgr(void)
|
|
|
{
|
|
|
pMarkingScanCom = NULL;//振镜dll 生成com 组件的指针
|
|
|
m_bIni = false;//是否初始化
|
|
|
}
|
|
|
CLaipuVbDllMgr::~CLaipuVbDllMgr(void)
|
|
|
{
|
|
|
}
|
|
|
void CLaipuVbDllMgr::Ini()
|
|
|
{
|
|
|
//初始化振镜mark dll 的com 组件------------------------------------------------------
|
|
|
HRESULT hresult;
|
|
|
CLSID cls_marking_scan_id;
|
|
|
|
|
|
//单线程初始化函数
|
|
|
CoInitialize(NULL);
|
|
|
//多线程初始化函数
|
|
|
//CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
|
|
|
|
|
//根据给定的程序标识符从注册表找出对应的类标识符
|
|
|
hresult=CLSIDFromProgID(OLESTR("marking_scan.marking_scan_dll"), &cls_marking_scan_id);
|
|
|
//得到组件的CLSID
|
|
|
|
|
|
//初始化CLSADO
|
|
|
/*用指定的类标识符创建一个Com对象
|
|
|
CoCreateInstance()的第一个参数是对象的CLSID(类代码),这个128位的编码唯一地标识了组件服务,它的路径和运行参数等信息都放在系统注册表中;
|
|
|
第二个参数一般情况下设为NULL;
|
|
|
第三个参数用来指明对象的运行环境,如远程或本地,此处设为CLSCTX_INPROC_SERVER,标明是服务组件是一个DLL;
|
|
|
第四个参数指明用来与对象通信接口的ID,这也是一个128位的编码;
|
|
|
第五个参数是用来接收对象的接口指针。*/
|
|
|
hresult=CoCreateInstance(cls_marking_scan_id,NULL,CLSCTX_INPROC_SERVER,__uuidof(_marking_scan_dll),(LPVOID *) &pMarkingScanCom);
|
|
|
if(FAILED(hresult))
|
|
|
{
|
|
|
LaserLogger::GetInstance()->WriteLog(0, "mark dll com is error");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
m_bIni = true;
|
|
|
LaserLogger::GetInstance()->WriteLog(0, "mark dll com is ok");
|
|
|
}
|
|
|
}
|
|
|
//通过vb dll 来初始化
|
|
|
void CLaipuVbDllMgr::VbIniCard(short low,short High)
|
|
|
{
|
|
|
|
|
|
if(!m_bIni)
|
|
|
{
|
|
|
Ini();
|
|
|
}
|
|
|
//gLogMgr->WriteDebugLog(_T("func : VbIniCard"));
|
|
|
////创建SAFEARRAY
|
|
|
//const int size = 5;
|
|
|
//BYTE ComArr[size];//脱机卡使用的串口号
|
|
|
//for(int i=0;i<size;i++)
|
|
|
//{
|
|
|
// ComArr[i]=gSinglechipCardMgr->GetCardCom(i);
|
|
|
//}
|
|
|
//转换为SAFEARRAY 数组----------------------------------------------
|
|
|
SAFEARRAY *psa;
|
|
|
SAFEARRAYBOUND rgsabound[1];
|
|
|
rgsabound[0].cElements = 5;//数组元素个数
|
|
|
rgsabound[0].lLbound = 0;
|
|
|
psa = SafeArrayCreate(VT_UI1,1,rgsabound);//VT_UI1 表示BYTE 类型
|
|
|
//添加数组元素到SAFEARRAY
|
|
|
/*for (long index = 0; index < 5; index++)
|
|
|
{
|
|
|
if (FAILED(SafeArrayPutElement(psa, &index, &ComArr[index])))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
short card = 0;//脱机卡1 , pci 卡0
|
|
|
short LaserFlg = 0;//高开激光?
|
|
|
|
|
|
/*if(gMirror->IsLaserSwitch())
|
|
|
{
|
|
|
LaserFlg = 1;
|
|
|
}*/
|
|
|
|
|
|
short LaserType = _FIBER;
|
|
|
short MirrorIdx = 0;//暂时只有一个振镜
|
|
|
short ret = 0;
|
|
|
//low = 1L << 7;
|
|
|
//High = 1L << 7;
|
|
|
ret = pMarkingScanCom->Marking_init_pci(
|
|
|
&low,//低8位输出端口初始值
|
|
|
&High,//高8位输出端口初始值
|
|
|
&card,
|
|
|
&LaserType,
|
|
|
&MirrorIdx,//用来区分调用不同的校准文件
|
|
|
&psa,
|
|
|
&LaserFlg
|
|
|
);
|
|
|
|
|
|
LaserLogger::GetInstance()->WriteLog(0, "Marking_init_pci is " + ret);
|
|
|
|
|
|
SafeArrayDestroy(psa);//释放SAFEARRAY 空间
|
|
|
|
|
|
/*if (false == CLaipuVbDllMgr::m_zIsInitOk)
|
|
|
{
|
|
|
pMarkingScanCom->Marking_init_Z();
|
|
|
CLaipuVbDllMgr::m_zIsInitOk = true;
|
|
|
}*/
|
|
|
}
|
|
|
//获取vb com 组件指针
|
|
|
_marking_scan_dll *CLaipuVbDllMgr::GetCom()
|
|
|
{
|
|
|
return pMarkingScanCom;
|
|
|
}
|
|
|
void CLaipuVbDllMgr::MarkingStart()
|
|
|
{
|
|
|
//gLogMgr->WriteDebugLog(_T("MarkingStart"));
|
|
|
pMarkingScanCom->marking_start();
|
|
|
}
|
|
|
void CLaipuVbDllMgr::MarkingStop()
|
|
|
{
|
|
|
//gLogMgr->WriteDebugLog(_T("MarkingStop"));
|
|
|
pMarkingScanCom->Marking_stop();
|
|
|
}
|
|
|
void CLaipuVbDllMgr::CallMarkingEnd(long fileno,long fileAll,long MarkM,long m_sel,long head,SAFEARRAY * psa)
|
|
|
{
|
|
|
//gLogMgr->WriteDebugLog(_T("CallMarkingEnd"));
|
|
|
//test
|
|
|
pMarkingScanCom->Marking_end(&fileno,&fileAll,&MarkM,&m_sel,&head,&psa);
|
|
|
}
|
|
|
#if 1
|
|
|
void CLaipuVbDllMgr::CallMarkingData(vector<vector<Dbxy2>> &vec)
|
|
|
{
|
|
|
SAFEARRAY *pSafeArr = CreatSafeArray(vec);
|
|
|
if(pSafeArr)
|
|
|
{
|
|
|
//TODO:这儿使用的是一个固定值
|
|
|
pMarkingScanCom->Marking_data(&pSafeArr , 60);
|
|
|
SafeArrayDestroy(pSafeArr);//释放SAFEARRAY
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void CLaipuVbDllMgr::CallMarkingDataInSemi(vector<vector<Dbxy2>> &vec)
|
|
|
{
|
|
|
int vecCnt = vec.size();
|
|
|
vector<double> NewVec;
|
|
|
NewVec.push_back(vecCnt);//点数
|
|
|
|
|
|
for (auto const & LineVec : vec)
|
|
|
{
|
|
|
Dbxy2 FirstPt = LineVec[0];
|
|
|
double SumX = FirstPt.x;
|
|
|
double SumY = FirstPt.y;
|
|
|
int PtCnt = 1;
|
|
|
for (auto const & pt : LineVec)
|
|
|
{
|
|
|
if (pt == FirstPt)
|
|
|
continue;
|
|
|
PtCnt++;
|
|
|
SumX += pt.x;
|
|
|
SumY += pt.y;
|
|
|
}
|
|
|
NewVec.emplace_back(SumX / PtCnt);
|
|
|
NewVec.emplace_back(SumY / PtCnt);
|
|
|
}
|
|
|
NewVec.push_back(0);//结束位
|
|
|
|
|
|
SAFEARRAY *pSafeArr = CreatSafeArrayD(NewVec);
|
|
|
if (pSafeArr)
|
|
|
{
|
|
|
//gLogMgr->WriteDebugLog("Func : pMarkingScanCom->Marking_data");
|
|
|
//pMarkingScanCom->Marking_Points(&pSafeArr, gProgramCspMarkMgr->GetPulseHoldTime(), gProgramCspMarkMgr->GetFirstPulseDelay()); //连续打点
|
|
|
|
|
|
//TODO:后面这两个时间需要修改
|
|
|
pMarkingScanCom->Marking_Points(&pSafeArr, 20/*m_pauseDelay*/,0/*m_pauseFirstDelay*/);
|
|
|
SafeArrayDestroy(pSafeArr);//释放SAFEARRAY
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//计算数组元素的个数
|
|
|
int CLaipuVbDllMgr::CalElementsCnt(vector<vector<Dbxy2>> &vec)
|
|
|
{
|
|
|
int ret = 0;
|
|
|
vector<vector<Dbxy2>>::iterator iter = vec.begin();
|
|
|
vector<vector<Dbxy2>>::iterator iter_end = vec.end();
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
{
|
|
|
ret++;//当前线段的点的个数
|
|
|
ret += (*iter).size()*2;//坐标数量
|
|
|
}
|
|
|
ret++;//最后的结束位
|
|
|
return ret;
|
|
|
}
|
|
|
int CLaipuVbDllMgr::CalElementsCnt(vector<double> &vec)
|
|
|
{
|
|
|
int ret = vec.size()*3;
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
//封装SAFEARRAY 的创建过程(需要在调用后释放资源)
|
|
|
SAFEARRAY * CLaipuVbDllMgr::CreatSafeArray(vector<vector<Dbxy2>> &vec)
|
|
|
{
|
|
|
//创建SAFEARRAY
|
|
|
SAFEARRAY *psa;
|
|
|
SAFEARRAYBOUND rgsabound[1];
|
|
|
rgsabound[0].cElements = CalElementsCnt(vec);//数组元素个数
|
|
|
rgsabound[0].lLbound = 0;
|
|
|
psa = SafeArrayCreate(VT_R8,1,rgsabound);//VT_R8 表示double 类型
|
|
|
//添加数组元素到SAFEARRAY
|
|
|
long idx = 0;
|
|
|
vector<vector<Dbxy2>>::iterator iter = vec.begin();
|
|
|
vector<vector<Dbxy2>>::iterator iter_end = vec.end();
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
{
|
|
|
int size = (*iter).size();
|
|
|
if(size==0)
|
|
|
continue;
|
|
|
double Cnt = (double)size;
|
|
|
if(FAILED(SafeArrayPutElement(psa,&idx,&Cnt)))//当前线段的点数
|
|
|
{
|
|
|
SafeArrayDestroy(psa);//释放SAFEARRAY
|
|
|
return NULL;
|
|
|
}
|
|
|
idx++;
|
|
|
|
|
|
vector<Dbxy2>::iterator iter1 = (*iter).begin();
|
|
|
vector<Dbxy2>::iterator iter1_end = (*iter).end();
|
|
|
for(;iter1!=iter1_end;iter1++)
|
|
|
{
|
|
|
if(FAILED(SafeArrayPutElement(psa,&idx,&(*iter1).x)))//数据点X 坐标
|
|
|
{
|
|
|
SafeArrayDestroy(psa);//释放SAFEARRAY
|
|
|
return NULL;
|
|
|
}
|
|
|
idx++;
|
|
|
if(FAILED(SafeArrayPutElement(psa,&idx,&(*iter1).y)))//数据点Y 坐标
|
|
|
{
|
|
|
SafeArrayDestroy(psa);//释放SAFEARRAY
|
|
|
return NULL;
|
|
|
}
|
|
|
idx++;
|
|
|
}
|
|
|
}
|
|
|
double zero = 0;
|
|
|
if(FAILED(SafeArrayPutElement(psa,&idx,&zero)))//结束位
|
|
|
{
|
|
|
SafeArrayDestroy(psa);//释放SAFEARRAY
|
|
|
return NULL;
|
|
|
}
|
|
|
return psa;
|
|
|
}
|
|
|
SAFEARRAY * CLaipuVbDllMgr::CreatSafeArray(vector<double> &vec)
|
|
|
{
|
|
|
//创建SAFEARRAY
|
|
|
SAFEARRAY *psa;
|
|
|
SAFEARRAYBOUND rgsabound[1];
|
|
|
rgsabound[0].cElements = CalElementsCnt(vec);//数组元素个数
|
|
|
rgsabound[0].lLbound = 0;
|
|
|
psa = SafeArrayCreate(VT_R8,1,rgsabound);//VT_R8 表示double 类型
|
|
|
//添加数组元素到SAFEARRAY
|
|
|
long idx = 0;
|
|
|
vector<double>::iterator iter = vec.begin();
|
|
|
vector<double>::iterator iter_end = vec.end();
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
{
|
|
|
if(FAILED(SafeArrayPutElement(psa,&idx,&(*iter))))
|
|
|
{
|
|
|
SafeArrayDestroy(psa);//释放SAFEARRAY
|
|
|
return NULL;
|
|
|
}
|
|
|
idx++;
|
|
|
}
|
|
|
return psa;
|
|
|
}
|
|
|
|
|
|
SAFEARRAY * CLaipuVbDllMgr::CreatSafeArrayD(vector<double> &vec)
|
|
|
{
|
|
|
//创建SAFEARRAY
|
|
|
SAFEARRAY *psa;
|
|
|
SAFEARRAYBOUND rgsabound[1];
|
|
|
rgsabound[0].cElements = CalElementsCnt(vec);//数组元素个数
|
|
|
rgsabound[0].lLbound = 0;
|
|
|
psa = SafeArrayCreate(VT_R8, 1, rgsabound);//VT_R8 表示double 类型
|
|
|
//添加数组元素到SAFEARRAY
|
|
|
long idx = 0;
|
|
|
vector<double>::iterator iter = vec.begin();
|
|
|
vector<double>::iterator iter_end = vec.end();
|
|
|
for (; iter != iter_end; iter++)
|
|
|
{
|
|
|
if (FAILED(SafeArrayPutElement(psa, &idx, &(*iter))))
|
|
|
{
|
|
|
SafeArrayDestroy(psa);//释放SAFEARRAY
|
|
|
return NULL;
|
|
|
}
|
|
|
idx++;
|
|
|
}
|
|
|
return psa;
|
|
|
}
|
|
|
|
|
|
#endif
|