⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpctestview.cpp

📁 VC++实现的预测控制
💻 CPP
📖 第 1 页 / 共 2 页
字号:
									tag->name = AITagList->GetAt(i)->name;
									tag->pos = AITagList->GetAt(i)->pos;
									AITagList->SetAtGrow(i,tag) ;
									delete tag;
									
									break;
								}
							}
							for(i=0;i<AOTagList->GetSize();i++)
							{
                                if(AOTagList->GetAt(i)->name.Compare(pItem->name)==0)
								{
									mytag* tag =new mytag;
									tag->value = double(pItem->value.dblVal);
									tag->name = AOTagList->GetAt(i)->name;
									tag->pos = AOTagList->GetAt(i)->pos;
									AOTagList->SetAtGrow(i,tag) ;
									delete tag;
									break;
								}
							}
							
							
							break;
						}
					case VT_BOOL:
						AITagList->GetAt(index)->value = double(pItem->value.boolVal);					
						break;
					case VT_UI2:	//WORD
						AITagList->GetAt(index)->value = double(pItem->value.uiVal);		
						break;
					case VT_UI4:	//DWORD
						AITagList->GetAt(index)->value = double(pItem->value.ulVal);				
						break;
					case VT_BSTR:	//String
						ReadItemStringValue[index]=pItem->value.bstrVal;
						break;
						
					}
					pDocs.GetAt(count+1)->items.GetNext(pos);		   
				}
			}
		}
		control();
		time = time+ComputeTime/24.0/60.0/60.0;
		UpdateData(0);
	}
	CRecordView::OnTimer(nIDEvent);
}

void CMPCTestView::OnLoopset() 
{
	// TODO: Add your command handler code here
	if(!m_IsStart)
	{
    CZhuTai dlg;
	dlg.pDoc = pDoc;
	if(dlg.DoModal()!=IDOK)
	{		
	}
	DllPath = dlg.m_dllpath;
	suantime = dlg.m_suanfatime;
	}
	
}

