From cc4f25d1228fee0ea5b4afcc10e1cf129494e331 Mon Sep 17 00:00:00 2001 From: Maxson Ramon dos Anjos Medeiros Date: Wed, 16 Jul 2025 18:06:16 +0200 Subject: [PATCH] -> Add wrapper for GetActiveSettingGroupChangedHandler --- dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs | 14 ++++++++ .../server_example_access_control/Program.cs | 32 ++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs index 6d237e28..98779da5 100644 --- a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs +++ b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs @@ -2461,6 +2461,15 @@ namespace IEC61850 [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] public static extern void IedServer_setActiveSettingGroupChangedHandler(IntPtr self, IntPtr sgcb, ActiveSettingGroupChangedHandler handler, IntPtr parameter); + /// + /// Get the active setting group number + /// + /// the instance of IedServer to operate on + /// the handle of the setting group control block of the setting group + /// the number of the active setting group + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + public static extern uint IedServer_getActiveSettingGroup(IntPtr self, IntPtr sgcb); + /// /// Set the callback handler for the SetEditSG event /// @@ -2920,6 +2929,11 @@ namespace IEC61850 } } + public int GetActiveSettingGroupChangedHandler(SettingGroupControlBlock settingGroupControlBlock) + { + return Convert.ToInt32(IedServer_getActiveSettingGroup(self, settingGroupControlBlock.self)); + } + private bool InternalActiveSettingGroupChangedImplementation(IntPtr parameter, IntPtr sgcb, uint newActSg, IntPtr connection) { if (sgcb != IntPtr.Zero && connection != IntPtr.Zero) diff --git a/dotnet/server_example_access_control/Program.cs b/dotnet/server_example_access_control/Program.cs index 7a01724f..630c437e 100644 --- a/dotnet/server_example_access_control/Program.cs +++ b/dotnet/server_example_access_control/Program.cs @@ -20,7 +20,7 @@ namespace server_access_control { class MainClass { - struct PTOC1Settings + class PTOC1Settings { public float strVal; public int opDlTmms; @@ -281,6 +281,8 @@ namespace server_access_control { Console.WriteLine("Switch to setting group "+ newActSg +"\n"); + LoadActiveSgValues(Convert.ToInt32(newActSg)); + return true; } @@ -296,6 +298,34 @@ namespace server_access_control void editSGConfirmationHandler(object parameter, SettingGroupControlBlock sgcb, uint editSg) { Console.WriteLine("Received edit sg confirm for sg " + editSg + "\n"); + + int edit = Convert.ToInt32(editSg); + + DataObject strVal = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/PTOC1.StrVal"); + DataAttribute setMagF = strVal.GetChildWithFc("setMag.f", FunctionalConstraint.SE); + MmsValue setMagFValue = iedServer.GetAttributeValue(setMagF); + + DataObject opDlTmms = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/PTOC1.OpDlTmms"); + DataAttribute setVal = opDlTmms.GetChildWithFc("setVal", FunctionalConstraint.SE); + MmsValue setValValue = iedServer.GetAttributeValue(setVal); + + DataObject rsDlTmms = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/PTOC1.RsDlTmms"); + DataAttribute rsDlTmmsSetVal = rsDlTmms.GetChildWithFc("setVal", FunctionalConstraint.SE); + MmsValue rsDlTmmsSetValValue = iedServer.GetAttributeValue(rsDlTmmsSetVal); + + DataObject rstTms = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/PTOC1.RstTms"); + DataAttribute rstTmsSetVal = rstTms.GetChildWithFc("setVal", FunctionalConstraint.SE); + MmsValue rstTmsSetValVaue = iedServer.GetAttributeValue(rstTmsSetVal); + + ptoc1Settings[edit - 1].strVal = setMagFValue.ToFloat(); + ptoc1Settings[edit - 1].opDlTmms = setValValue.ToInt32(); + ptoc1Settings[edit - 1].rsDlTmms = rsDlTmmsSetValValue.ToInt32(); + ptoc1Settings[edit - 1].rstTms = rsDlTmmsSetValValue.ToInt32(); + + if (iedServer.GetActiveSettingGroupChangedHandler(sgcb) == edit) + { + LoadActiveSgValues(edit); + } } iedServer.SetActiveSettingGroupChangedHandler(activeSGChangedHandler, settingGroupControlBlock, null);