OPC Version 1.8 build 0925 KOCRDK Knight OPC Client Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9
OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOC_Init...5 2.2.2 KOC_Uninit...5 2.3...5 2.3.1 KOC_SetDataChangeProc...6 2.3.2 KOC_SetShutdownProc...7 2.4 Server...7 2.4.1 KOC_GetServerCount...7 2.4.2 KOC_GetServerName...8 2.4.3 KOC_Connect...8 2.4.4 KOC_Disconnect...9 2.5 Group...9 2.5.1 KOC_AddGroup...9 2.5.2 KOC_RemoveGroup...10 2.6 Item...10 2.6.1 KOC_GetItemCount...10 2.6.2 KOC_GetItemName...11 2.6.3 KOC_AddItem...11 2.6.4 KOC_RemoveItem...12 2.6.5 KOC_WriteItem...12 2.6.6 KOC_ReadItem...12 3...14 3.1...14 3.2 step1...14 3.3 step2...15 3.4 Step3...15 3.4.1...15 3.5 Step4 OPC...16 3.5.1 OPC...16 3.5.2 OPC...17 3.5.3...17 3.6 Step5 OPC...20 2
Knight OPC Client Rapid Development Toolkits 3.7 step6 OPC...21 3.8 step7 OPC...21 3.8.1 OPC...22 3.8.2 OPC...23 3.9 step8 OPC...23 4...25 4.1...25 4.2...25 3
OPC 1 KOCRDK Knight OPC Client Rapid Development Toolkits KOCRDK OPC OLE For Process Control DA Data Access KOCRDK OPC OPC DA: Data Access 1.0/2.0 DLL ATL/DCOM OPC Visual C++, Visual Basic, Borland C++ builder, Delphi 4
Knight OPC Client Rapid Development Toolkits 2 API 2.1 KOCRDK API KOCRDKapi.h API KOC_ 2.2 2.2.1 KOC_Init OPC OPC BOOL KOC_Init (); 0 2.2.2 KOC_Uninit VOID KOC_Uninit (); OPC 2.3 OPC Client DLL KOCRDK.dll 5
OPC 2.3.1 KOC_SetDataChangeProc BOOL KOC_SetDataChangeProc (HANDLE hconnect, DATACHANGEPROC lpcallback) 0 (1) HANDLE hconnect : OPC (2) DATACHANGEPROC lpcallback KOCRDK OPC OPC OPC OPC OPC OPC void CALLBACK EXPORT ClientWriteProc DataChangeProc ( HANDLE hconnect, HANDLE hgroup, HANDLE hitem, VARIANT *pvar, FILETIME timestamp, DWORD quality) (1) HANDLE hconnect OPC Server (2) HANDLE hgroup OPC Group (3) HANDLE hitem OPC Item (4) VARIANT *pvar (5) FILETIME timestamp (6) DWORD quality 6
Knight OPC Client Rapid Development Toolkits 2.3.2 KOC_SetShutdownProc BOOL KOC_SetShutdownProc (HANDLE hconnect, SHUTDOWNPROC lpcallback ) 0 (1) HANDLE hconnect : OPC (2) SHUTDOWNPROC lpcallback OPC OPC KOCRDK.DLL OPC void CALLBACK EXPORT ShutdownProc(HANDLE hconnect) (1) HANDLE hconnect : OPC 2.4 Server API OPC 2.4.1 KOC_GetServerCount int KOC_GetServerCount (LPCSTR MachineName, BOOL bver2 = true); -1 OPC (1) LPCSTR MachineName (2) BOOL bver2 OPC OPC TRUE OPC 2.0 FALSE OPC 1.0 TRUE OPC 7
OPC KOCRDK KOC_GetServerName OPC OPC -1 : OPC DCOMCNFG.exe 2.4.2 KOC_GetServerName BOOL KOC_GetServerName(int index, char *pbuf, int BufSize); false true (1) int index KOCRDK.dll KOC_GetServerCount 0 KOC_GetServerCount 1 (2) char *pbuf (3) int BufSize KOCRDK.dll OPC 2.4.3 KOC_Connect HANDLE KOC_Connect (LPCSTR MachineName, LPCSTR ServerName, BOOL bver2 = true); -1 OPC (1) LPCSTR MachineName (2) LPCSTR ServerName OPC (3) BOOL bver2 OPC OPC TRUE OPC 2.0 FALSE OPC 1.0 TRUE OPC 8
Knight OPC Client Rapid Development Toolkits OPC 2.0 1.0/2.0 OPC 1.0 1.0 OPC 2.4.4 KOC_Disconnect void KOC_Disconnect (HANDLE hconnect); (1) HANDLE hconnect OPC OPC OPC OPC 2.5 Group API OPC 2.5.1 KOC_AddGroup HANDLE KOC_AddGroup ( HANDLE LPCSTR hconnect, Name, BOOL *bactive, DWORD *prate, LONG *ptimebias, float *pdeadband, DWORD *dwlcid ); -1 OPC HANDLE (1) HANDLE hconnect OPC 9
OPC (2) LPCSTR Name OPC (3) BOOL *bactive: OPC (4) DWORD *prate DWORD OPC (5) LONG *ptimebias LONG (6) float *pdeadband: float (7) DWORD *dwlcid DWORD OPC OPC OPC OPC 2.5.2 KOC_RemoveGroup void KOC_RemoveGroup(HANDLE hconnect, HANDLE hgroup); (1) HANDLE hconnect OPC (2) HANDLE hgroup OPC OPC OPC 2.6 Item API OPC / 2.6.1 KOC_GetItemCount int KOC_GetItemCount (HANDLE hconnect); -1 OPC OPC (1) HANDLE hconnect OPC 10
Knight OPC Client Rapid Development Toolkits OPC OPC KOCRDK KOC_GetItemName OPC OPC -1 2.6.2 KOC_GetItemName BOOL KOC_GetItemName (int index, char *pbuf, int BufSize); false true (1) int index KOCRDK.dll OPC KOC_GetItemCount 0 KOC_GetItemCount 1 (2) char *pbuf (3) int BufSize KOCRDK.dll OPC OPC 2.6.3 KOC_AddItem HANDLE KOC_AddItem ( HANDLE hconnect, HANDLE hgroup, LPCSTR ItemName); -1 OPC HANDLE (1) HANDLE hconnect OPC (2) HANDLE hgroup OPC (3) LPCSTR ItemName: OPC KOC_GetItemName OPC OPC OPC OPC 11
OPC 2.6.4 KOC_RemoveItem void KOC_RemoveItem ( HANDLE hconnect, HANDLE hgroup, HANDLE hitem ); (1) HANDLE hconnect OPC (2) HANDLE hgroup OPC (3) HANDLE hitem: OPC OPC OPC 2.6.5 KOC_WriteItem BOOL KOC_WriteItem ( HANDLE hconnect, HANDLE hgroup, HANDLE hitem, VARIANT *pvar, BOOL DoAsync ); false true (1) HANDLE hconnect OPC (2) HANDLE hgroup OPC (3) HANDLE hitem: OPC (4) VARIANT *pvar: (5) BOOL DoAsync: True false OPC KOCRDK OPC OPC 2.6.6 KOC_ReadItem BOOL KOC_ReadItem ( HANDLE hconnect, HANDLE hgroup, HANDLE hitem, VARIANT *pvar, FILETIME *ptimestamp, DWORD *pquality ); false true 12
Knight OPC Client Rapid Development Toolkits (1) HANDLE hconnect OPC (2) HANDLE hgroup OPC (3) HANDLE hitem: OPC (4) VARIANT *pvar: (5) FILETIME *ptimestamp (6) DWORD *pquality OPC 13
OPC 3 3.1 Microsoft Visual C++ 6.0 OPC KOCRDK \Samples\source\KOCVC\DemoClient.dsw 3.2 step1 OPC / OPC / DLL http://www.opcfoundation.org http://www.eehoo.net/opcdist.zip KOCRDK 1.5 4 system32 opcproxy.dll opccomn_ps.dll opcae_ps.dll opchda_ps.dll 4 REGSVR32 opcproxy.dll REGSVR32 opccomn_ps.dll REGSVR32 opc_aeps.dll REGSVR32 opchda_ps.dll actxprxy.dll aprxdist.exe 14
Knight OPC Client Rapid Development Toolkits 3.3 step2 Visual C++ KOCRDK 3 (1) KOCRDK.dll KOCRDK OPC (2) KOCRDK.lib KOCRDK.dll (3) KOCRDKapi.h KOCRDK KOCRDK API opcda.h OPC Visual Basic Delphi 3.4 Step3 3.4.1 KOC_Init() BOOL KOC_Init() //Filename: DemoClient.cpp //Function: CDemoClientApp::InitInstance() AfxEnableControlContainer(); ////////// KOC Init /////////////////// if (!KOC_Init()) return FALSE; 15
OPC 3.5 Step4 OPC OPC KOC_GetServerCount OPC KOC_GetServerName OPC KOC_Connect OPC OPC KOC_Connect 3.5.1 OPC //Filename: ConnectDlg.cpp //Function: CConnectDlg::OnFind() int i,ncount; char buf[100]; // OPC ncount = KOC_GetServerCount(m_strNodeName,!m_bVer1); if ( ncount == -1) { MessageBox("Can't get Server List!", "Error", MB_ICONSTOP ); } return; for (i=0;i<ncount;i++) { } // OPC KOC_GetServerName(i,buf,100); m_lbserverlist.addstring(buf); 16
Knight OPC Client Rapid Development Toolkits 3.5.2 OPC OPC //Filename: DemoClientView.cpp //Function: CDemoClientView::OnOpcConnect() HANDLE hconnect; hconnect = KOC_Connect( dlg.m_strnodename, // dlg.m_strservername, //OPC!dlg.m_bVer1); //OPC if (hconnect==invalid_handle_value) { AfxMessageBox("Connect to OPC Server Failed!"); return; } 3.5.3 OPC KOCRDK CALLBACK KOCRDK.dll (1) OPC OPC OPC OPC KOCRDK.dll //Filename: DemoClientView.cpp 17
OPC //Function: CDemoClientView::OnOpcConnect() // KOC_SetDataChangeProc ( m_hconnect, &DataChangeProc); DataChangeProc //Filename: DemoClientView.cpp void CALLBACK EXPORT DataChangeProc( { CMainFrame *pwnd; HANDLE hserver, HANDLE hgroup, HANDLE hitem, VARIANT *pvar, FILETIME timestamp, DWORD quality) pwnd = (CMainFrame *)AfxGetMainWnd(); CItem *pitem; int i; // OPC OPC for (i=0;i<pwnd->m_pview->itemlist.getsize();i++) { pitem = (CItem *)pwnd->m_pview->itemlist.getat(i); if (pitem->hitem == hitem) { // OPC VariantClear(&(pItem->Value)); VariantCopy (&(pitem->value), pvar); pitem->timestamp = timestamp; pitem->quality = quality; 18
Knight OPC Client Rapid Development Toolkits return; } } } (2) OPC //Filename: DemoClientView.cpp //Function: CDemoClientView::OnOpcConnect() // KOC_SetShutdownProc (m_hconnect, &ShutdownProc); ShutdownProc //Filename: DemoClientView.cpp void CALLBACK EXPORT ShutdownProc(HANDLE hconnect) { CMainFrame *pwnd; pwnd = (CMainFrame *)AfxGetMainWnd(); // 0); PostMessage(pWnd->m_pView->m_hWnd, OPCSHUTDOWN_MSG, 0, } OPC OPC OPC 19
OPC 3.6 Step5 OPC OPC OPC //Filename: DemoClientView.cpp //Function: CDemoClientView::OnOpcGroupAdd() CGroupAddDlg dlg; dlg.m_strgroupname = "Group1"; dlg.m_dwupdaterate = 100; dlg.m_fdeadband = 0.0f; if (dlg.domodal()!= IDOK ) return; HANDLE hgroup; BOOL bactive = true; long ltimebias = 0; DWORD dwlcid = 0; hgroup = KOC_AddGroup( m_hconnect, //OPC dlg.m_strgroupname, //OPC &bactive, // &dlg.m_dwupdaterate, // <imebias, &dlg.m_fdeadband, // // &dwlcid); // if (hgroup==invalid_handle_value) { AfxMessageBox("Add Group Failed!"); return; } 20
Knight OPC Client Rapid Development Toolkits 3.7 step6 OPC OPC OPC OPC OPC OPC KOC_GetItemCount KOC_GetItemName OPC OPC OPC //Filename: DemoClientView.cpp //Function: CDemoClientView::AddItem( ) HANDLE htag = NULL; htag = KOC_AddItem( m_hconnect, m_hgroup, //OPC //OPC stritemname); //OPC if (htag == INVALID_HANDLE_VALUE) { TRACE("Add Item %s Failed!\n",strItemName); return FALSE; } OPC OPC OPC OPC 3.8 step7 OPC OPC OPC OPC OPC OPC OPC OPC 21
OPC 3.8.1 OPC OPC //Filename: DemoClientView.cpp //Function: CDemoClientView:: OnItemRead() VARIANT Value; VariantInit (&Value); FILETIME fttime; DWORD dwquality; BOOL bresult = KOC_ReadItem( m_hconnect, //OPC m_hgroup, //OPC pitem->hitem,//opc &Value, &fttime, // // &dwquality );// if (bresult) { TRACE("Read Succ.\n"); VariantCopy(&pItem->Value,&Value); pitem->timestamp = fttime; pitem->quality = dwquality; } else TRACE("Read Failed.\n"); VariantClear(&Value); 22
Knight OPC Client Rapid Development Toolkits 3.8.2 OPC OPC OPC //Filename: DemoClientView.cpp //Function: CDemoClientView:: OnItemWrite() BOOL bresult = KOC_WriteItem( m_hconnect, m_hgroup, //OPC //OPC pitem->hitem, //OPC vt, // dlg.m_basync); // OPC (1) OPC (2) OPC (3) OPC (4) OPC (5) OPC 3.9 step8 OPC OPC (1) KOC_RemoveItem() KOCRDK.dll OPC (2) KOC_RemoveGroup() KOCRDK.dll OPC (3) new 23
OPC (4) KOC_Uninit() OPC 24
Knight OPC Client Rapid Development Toolkits 4 4.1 KOCRDK 4.2 http://www.eehoo.net OPC opc@eehoo.net / sales@eehoo.net support@eehoo.net 25