/// <summary> /// 为待监听的全部Item生成ClientHandles, /// 根据配置信息将这些ClientHandles归档(Sum,Avg,Single), /// 并返回为之生成的ClientHandles /// </summary> /// <returns>生成的ClientHandles</returns> private int[] SetupItems() { int handle = 1; int id = 1; List <int> result = new List <int>(); for (int i = 0; i < Config.Group.OpcItems.Length; i++) { foreach (var item in Config.Group.OpcItems[i].Items) { ItemRow ir = new ItemRow(); ir.ID = id; ir.Name = item.Name; ir.Strategy = item.Strategy; ir.Handles = new List <int>(); ir.Data = new object[item.SubItems.Count]; foreach (var subItem in item.SubItems) { rowIdMap.Add(handle, id); ir.Handles.Add(handle); result.Add(handle); itemIDs.Add(subItem.Value); handle++; } itemTable.Add(ir); id++; } } return(result.ToArray()); }
private void Group_DataChange(int _TransactionID, int _NumItems, ref Array _ClientHandles, ref Array _ItemValues, ref Array _Qualities, ref Array _timeStamps) { //_ClientHandles可确定该条数据是哪个测点的 int id = 0; for (int i = 1; i <= _NumItems; i++) { OPCAutomation.OPCQuality quality = (OPCAutomation.OPCQuality)_Qualities.GetValue(i); int clientHandle = (int)_ClientHandles.GetValue(i); id = (int)rowIdMap[clientHandle]; if (quality == OPCAutomation.OPCQuality.OPCQualityGood) { object value = _ItemValues.GetValue(i); ItemRow ir = itemTable[id - 1]; //clientHandle-id可保证每次都覆盖clientHandle对应位置上的数据并保留本次没有更新到的数据 ir.Data[clientHandle - id] = value; //重复赋值,但只取最后一次的值,待优化 ir.Timestamp = (DateTime)_timeStamps.GetValue(i); } else { errorCount++; errorItems.Add(itemIDs[id - 1]); } } Hashtable result = ProcessItemTable(); if (errorCount == 0) { OPCDataChanged(this, new OpcDataChangedEventArgs(Config.Type, result)); } else { string message = OpcUnableToReadException.CreateErrorMessage(errorCount, errorItems); OPCDataChanged(this, new OpcDataChangedEventArgs(Config.Type, result, message)); } }
/// <summary> /// 为待监听的全部Item生成ClientHandles, /// 根据配置信息将这些ClientHandles归档(Sum,Avg,Single), /// 并返回为之生成的ClientHandles /// </summary> /// <returns>生成的ClientHandles</returns> private int[] SetupItems() { int handle = 1; int id = 1; List<int> result = new List<int>(); for (int i = 0; i < Config.Group.OpcItems.Length; i++) { foreach (var item in Config.Group.OpcItems[i].Items) { ItemRow ir = new ItemRow(); ir.ID = id; ir.Name = item.Name; ir.Strategy = item.Strategy; ir.Handles = new List<int>(); ir.Data = new object[item.SubItems.Count]; foreach (var subItem in item.SubItems) { rowIdMap.Add(handle, id); ir.Handles.Add(handle); result.Add(handle); itemIDs.Add(subItem.Value); handle++; } itemTable.Add(ir); id++; } } return result.ToArray(); }