void COPCItem::readSync(OPCItemData &data, OPCDATASOURCE source){ CAtlArray<COPCItem *> items; items.Add(this); COPCItem_DataMap opcData; group->readSync(items, opcData, source); COPCItem_DataMap::CPair* pos = opcData.Lookup(this); if (pos){ OPCItemData * readData = opcData.GetValueAt(pos); if (readData && !FAILED(readData->error)){ data = *readData; return; } } throw OPCException("Read failed"); }
/** * Enter the OPC items data that resulted from an operation */ static void updateOPCData(COPCItem_DataMap &opcData, DWORD count, OPCHANDLE * clienthandles, VARIANT* values, WORD * quality,FILETIME * time, HRESULT * errors){ // see page 136 - returned arrays may be out of order for (unsigned i = 0; i < count; i++){ // TODO this is bad - server could corrupt address - need to use look up table COPCItem * item = (COPCItem *)clienthandles[i]; CAtlMap<COPCItem *, OPCItemData *>::CPair* pair = opcData.Lookup(item); OPCItemData * data = NULL; if (FAILED(errors[i])){ data = new OPCItemData(errors[i]); } else { data = new OPCItemData(time[i],quality[i],values[i],errors[i]); } if (pair == NULL){ opcData.SetAt(item,data); } else { opcData.SetValueAt(pair,data); } } }