From 18cc25f1ff865d2e481142eaedb15c5145ab222e Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 16 Oct 2018 19:58:26 +0200 Subject: [PATCH] - added C# example code for client side setting group handling --- .../client_example_setting_groups/Program.cs | 78 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 27 +++++++ .../client_example_setting_groups.csproj | 44 +++++++++++ dotnet/dotnet.sln | 6 ++ dotnet/tests/Test.cs | 5 +- 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 dotnet/client_example_setting_groups/Program.cs create mode 100644 dotnet/client_example_setting_groups/Properties/AssemblyInfo.cs create mode 100644 dotnet/client_example_setting_groups/client_example_setting_groups.csproj diff --git a/dotnet/client_example_setting_groups/Program.cs b/dotnet/client_example_setting_groups/Program.cs new file mode 100644 index 00000000..de24ad92 --- /dev/null +++ b/dotnet/client_example_setting_groups/Program.cs @@ -0,0 +1,78 @@ +using System; +using IEC61850.Client; +using IEC61850.Common; + +namespace client_examples_setting_groups +{ + /// + /// This class is intended to show how to use setting groups from the client side. + /// It works with server_example_setting_groups. + /// + class SettingGroupsClientExample + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + + IedConnection con = new IedConnection (); + + string hostname; + + if (args.Length > 0) + hostname = args[0]; + else + hostname = "127.0.0.1"; + + int port = 102; + + if (args.Length > 1) + port = Int32.Parse(args [1]); + + Console.WriteLine("Connect to " + hostname); + + try + { + con.Connect(hostname, port); + + /* Get variable specification of the SGCB (optional) */ + MmsVariableSpecification sgcbVarSpec = con.GetVariableSpecification("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP); + + /* Read SGCB */ + MmsValue sgcbVal = con.ReadValue("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP); + + Console.WriteLine("NumOfSG: {0}", sgcbVal.GetChildValue("NumOfSG", sgcbVarSpec).ToString()); + Console.WriteLine("ActSG: {0}", sgcbVal.GetChildValue("ActSG", sgcbVarSpec).ToString()); + Console.WriteLine("EditSG: {0}", sgcbVal.GetChildValue("EditSG", sgcbVarSpec).ToString()); + Console.WriteLine("CnfEdit: {0}", sgcbVal.GetChildValue("CnfEdit", sgcbVarSpec).ToString()); + + /* Set active setting group */ + con.WriteValue("DEMOPROT/LLN0.SGCB.ActSG", FunctionalConstraint.SP, new MmsValue((uint) 2)); + + /* Set edit setting group */ + con.WriteValue("DEMOPROT/LLN0.SGCB.EditSG", FunctionalConstraint.SP, new MmsValue((uint) 1)); + + /* Change a setting group value */ + con.WriteValue("DEMOPROT/PTOC1.StrVal.setMag.f", FunctionalConstraint.SE, new MmsValue(1.0f)); + + /* Confirm new setting group values */ + con.WriteValue("DEMOPROT/LLN0.SGCB.CnfEdit", FunctionalConstraint.SP, new MmsValue(true)); + + /* Read SGCB */ + con.ReadValue("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP); + + Console.WriteLine("ActSG: {0}",sgcbVal.GetChildValue("ActSG", sgcbVarSpec).ToString()); + + + con.Abort(); + } + catch (IedConnectionException e) + { + Console.WriteLine(e.Message); + } + + // release all resources - do NOT use the object after this call!! + con.Dispose (); + + } + } +} diff --git a/dotnet/client_example_setting_groups/Properties/AssemblyInfo.cs b/dotnet/client_example_setting_groups/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..7fc4366c --- /dev/null +++ b/dotnet/client_example_setting_groups/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("client-example-setting-group")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("mzillgit")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/dotnet/client_example_setting_groups/client_example_setting_groups.csproj b/dotnet/client_example_setting_groups/client_example_setting_groups.csproj new file mode 100644 index 00000000..9030d71b --- /dev/null +++ b/dotnet/client_example_setting_groups/client_example_setting_groups.csproj @@ -0,0 +1,44 @@ + + + + Debug + AnyCPU + {0DA95476-B149-450B-AC36-01CEECFC1A43} + Exe + clientexamplesettinggroup + client-example-setting-group + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + + + full + true + bin\Release + prompt + 4 + true + + + + + + + + + + + + {C35D624E-5506-4560-8074-1728F1FA1A4D} + IEC61850.NET + + + \ No newline at end of file diff --git a/dotnet/dotnet.sln b/dotnet/dotnet.sln index ba1be6f4..97feef4c 100644 --- a/dotnet/dotnet.sln +++ b/dotnet/dotnet.sln @@ -44,6 +44,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sv_subscriber", "sv_subscri EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tls_server_example", "tls_server_example\tls_server_example.csproj", "{B63F7A81-1D3A-4F2F-A7C2-D6F77E5BD307}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "client_example_setting_groups", "client_example_setting_groups\client_example_setting_groups.csproj", "{0DA95476-B149-450B-AC36-01CEECFC1A43}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -54,6 +56,10 @@ Global {0BECEC77-2315-4B95-AFF9-E6007E644BBF}.Debug|Any CPU.Build.0 = Debug|Any CPU {0BECEC77-2315-4B95-AFF9-E6007E644BBF}.Release|Any CPU.ActiveCfg = Release|Any CPU {0BECEC77-2315-4B95-AFF9-E6007E644BBF}.Release|Any CPU.Build.0 = Release|Any CPU + {0DA95476-B149-450B-AC36-01CEECFC1A43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DA95476-B149-450B-AC36-01CEECFC1A43}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DA95476-B149-450B-AC36-01CEECFC1A43}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DA95476-B149-450B-AC36-01CEECFC1A43}.Release|Any CPU.Build.0 = Release|Any CPU {1285372C-2E62-494A-A661-8D5D3873318C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1285372C-2E62-494A-A661-8D5D3873318C}.Debug|Any CPU.Build.0 = Debug|Any CPU {1285372C-2E62-494A-A661-8D5D3873318C}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/dotnet/tests/Test.cs b/dotnet/tests/Test.cs index d0bb0e40..d1c38871 100644 --- a/dotnet/tests/Test.cs +++ b/dotnet/tests/Test.cs @@ -276,7 +276,10 @@ namespace tests [Test ()] public void AccessDataModelClientServer() { - IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile ("../../model.cfg"); + IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); + + + ModelNode ind1 = iedModel.GetModelNodeByShortObjectReference ("GenericIO/GGIO1.Ind1.stVal");