public static void Main(string[] args) { bool running = true; /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg"); if (iedModel == null) { Console.WriteLine("No valid data model found!"); return; } DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); TLSConfiguration tlsConfig = new TLSConfiguration(); tlsConfig.SetOwnCertificate(new X509Certificate2("server.cer")); tlsConfig.SetOwnKey("server-key.pem", null); // Add a CA certificate to check the certificate provided by the server - not required when ChainValidation == false tlsConfig.AddCACertificate(new X509Certificate2("root.cer")); // Check if the certificate is signed by a provided CA tlsConfig.ChainValidation = true; // Check that the shown server certificate is in the list of allowed certificates tlsConfig.AllowOnlyKnownCertificates = false; IedServer iedServer = new IedServer(iedModel, tlsConfig); iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean(); if (val) { Console.WriteLine("received binary control command: on"); } else { Console.WriteLine("received binary control command: off"); } return(ControlHandlerResult.OK); }, null); iedServer.Start(); Console.WriteLine("Server started"); GC.Collect(); DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f"); DataAttribute ggio1AnIn1T = (DataAttribute)ggio1AnIn1.GetChild("t"); float floatVal = 1.0f; while (running) { floatVal += 1f; iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now)); iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal); Thread.Sleep(100); } iedServer.Stop(); Console.WriteLine("Server stopped"); iedServer.Destroy(); }
public static void Main(string[] args) { TLSConfiguration tlsConfig = new TLSConfiguration(); tlsConfig.SetOwnCertificate(new X509Certificate2("client1.cer")); tlsConfig.SetOwnKey("client1-key.pem", null); // Add a CA certificate to check the certificate provided by the server - not required when ChainValidation == false tlsConfig.AddCACertificate(new X509Certificate2("root.cer")); // Check if the certificate is signed by a provided CA tlsConfig.ChainValidation = true; // Check that the shown server certificate is in the list of allowed certificates tlsConfig.AllowOnlyKnownCertificates = false; IedConnection con = new IedConnection(tlsConfig); string hostname; if (args.Length > 0) { hostname = args[0]; } else { hostname = "127.0.0.1"; } int port = -1; if (args.Length > 1) { port = Int32.Parse(args [1]); } Console.WriteLine("Connect to " + hostname); try { con.Connect(hostname, port); List <string> serverDirectory = con.GetServerDirectory(false); foreach (string entry in serverDirectory) { Console.WriteLine("LD: " + entry); } List <string> lnDirectory = con.GetLogicalNodeDirectory("simpleIOGenericIO/LLN0", ACSIClass.ACSI_CLASS_DATA_SET); foreach (string entry in lnDirectory) { Console.WriteLine("Dataset: " + entry); } string vendor = con.ReadStringValue("simpleIOGenericIO/LLN0.NamPlt.vendor", FunctionalConstraint.DC); Console.WriteLine("Vendor: " + vendor); /* read FCDO */ MmsValue value = con.ReadValue("simpleIOGenericIO/GGIO1.AnIn1", FunctionalConstraint.MX); if (value.GetType() == MmsType.MMS_STRUCTURE) { Console.WriteLine("Value is of complex type"); for (int i = 0; i < value.Size(); i++) { Console.WriteLine(" element: " + value.GetElement(i).GetType()); if (value.GetElement(i).GetType() == MmsType.MMS_UTC_TIME) { Console.WriteLine(" -> " + value.GetElement(i).GetUtcTimeAsDateTimeOffset()); } } } DataSet dataSet = con.ReadDataSetValues("simpleIOGenericIO/LLN0.Events", null); Console.WriteLine("Read data set " + dataSet.GetReference()); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } System.Threading.Thread.Sleep(2000); // release all resources - do NOT use the object after this call!! con.Dispose(); }