{ }
boolCOPCComm::AddItem(DWORD NumItems) {
//DWORD NumItems; //NumItems = 31;
pItems = new OPCITEMDEF[NumItems];
for(i = 0; i pItems[i].szAccessPath = L\pItems[i].szItemID = g_szItemID[i]; pItems[i].bActive = TRUE; pItems[i].hClient = i + 1; pItems[i].dwBlobSize = 0; pItems[i].pBlob = NULL; pItems[i].vtRequestedDataType = VT_R4; // TODO: Add your control notification handler code here OPCITEMDEF* pItems; OPCITEMRESULT* pItResult; HRESULT* pErrors; DWORD i; return false; //AfxMessageBox(_T(\ return false; } else { } AfxMessageBox(_T(\return true; if(!FAILED(r1)) r1 = m_IOPCServer->AddGroup(L\ &RevUpRate, IID_IOPCItemMgt, (LPUNKNOWN*)&m_IOPCItemMgt); dwLCID, &m_GrpSrvHandle, m_IOPCItemMgt = NULL; HRESULT r1; r1 = m_IOPCItemMgt->AddItems(NumItems, pItems, &pItResult, &pErrors); if(FAILED(r1) &&(r1 != S_FALSE)) { /* if(pItResult[0].dwAccessRights != (OPC_READABLE + OPC_WRITEABLE)) { } r1 = m_IOPCItemMgt->QueryInterface(IID_IOPCAsyncIO2, AfxMessageBox(_T(\delete[] pItems; return true; for (i = 0; i if(FAILED(pErrors[i])) { } else { } m_pItAttr[i].szAccessPath = pItems[i].szAccessPath; m_pItAttr[i].hClient = pItems[i].hClient; m_pItAttr[i].hServer = pItResult[i].hServer; m_pItAttr[i].dwAccessRights = pItResult[i].dwAccessRights; m_pItAttr[i].bActive = pItems[i].bActive; AfxMessageBox(_T(\delete[] pItems; return true; } delete[] pItems; return true; if(m_IOPCServer != NULL) { } m_IOPCServer->Release(); AfxMessageBox(_T(\ //exit(1); m_pItAttr[i].szItemID = g_szItemID[i]; (void**)&m_IOPCAsyncIO2); if (r1 < 0) { AfxMessageBox(\没有发现,错误的查询!\ CoTaskMemFree(m_ItemResult); m_IOPCItemMgt->Release(); m_IOPCItemMgt = NULL; m_GrpSrvHandle = NULL; m_IOPCServer->Release(); m_IOPCServer = NULL; CoUninitialize(); return; }*/ } boolCOPCComm::Write(DWORD NumItems) { /* m_ItemID[1] = g_szItemID[1]; */ r1 = m_IOPCItemMgt->QueryInterface(IID_IOPCAsyncIO, (void **)&pAsyncIO); for(i = 0; i phServer[i] = m_pItAttr[i].hServer; //NumItems = 31; phServer = new OPCHANDLE[NumItems]; IOPCAsyncIO* pAsyncIO; OPCHANDLE* phServer; HRESULT r1, r2; HRESULT* pErrors; BOOL found = FALSE; DWORD i; m_ItemValues[1].vt = VT_R4; //要写入的另一Item值 m_ItemValues[1].fltVal = 345.2; // TODO: Add your control notification handler code here m_ItemID[0] = g_szItemID[0]; m_ItemValues[0].vt = VT_R4; delete[] pItems; return false; m_ItemValues[0].fltVal = 258.5; //要写入的一Item值 } if(FAILED(r1)) { } else { } pAsyncIO->Release(); //CoTaskMemFree(pItemValue); CoTaskMemFree(pErrors); delete[] phServer; return false; //using IOPCAsyncIO::Write(..), look at OPC spezifikation r2 = pAsyncIO->Write(0, NumItems, phServer, m_ItemValues, &m_TransactionID, &pErrors); AfxMessageBox(_T(\CoTaskMemFree(pErrors); delete[] phServer; return true; if(FAILED(r2) && (r2 == E_FAIL)) { } AfxMessageBox(_T(\delete[] phServer; return true; //exit(1); float COPCComm::Read(DWORD NumItems) { //NumItems = 31; phServer = new OPCHANDLE[NumItems]; IOPCSyncIO* pSyncIO; OPCHANDLE* phServer; HRESULT r1, r2; HRESULT* pErrors; BOOL found = FALSE; DWORD i; CString temp; // TODO: Add your control notification handler code here
相关推荐: