/// <summary> /// 设置组属性 /// </summary> /// <param name="opcGroup">OPCGroup对象</param> /// <param name="groupPropertiesModel">GroupPropertiesModel对象</param> public void SetGroupProperty(OPCGroup opcGroup, GroupPropertiesModel groupPropertiesModel) { _opcSerialInfo.OpcServer.OPCGroups.DefaultGroupIsActive = groupPropertiesModel.DefaultGroupIsActive; _opcSerialInfo.OpcServer.OPCGroups.DefaultGroupDeadband = groupPropertiesModel.DefaultGroupDeadBand; opcGroup.IsActive = groupPropertiesModel.IsActive; opcGroup.IsSubscribed = groupPropertiesModel.IsSubscribed; opcGroup.UpdateRate = groupPropertiesModel.UpdateRate; }
private void SetGroupProperty(GroupPropertiesModel groupPropertiesModel) { Log.Info($"设置组属性:" + $"{groupPropertiesModel.DefaultGroupIsActive}," + $"{groupPropertiesModel.DefaultGroupDeadBand}," + $"{groupPropertiesModel.IsActive}," + $"{groupPropertiesModel.IsSubscribed}," + $"{groupPropertiesModel.UpdateRate}"); _opcServer.OPCGroups.DefaultGroupIsActive = groupPropertiesModel.DefaultGroupIsActive; _opcServer.OPCGroups.DefaultGroupDeadband = groupPropertiesModel.DefaultGroupDeadBand; _opcGroup.IsActive = groupPropertiesModel.IsActive; _opcGroup.IsSubscribed = groupPropertiesModel.IsSubscribed; _opcGroup.UpdateRate = groupPropertiesModel.UpdateRate; }
public void ReadOpcServer(string[] filter, GroupPropertiesModel groupPropertiesModel) { if (_opcServer != null && _opcGroups != null && _opcGroup != null && _opcItems != null) { Log.Info("没有有对象为null"); AddDataChangeEvent(); } else { Log.Info("有对象为null"); LocalIpHost.ReadIpHost(out _hostIp, out _hostName); try { object opcServers = _opcServer.GetOPCServers(_hostName); foreach (string turn in (Array)opcServers) { _kepServerName = turn; } } catch (Exception exception) { Log.Error("初始化Opc出错:" + exception); throw; } //连接opc try { //KEPware.KEPServerEx.V4 //127.0.0.1 Log.Info($"连接Opc:{_kepServerName},{_hostIp}"); _opcServer.Connect(_kepServerName, _hostIp); } catch (Exception e) { Log.Error("连接Opc出错:" + e); throw; } RecurBrowse(_opcServer.CreateBrowser(), filter); try { _opcGroups = _opcServer.OPCGroups; _opcGroup = _opcGroups.Add("OPC.NetGroup"); SetGroupProperty(groupPropertiesModel); _opcItems = _opcGroup.OPCItems; for (int i = 0; i < _bindingData.Count; i++) { try { OPCItem item = _opcItems.AddItem(_bindingData[i].OpcName, i); if (item != null) { _itmHandleServer = item.ServerHandle; _dic.Add(item.ClientHandle, _bindingData[i].OpcName); _serviceDic.Add(_itmHandleServer, _bindingData[i].OpcName); } } catch (Exception e) { Log.Error("客户端服务器句柄赋值失败:" + e); throw; } foreach (KeyValuePair <int, string> keyValuePair in _serviceDic) { try { ReadOPCValue(keyValuePair.Key); } catch (Exception e) { // ignored } } } Log.Info("第一次装载_opcGroup数据改变监听事件"); _opcGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup_DataChange); } catch (Exception e) { Log.Error("设置opcGroups,opcGroup,opcItems:" + e); throw; } } }
/// <summary> /// 初始化OPCGroups和OPCItems /// </summary> /// <param name="opcGroups">OPCGroups对象</param> /// <param name="GroupName">自定义组名字</param> /// <param name="opcGroup">OPCGroup对象</param> /// <param name="opcItems">OPCItems对象</param> /// <param name="groupPropertiesModel">GroupPropertiesModel对象</param> public void SetGroupsAndItems(out OPCGroups opcGroups, string GroupName, out OPCGroup opcGroup, out OPCItems opcItems, GroupPropertiesModel groupPropertiesModel) { opcGroups = _opcSerialInfo.OpcServer.OPCGroups; opcGroup = opcGroups.Add(GroupName); SetGroupProperty(opcGroup, groupPropertiesModel); opcItems = opcGroup.OPCItems; }