internal OpcDaGroup CreateGroupWrapper(object opcDaGroup) { var group = new OpcDaGroup(opcDaGroup, this); _groups.Add(group); return(group); }
/// <summary> /// Adds the server group by group name and group state (optional). /// </summary> /// <param name="name">The group name.</param> /// <param name="state">The group state.</param> /// <returns> /// Added group. /// </returns> public OpcDaGroup AddGroup(string name, OpcDaGroupState state = null) { CheckConnected(); if (state == null) { state = new OpcDaGroupState(); } int serverGroupHandle; TimeSpan revisedUpdateRate; int localeId = CultureHelper.GetLocaleId(state.Culture); object opcDaGroup = As <OpcServer>().AddGroup(name, state.IsActive.GetValueOrDefault(false), state.UpdateRate.GetValueOrDefault(TimeSpan.FromSeconds(1)), state.ClientHandle.GetValueOrDefault(0), state.TimeBias, state.PercentDeadband, localeId, out serverGroupHandle, out revisedUpdateRate); OpcDaGroup @group = CreateGroupWrapper(opcDaGroup); @group.UserData = state.UserData; OnGroupsChanged(new OpcDaServerGroupsChangedEventArgs(group, null)); return(@group); }
internal static OpcDaItemValue[] Create(OpcDaGroup opcDaGroup, int dwCount, int[] phClientItems, object[] pvValues, short[] pwQualities, FILETIME[] pftTimeStamps, HRESULT[] pErrors) { try { var values = new OpcDaItemValue[dwCount]; for (var i = 0; i < values.Length; i++) { values[i] = new OpcDaItemValue { Value = pvValues[i], Item = opcDaGroup.GetItem(phClientItems[i]), Quality = pwQualities[i], Timestamp = FileTimeConverter.FromFileTime(pftTimeStamps[i]), Error = pErrors[i] }; } return(values); } catch (Exception ex) { Log.Error("Cannot create OpcDaItemValue object.", ex); return(new OpcDaItemValue[0]); } }
internal static OpcDaItemValue[] Create(OpcDaGroup opcDaGroup, OPCITEMSTATE[] ppItemValues, HRESULT[] ppErrors) { try { var result = new OpcDaItemValue[ppItemValues.Length]; for (var i = 0; i < result.Length; i++) { result[i] = new OpcDaItemValue { Timestamp = FileTimeConverter.FromFileTime(ppItemValues[i].ftTimeStamp), Value = ppItemValues[i].vDataValue, Quality = ppItemValues[i].wQuality, Error = ppErrors[i], Item = opcDaGroup.GetItem(ppItemValues[i].hClient) }; } return(result); } catch (Exception ex) { Log.Error("Cannot create OpcDaItemValue object.", ex); return(new OpcDaItemValue[0]); } }
/// <summary> /// Creates a second copy of the group with a unique name. /// </summary> /// <param name="name">The name of the group. The name must be unique among the other groups created by this client.</param> /// <returns> /// The group clone. /// </returns> public OpcDaGroup Clone(string name) { object comGroup = As <OpcGroupStateMgt>().CloneGroup(name); OpcDaGroup group = Server.CreateGroupWrapper(comGroup); group.SyncItems(); return(group); }
/// <summary> /// Removes the group from the server. /// </summary> /// <param name="group">The server group.</param> /// <exception cref="System.ArgumentException">The group doesn't belong to the server;group</exception> public void RemoveGroup(OpcDaGroup group) { CheckConnected(); if (group.Server != this) { throw new ArgumentException("The group doesn't belong to the server", "group"); } TryRemoveGroup(@group); }
internal OpcDaItem(OpcDaItemDefinition itemDefinition, OPCITEMRESULT itemResult, OpcDaGroup @group) { Group = @group; ClientHandle = 0; ServerHandle = itemResult.hServer; ItemId = itemDefinition.ItemId; RequestedDataType = itemDefinition.RequestedDataType; CanonicalDataType = TypeConverter.FromVarEnum((VarEnum)itemResult.vtCanonicalDataType); Blob = itemResult.pBlob; AccessPath = itemDefinition.AccessPath; IsActive = itemDefinition.IsActive; AccessRights = (OpcDaAccessRights)itemResult.dwAccessRights; }
internal OpcDaItem(OPCITEMATTRIBUTES opcItemDefinition, OpcDaGroup @group) { Group = @group; ClientHandle = opcItemDefinition.hClient; ServerHandle = opcItemDefinition.hServer; ItemId = opcItemDefinition.szItemID; RequestedDataType = TypeConverter.FromVarEnum((VarEnum)opcItemDefinition.vtRequestedDataType); CanonicalDataType = TypeConverter.FromVarEnum((VarEnum)opcItemDefinition.vtCanonicalDataType); AccessPath = opcItemDefinition.szAccessPath; IsActive = opcItemDefinition.bActive; AccessRights = (OpcDaAccessRights)opcItemDefinition.dwAccessRights; if (opcItemDefinition.pBlob != IntPtr.Zero) { Blob = new byte[opcItemDefinition.dwBlobSize]; Marshal.Copy(opcItemDefinition.pBlob, Blob, 0, Blob.Length); } }
private bool TryRemoveGroup(OpcDaGroup @group, bool rpcFailed = false) { try { ((IDisposable)@group).Dispose(); if (!rpcFailed) { As <OpcServer>().RemoveGroup(@group.ServerHandle, false); } _groups.Remove(group); OnGroupsChanged(new OpcDaServerGroupsChangedEventArgs(null, group)); return(true); } catch (Exception ex) { Log.ErrorFormat("Cannot remove group '{0}'.", ex, @group.Name); return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="OpcDaServerGroupsChangedEventArgs"/> class. /// </summary> /// <param name="added">The added groups.</param> /// <param name="removed">The removed groups.</param> public OpcDaServerGroupsChangedEventArgs(OpcDaGroup added, OpcDaGroup removed) { Added = added; Removed = removed; }