public void ControlWriteAccessComplexDAToServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model2.cfg"); IEC61850.Server.DataAttribute setAnVal_setMag = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/LLN0.SetAnVal.setMag"); IedServer iedServer = new IedServer(iedModel); int handlerCalled = 0; MmsValue receivedValue = null; iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY); iedServer.HandleWriteAccessForComplexAttribute(setAnVal_setMag, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { receivedValue = value; handlerCalled++; return(MmsDataAccessError.SUCCESS); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); MmsValue complexValue = MmsValue.NewEmptyStructure(1); complexValue.SetElement(0, new MmsValue((float)1.0)); connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag", FunctionalConstraint.SP, complexValue); Assert.NotNull(receivedValue); Assert.AreEqual(MmsType.MMS_STRUCTURE, receivedValue.GetType()); Assert.AreEqual(1.0, receivedValue.GetElement(0).ToFloat()); receivedValue.Dispose(); receivedValue = null; connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag.f", FunctionalConstraint.SP, new MmsValue((float)2.0)); Assert.NotNull(receivedValue); Assert.AreEqual(MmsType.MMS_FLOAT, receivedValue.GetType()); Assert.AreEqual(2.0, receivedValue.ToFloat()); connection.Abort(); iedServer.Stop(); iedServer.Dispose(); }
public void MmsValueArray() { MmsValue val = MmsValue.NewEmptyArray(3); val.SetElement(0, new MmsValue(1)); val.SetElement(1, new MmsValue(2)); val.SetElement(2, new MmsValue(3)); Assert.AreEqual(val.GetType(), MmsType.MMS_ARRAY); Assert.AreEqual(val.Size(), 3); MmsValue elem0 = val.GetElement(0); Assert.AreEqual(elem0.GetType(), MmsType.MMS_INTEGER); Assert.AreEqual(elem0.ToInt32(), 1); MmsValue elem2 = val.GetElement(2); Assert.AreEqual(elem2.GetType(), MmsType.MMS_INTEGER); Assert.AreEqual(elem2.ToInt32(), 3); val.SetElement(0, null); val.SetElement(1, null); val.SetElement(2, null); }
public void TestGetMMSType() { var expected = MmsType.MMS_BOOLEAN; var mmsValue = new MmsValue(true); var actual = mmsValue.GetType(); Assert.Equal(expected, actual); }
void mmsValueInit() { sDataAttribute sda = (sDataAttribute)Marshal.PtrToStructure(self, typeof(sDataAttribute)); if (sda.mmsValue != IntPtr.Zero) { mmsValue = new MmsValue(sda.mmsValue); mmsType = mmsValue.GetType(); } }
/// <summary>Read the value of a basic data attribute (BDA) of type integer (MMS_INTEGER).</summary> /// <description>This function should also be used if enumerations are beeing read. Because /// enumerations are mapped to integer types for the MMS mapping</description> /// <param name="objectReference">The object reference of a BDA.</param> /// <param name="fc">The functional constraint (FC) of the object</param> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> public Int64 ReadIntegerValue(string objectReference, FunctionalConstraint fc) { var mmsValuePtr = readObjectInternal(objectReference, fc); var mmsValue = new MmsValue(mmsValuePtr, true); if (mmsValue.GetType() == MmsType.MMS_INTEGER) { return(mmsValue.ToInt64()); } else { throw new IedConnectionException("Result is not of type integer (MMS_INTEGER)", 0); } }
/// <summary>Read the value of a basic data attribute (BDA) of type timestamp (MMS_UTC_TIME).</summary> /// <param name="objectReference">The object reference of a BDA.</param> /// <param name="fc">The functional constraint (FC) of the object</param> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> public UInt64 ReadTimestampValue(string objectReference, FunctionalConstraint fc) { var mmsValuePtr = readObjectInternal(objectReference, fc); var mmsValue = new MmsValue(mmsValuePtr, true); if (mmsValue.GetType() == MmsType.MMS_UTC_TIME) { return(mmsValue.GetUtcTimeInMs()); } else { throw new IedConnectionException("Result is not of type timestamp (MMS_UTC_TIME)", 0); } }
public void MmsValueStructure() { MmsValue val = MmsValue.NewEmptyStructure(2); val.SetElement(0, new MmsValue(true)); val.SetElement(1, MmsValue.NewBitString(10)); Assert.AreEqual(val.GetType(), MmsType.MMS_STRUCTURE); Assert.AreEqual(val.Size(), 2); MmsValue elem0 = val.GetElement(0); Assert.AreEqual(elem0.GetType(), MmsType.MMS_BOOLEAN); Assert.AreEqual(elem0.GetBoolean(), true); MmsValue elem1 = val.GetElement(1); Assert.AreEqual(elem1.GetType(), MmsType.MMS_BIT_STRING); }
public void ReadNonExistingObject() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IedServer iedServer = new IedServer(iedModel); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); MmsValue value = connection.ReadValue("simpleIOGenericIO/GGIO1.SPCSO1.stVal", FunctionalConstraint.MX); Assert.IsNotNull(value); Assert.AreEqual(MmsType.MMS_DATA_ACCESS_ERROR, value.GetType()); iedServer.Stop(); iedServer.Destroy(); }
public static void Main(string[] args) { IedConnection con = new IedConnection(); string hostname; if (args.Length > 0) { hostname = args[0]; } else { hostname = "10.0.2.2"; } Console.WriteLine("Connect to " + hostname); try { con.Connect(hostname, 102); 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(); }
/// <summary>Read the value of a basic data attribute (BDA) of type integer (MMS_INTEGER).</summary> /// <description>This function should also be used if enumerations are beeing read. Because /// enumerations are mapped to integer types for the MMS mapping</description> /// <param name="objectReference">The object reference of a BDA.</param> /// <param name="fc">The functional constraint (FC) of the object</param> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> public Int64 ReadIntegerValue(string objectReference, FunctionalConstraint fc) { var mmsValuePtr = readObjectInternal (objectReference, fc); var mmsValue = new MmsValue (mmsValuePtr, true); if (mmsValue.GetType () == MmsType.MMS_INTEGER) return mmsValue.ToInt64 (); else throw new IedConnectionException ("Result is not of type integer (MMS_INTEGER)", 0); }
/// <summary>Read the value of a basic data attribute (BDA) of type timestamp (MMS_UTC_TIME).</summary> /// <param name="objectReference">The object reference of a BDA.</param> /// <param name="fc">The functional constraint (FC) of the object</param> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> public UInt64 ReadTimestampValue(string objectReference, FunctionalConstraint fc) { var mmsValuePtr = readObjectInternal (objectReference, fc); var mmsValue = new MmsValue (mmsValuePtr, true); if (mmsValue.GetType () == MmsType.MMS_UTC_TIME) return mmsValue.GetUtcTimeInMs (); else throw new IedConnectionException ("Result is not of type timestamp (MMS_UTC_TIME)", 0); }
public ResultSingleModel ReadSingleGroup(string hostip, Int32 port, string FC, string vargroup) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //exctract fc data_extract dataExtract = new data_extract(); var FunctionCode = dataExtract.ExtractFC(FC); //read group MmsValue mmsresult = con.ReadValue(vargroup, FunctionCode); //con close con.Abort(); //result list dynamic ValueTuple = mmsresult; Read_Result listresult = null; Int16 Quality; DateTimeOffset Timestamp; List <dynamic> valueArray = new List <dynamic>(); if (mmsresult.GetType() == MmsType.MMS_STRUCTURE) { if (mmsresult.Size() == 4) { ValueTuple = dataExtract.ExtractValue(mmsresult.GetElement(0)); Quality = dataExtract.ExtractValue(mmsresult.GetElement(2)); Timestamp = dataExtract.ExtractValue(mmsresult.GetElement(3)); } else { ValueTuple = dataExtract.ExtractValue(mmsresult.GetElement(0)); Quality = dataExtract.ExtractValue(mmsresult.GetElement(1)); Timestamp = dataExtract.ExtractValue(mmsresult.GetElement(2)); } listresult = new Read_Result { Address = vargroup, Value = ValueTuple, Quality = Quality, Timestamp = Timestamp }; } ResultSingleModel result = new ResultSingleModel() { data = listresult, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultSingleModel result = new ResultSingleModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy instance con.Dispose(); //error result return(result); } }
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(); }
public static void Main(string[] args) { 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); 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()); /* read multiple variables (WARNING: this is not IEC 61850 standard compliant but might * be supported by most servers). */ MmsConnection mmsConnection = con.GetMmsConnection(); MmsValue result = mmsConnection.ReadMultipleVariables("simpleIOGenericIO", new List <string>() { "GGIO1$ST$Ind1", "GGIO1$ST$Ind1", "GGIO1$ST$Ind1", "GGIO1$ST$Ind1" }); Console.WriteLine(result.ToString()); 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(); }