private void Group_DataChange(object p_Sender, DataChangeEventArgs p_EvArgs) { m_ItemAccessMutex.WaitOne(); for (int i = 0; i < p_EvArgs.Status.Length; ++i) { try { Dictionary <string, string> l_ItemProps = new Dictionary <string, string>(); IOPCItem l_Item = m_ServerModel.GetItemFromClientHandle(p_EvArgs.Status[i].HandleClient); l_ItemProps.Add(ServerModel.ITEM_PROP_VALUE_KEY, OPCUtility.ValueToString(l_Item.Type, p_EvArgs.Status[i].DataValue)); l_ItemProps.Add(ServerModel.ITEM_PROP_QUALITY_KEY, OPCUtility.QualityToString(p_EvArgs.Status[i].Quality)); l_ItemProps.Add(ServerModel.ITEM_PROP_TIMESTAMP_KEY, OPCUtility.TimeStampToString(p_EvArgs.Status[i].Timestamp)); m_ServerModel.UpdateItem(p_EvArgs.Status[i].HandleClient, l_ItemProps); if (this.VeriteqOPCServer) { WriteToDatabase(l_Item); } } catch (Exception l_Ex) { ErrorLog l_ErrorLog = ErrorLog.GetInstance(); l_ErrorLog.WriteToErrorLog(l_Ex.Message, l_Ex.StackTrace, "Error during OPC group update"); } } m_ItemAccessMutex.ReleaseMutex(); }
public void ReadItems() { m_ItemAccessMutex.WaitOne(); try { int l_Index = 0; OPCItemState[] l_ItemStateArray; List <int> l_ServerHandleList = m_ServerModel.GetServerHandleList(); m_Group.Read(OPCDataSource.OPC_DS_DEVICE, l_ServerHandleList.ToArray(), out l_ItemStateArray); foreach (int l_ServerHandle in l_ServerHandleList) { if (l_ItemStateArray[l_Index].Error == HResults.S_OK) { int l_ClientHandle = m_ServerModel.GetClientHandleFromServerHandle(l_ServerHandle); Dictionary <string, string> l_ItemProps = new Dictionary <string, string>(); IOPCItem l_Item = m_ServerModel.GetItemFromClientHandle(l_ClientHandle); l_ItemProps.Add(ServerModel.ITEM_PROP_VALUE_KEY, OPCUtility.ValueToString(l_Item.Type, l_ItemStateArray[l_Index].DataValue)); l_ItemProps.Add(ServerModel.ITEM_PROP_QUALITY_KEY, OPCUtility.QualityToString(l_ItemStateArray[l_Index].Quality)); l_ItemProps.Add(ServerModel.ITEM_PROP_TIMESTAMP_KEY, OPCUtility.TimeStampToString(l_ItemStateArray[l_Index].Timestamp)); m_ServerModel.UpdateItem(l_ClientHandle, l_ItemProps); if (this.VeriteqOPCServer) { WriteToDatabase(l_Item); } } l_Index++; } } catch (Exception l_Ex) { Disconnect(); throw l_Ex; } finally { m_ItemAccessMutex.ReleaseMutex(); } }