void CMPCTestView::OnOpenInifile() 
{
	// TODO: Add your command handler code here
	// initial the OPC Server Com
	// Use the SelectServer to connect OPC server
	// ParentDoc is the point usefor OPCServer in SelectServer
	CSelectServer dlg; //Create the object
	dlg.ParentDoc = pDoc;
	// Use the File to Read Configure File
	//if Second Use this command
	// Stop the Control program
	//disConnect OPC Server
	if(m_Stop)
	{
		AfxMessageBox("停止现存的控制程序?");
		m_Stop = FALSE;
        dlg.RemoveServer();
	}
	CFileDialog LoadFileDlg(true,NULL,NULL,OFN_READONLY|OFN_LONGNAMES|OFN_HIDEREADONLY|OFN_EXTENSIONDIFFERENT,"configure Files (*.ini)|*.ini||All Files (*.*)|*.*||",NULL);	//文件对话框
	LoadFileDlg.m_ofn.lpstrTitle="保存配置好的文件"; 
	CString  FilePath;
	if(LoadFileDlg.DoModal()!=0)
    {
		UpdateData();
		FilePath = LoadFileDlg.m_ofn.lpstrFile;	
	}
    else
	{
		AfxMessageBox("空文档");
		return;
	}
    AITagList->RemoveAll();
	AOTagList->RemoveAll();
	CString strSection       = "Section1";
	CString strSectionKey    = "OPC Server Name";
	CString strValue       = _T("");
	char inBuf[80];
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	if(strValue.Compare("")==0)
	{
		AfxMessageBox("调用文档失败!");
		return;
	}
    dlg.m_Server = strValue;
	strSection       = "Section1";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	
	strSection       = "Section2";
	strSectionKey    = "OPC Server Node";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
    
	
	functionname = strValue;	
	strSection       = "Section2";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	if(strValue.Compare("")==0)
	{
		AfxMessageBox("调用文档失败!");
		return;
	}
	dlg.m_Node = strValue;
    dlg.Addserver(dlg.m_Server);
	
	strSection       = "Section3";
	strSectionKey    = "DLL FilePath";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	DllPath = strValue;
	strSection       = "Section3";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	
	strSection       = "Section4";
	strSectionKey    = "INI FilePath";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	IniPathName = strValue;
	if(strValue.Compare("")==0)
	{
		AfxMessageBox("调用文档失败!");
		return;
	}
	
	strSection       = "Section2";
	strSectionKey    = "Functionname";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	functionname = strValue;
	strSection       = "Section2";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	strSection       = "Section3";
	strSectionKey    = "Dialogname";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	dialogname = strValue;
	
	strSection       = "Section3";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, IniPathName); 
	strValue=inBuf;
	
	strSection       = "Section4";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	
	strSection       = "Section5";
	strSectionKey    = "AI的个数";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	if(strValue.Compare("")==0)
	{
		AfxMessageBox("调用文档失败!");
		return;
	}
	int k = atoi(strValue);   
	strSection       = "Section5";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	
	strValue=inBuf;
	strSection       = "Section6";
	strSectionKey    = "AO的个数";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	if(strValue.Compare("")==0)
	{
		AfxMessageBox("调用文档失败!");
		return;
	}
	int l = atoi(strValue);   
	strSection       = "Section6";
	strSectionKey    = "explain";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
	strValue=inBuf;
	CArray<CString,CString> AddItem;
    for(int index =0;index<k;index++)
	{
		strSection.Format("Section%d",7+index);
		strSectionKey = "Ai name";
		strValue       = _T("");
		GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
		strValue=inBuf;
		if(strValue.Compare("")==0)
		{
			AfxMessageBox("调用文档失败!");
			return;
		}
		m_CurveAIName[index]=strValue;
		
		strSection.Format("Section%d",7+index);
		strSectionKey = "OPC Client DataName1";
		strValue       = _T("");
		GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
		strValue=inBuf;
		if(strValue.Compare("")==0)
		{
			AfxMessageBox("调用文档失败!");
			return;
		}
		AddItem.SetAtGrow(index,strValue);
		tag* newtag = new tag;
		newtag->name = strValue;
		newtag->pos = index;
		AITagList->SetAtGrow(index,newtag);
		strSection.Format("Section%d",7+index);
		strSectionKey    = "explain";
		GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
		strValue = inBuf;
		
    }
	for(index =0;index<l;index++)
	{
		strSection.Format("Section%d",7+k+index);
		strSectionKey= "Ao name";
		strValue       = _T("");
		GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
		strValue=inBuf;
		if(strValue.Compare("")==0)
		{
            AfxMessageBox("调用文档失败!");
			return;
		}
        m_CurveAOName[index] = strValue;
		strSection.Format("Section%d",7+k+index);
		strSectionKey= "OPC Client DataName1";
		strValue       = _T("");
		GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
		strValue=inBuf;
		if(strValue.Compare("")==0)
		{
			AfxMessageBox("调用文档失败!");
			return;
		}
		AddItem.SetAtGrow(k+index,strValue);
		tag* newtag = new tag;
		newtag->name = strValue;
		newtag->pos = index;
		AOTagList->Add(newtag);
		strSection.Format("Section%d",7+k+index);
		strSectionKey    = "explain";
		GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath); 
		strValue =inBuf;
	}
	for(index=0;index<AddItem.GetSize();index++)
	{
		pDoc->Additem(AddItem.GetAt(index),"",0);
	}
	strSection       = "SectionT";
    strSectionKey    = "Time";
	strValue       = _T("");
	GetPrivateProfileString (strSection,strSectionKey,  NULL, inBuf, 80, FilePath
		); 
	strValue =inBuf;
	if(strValue.Compare("")==0)
	{
		AfxMessageBox("调用文档失败!");
		return;
	}
	ComputeTime = atof(strValue);
	strSection       = "SectionT";
	strSectionKey    = "explain";
    strValue       = _T("");
    GetPrivateProfileString  (strSection,strSectionKey,  
        NULL, inBuf, 80, FilePath); 
	strValue =inBuf;
	m_IsStart =TRUE;

	        m_siachart.SetLegends(AITagList->GetSize()+AOTagList->GetSize());
			m_siachart.SetSeries(AITagList->GetSize()+AOTagList->GetSize());
			m_siachart.AddSeriesToLegends();
			for(int i=0;i<AITagList->GetSize();i++)
			{
				m_siachart.SetLegendID(i);
				m_siachart.SetLegendTitle(m_CurveAIName[i]);
			}
			for(i=0;i<AOTagList->GetSize();i++)
			{
				m_siachart.SetLegendID(AITagList->GetSize()+i);
				m_siachart.SetLegendTitle(m_CurveAOName[i]);
			}
		if(!m_LoadDll)
		{
			
		    hDll=::LoadLibrary(DllPath);//加载链接库
	        if(hDll==NULL){ 
		     AfxMessageBox("找不到PIDDLL.dll,加载动态链接库失败,"); 
	        return ;} 
			m_LoadDll = TRUE;
		}

}
void CMPCTestView::OnSetup() 
{
	// TODO: Add your command handler code here
	if(m_IsStart)
	{
		typedef BOOL (*pShow)(BOOL t);
		pShow Show=(pShow)::GetProcAddress(hDll,dialogname); 
		if(Show==NULL)
		{
			AfxMessageBox("没有加载动态库"); //调用加载动态链接库失败
			return;
		}
		BOOL ty=TRUE;
		Show(ty);
		
	}
	else
		return;
}

void CMPCTestView::OnStop() 
{
	// TODO: Add your command handler code here
	if(m_IsStart)
	{
		if(pDoc==NULL||!pDoc->opcServer.IsOk())
		{
			MessageBox("请先连接服务器");
			return;
		}
		m_Stop =FALSE;
		CString s;
		s = "MC-EtherNet-H1 Interface.FI1.FBLOCK.FI-0005 PID.MODE_BLK.TARGET";
		pDoc->Write(s,8);
	}
	else
	{
		return;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -