开发报警网格 NetLogic
创建用于填充报警网格的 NetLogic。
小贴士:
可以使用预先配置的报警网格,而无需从头开始创建。有关更多信息,请选择 ,然后选择 。
模板库
先决条件
设置默认外部代码编辑器。请参见设置默认代码编辑器。
- 在项目视图窗格中,右键单击AlarmGridPane,然后选择 。
- 将光标悬停在 NetLogic 上,选择 并输入AlarmsGridNetLogic
- 双击 NetLogic。外部代码编辑器将打开。
- 使用以下代码替换现有代码:#region StandardUsing using System; using FTOptix.Core; using FTOptix.CoreBase; using FTOptix.HMIProject; using UAManagedCore; using OpcUa = UAManagedCore.OpcUa; using FTOptix.NetLogic; using FTOptix.OPCUAServer; using FTOptix.UI; using FTOptix.Alarm; #endregion public class AlarmsGridNetLogic : FTOptix.NetLogic.BaseNetLogic { public override void Start() { alarmsDatagrid = Owner.Children.Get<DataGrid>("AlarmsGrid"); alarmsDatagridModel = alarmsDatagrid.Children.GetVariable("Model"); affinityId = alarmsDatagrid.Context.AssignAffinityId(); try { RegisterObserverOnSessionLocaleIdChanged(alarmsDatagrid.Context); } catch (NullReferenceException){} } public override void Stop() { if (localeIdsRegistration != null) { localeIdsRegistration.Dispose(); localeIdsRegistration = null; } if (localeIdChangedObserver != null) localeIdChangedObserver = null; } public void RegisterObserverOnSessionLocaleIdChanged(IContext context) { var currentSessionLocaleIds = context.Sessions.CurrentSessionInfo.SessionObject.Children["ActualLocaleIds"]; localeIdChangedObserver = new CallbackVariableChangeObserver((IUAVariable variable, UAValue newValue, UAValue oldValue, uint[] _, ulong __) => { //reset datagrid model variable to trigger locale changed event var dynamicLink = alarmsDatagridModel.GetVariable("DynamicLink"); if (dynamicLink == null) return; string dynamicLinkValue = dynamicLink.Value; dynamicLink.Value = string.Empty; dynamicLink.Value = dynamicLinkValue; }); localeIdsRegistration = currentSessionLocaleIds.RegisterEventObserver( localeIdChangedObserver, EventType.VariableValueChanged, affinityId); } IEventRegistration localeIdsRegistration; IEventObserver localeIdChangedObserver; uint affinityId; DataGrid alarmsDatagrid; IUAVariable alarmsDatagridModel; }
- 保存代码。
提供反馈