#include "StdAfx.h" #include "PciPortMgr.h" #include "Propertie.h" #include "PropertieMgr.h" #include "Motor.h" #include "AuthorityMgr.h" #define PCI_PORT_CNT 16 //莱普pci 卡端口的个数 CPciPortMgr *gPciPortMgr = new CPciPortMgr; CPciPortMgr::CPciPortMgr(void) { //初始化pci 的端口控制容器 IniPciPortVec(); m_OutPortDefaultStateL = 0;//输出端口低八位的默认状态 m_OutPortDefaultStateH = 0;//输出端口高八位的默认状态 } CPciPortMgr::~CPciPortMgr(void) { } void CPciPortMgr::Ini() { //初始化端口控制类型 IniPortCtrlType(); //初始化端口变化的观察者 IniObserver(); } //初始化pci 的端口控制容器 void CPciPortMgr::IniPciPortVec() { m_PciPortCnt = PCI_PORT_CNT*2;//输入输出在一起 for(int i=0;iSetPciPortType(PCI_PORT_DIR_X,PCI_PORT_PLUS_X,PCI_PORT_LIMIT_SWITCH_X_F,PCI_PORT_LIMIT_SWITCH_X_N); pMotorY->SetPciPortType(PCI_PORT_DIR_Y,PCI_PORT_PLUS_Y,PCI_PORT_LIMIT_SWITCH_Y_F,PCI_PORT_LIMIT_SWITCH_Y_N); pMotorZ->SetPciPortType(PCI_PORT_DIR_Z,PCI_PORT_PLUS_Z,PCI_PORT_LIMIT_SWITCH_Z_F,PCI_PORT_LIMIT_SWITCH_Z_N); //电机马达为端口改变的观察者 Attach(pMotorX); Attach(pMotorY); Attach(pMotorZ); } #if 1//属性设置 CMFCPropertyGridProperty *CPciPortMgr::CreatGridProperty() { CString PropertyName;//属性名称 CString Description;//描述 CString Path = _T("PciPort");;//存储路径 CString Name; //-------------------------------------------------------------------------------// PropertyName = _T("PCI 端口设置"); CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName); //-------------------------------------------------------------------------------// if(gAuthorityMgr->CheckAuthority(_FACTORY)) { { //添加属性变量映射 Name = _T("m_OutPortDefaultStateL");//变量名字 CPropertie *pPropertie = new CPropertie; pPropertie->SetpVal((void*)&m_OutPortDefaultStateL); pPropertie->SetType(_PROP_TYPE_INT); pPropertie->SetpModule(this); pPropertie->SetPath(Path); pPropertie->SetName(Name); pPropertie->WriteRead(true);//读取保存的属性 //添加属性显示 PropertyName = _T("默认输出低"); Description = _T("输出端口低八位的默认状态,二进制的每一位控制一个端口"); CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_OutPortDefaultStateL, Description); pGroup->AddSubItem(p); gDevicePropertieMgr.Insert(p, pPropertie); } { //添加属性变量映射 Name = _T("m_OutPortDefaultStateH");//变量名字 CPropertie *pPropertie = new CPropertie; pPropertie->SetpVal((void*)&m_OutPortDefaultStateH); pPropertie->SetType(_PROP_TYPE_INT); pPropertie->SetpModule(this); pPropertie->SetPath(Path); pPropertie->SetName(Name); pPropertie->WriteRead(true);//读取保存的属性 //添加属性显示 PropertyName = _T("默认输出高"); Description = _T("输出端口高八位的默认状态,二进制的每一位控制一个端口"); CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_OutPortDefaultStateH, Description); pGroup->AddSubItem(p); gDevicePropertieMgr.Insert(p, pPropertie); } for(int i=0;iSetpVal((void*)&(m_PciPortVec[i].first)); pPropertie->SetType(_PROP_TYPE_STRING); pPropertie->SetpModule(this); pPropertie->SetPath(Path); pPropertie->SetName(Name); pPropertie->WriteRead(true);//读取保存的属性 //添加属性显示 PropertyName = _T("控制内容"); Description = _T("端口控制的内容"); CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_PciPortVec[i].first, Description); //插入端口可以控制的类型 if(iAllowEdit(FALSE);//不可修改 pGroup1->AddSubItem(p1); gDevicePropertieMgr.Insert(p1, pPropertie); } { //添加属性变量映射 Name = "m_PciPortVec_second" + Idx;//变量名字 CPropertie *pPropertie = new CPropertie; pPropertie->SetpVal((void*)&m_PciPortVec[i].second); pPropertie->SetType(_PROP_TYPE_BOOL); pPropertie->SetpModule(this); pPropertie->SetPath(Path); pPropertie->SetName(Name); pPropertie->WriteRead(true);//读取保存的属性 //添加属性显示 PropertyName = _T("是否反向"); Description = _T("端口反向后写入和读取都会取相反的值"); CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_PciPortVec[i].second, Description); pGroup1->AddSubItem(p); gDevicePropertieMgr.Insert(p, pPropertie); } pGroup->AddSubItem(pGroup1); } } //-------------------------------------------------------------------------------// return pGroup; } void CPciPortMgr::ExportPar(ofstream *pFile) { (*pFile)<<"[模块] [CPciPortMgr]------------------------------------------------"<::iterator iter = m_OutPortCtrlType.begin(); vector::iterator iter_end = m_OutPortCtrlType.end(); for(;iter!=iter_end;iter++) { p->AddOption(*iter); } } //插入in 端口可以控制的类型到属性设置 void CPciPortMgr::InsertInCtrlType(CMFCPropertyGridProperty* p) { vector::iterator iter = m_InPortCtrlType.begin(); vector::iterator iter_end = m_InPortCtrlType.end(); for(;iter!=iter_end;iter++) { p->AddOption(*iter); } } //查询控制类型对应的端口号 SPciPort CPciPortMgr::GetCtrlPort(CString CtrlContent) { SPciPort PciPort; vector>::iterator iter = m_PciPortVec.begin(); vector>::iterator iter_end = m_PciPortVec.end(); for(int i=0;iter!=iter_end;iter++,i++) { if(CtrlContent == (*iter).first) { PciPort.num = i%16;//注意(设置8 还是等于0的) PciPort.bReverse = (*iter).second; break; } } return PciPort;//没找到 }