diff --git a/dotnet/IEC61850forCSharp/MmsValue.cs b/dotnet/IEC61850forCSharp/MmsValue.cs
index 889126f6..f85b3218 100644
--- a/dotnet/IEC61850forCSharp/MmsValue.cs
+++ b/dotnet/IEC61850forCSharp/MmsValue.cs
@@ -136,6 +136,15 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsValue_newVisibleString(string value);
+ [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr MmsValue_createArray(IntPtr elementType, int size);
+
+ [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr MmsValue_createEmptyArray(int size);
+
+ [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
+ static extern IntPtr MmsValue_createEmptyStructure(int size);
+
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsValue_newOctetString(int size, int maxSize);
@@ -164,9 +173,12 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern ulong MmsValue_getBinaryTimeAsUtcMs (IntPtr self);
- [DllImport ("iec61850", CallingConvention=CallingConvention.Cdecl)]
+ [DllImport("iec61850", CallingConvention=CallingConvention.Cdecl)]
static extern int MmsValue_getDataAccessError(IntPtr self);
+ [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
+ static extern void MmsValue_setElement(IntPtr complexValue, int index, IntPtr elementValue);
+
internal IntPtr valueReference; /* reference to native MmsValue instance */
private bool responsableForDeletion; /* if .NET wrapper is responsable for the deletion of the native MmsValue instance */
@@ -214,6 +226,10 @@ namespace IEC61850
valueReference = MmsValue_newIntegerFromInt64 (value);
}
+ ///
+ /// Create a new instance of type MMS_VISIBLE_STRING.
+ ///
+ /// Value.
public MmsValue (string value)
{
valueReference = MmsValue_newVisibleString(value);
@@ -270,6 +286,53 @@ namespace IEC61850
this.setOctetString (octetString);
}
+ ///
+ /// Create a new MmsValue instance of type MMS_ARRAY. Array elements have the fiven type
+ ///
+ /// the newly created array
+ /// array element type
+ /// number of array elements
+ public static MmsValue NewArray(MmsVariableSpecification elementType, int size)
+ {
+ if (size < 1)
+ throw new MmsValueException ("array requires at least one element");
+
+ IntPtr newValue = MmsValue_createArray (elementType.self, size);
+
+ return new MmsValue (newValue, true);
+ }
+
+ ///
+ /// Create a new MmsValue instance of type MMS_ARRAY. Array elements are not initialized!
+ ///
+ /// the newly created array
+ /// number of array elements
+ public static MmsValue NewEmptyArray(int size)
+ {
+ if (size < 1)
+ throw new MmsValueException ("array requires at least one element");
+
+ IntPtr newValue = MmsValue_createEmptyArray (size);
+
+ return new MmsValue (newValue, true);
+ }
+
+ ///
+ /// Create a new MmsValue instance of type MMS_STRUCTURE. Structure elements are not initialized!
+ ///
+ /// the newly created array
+ /// number of structure elements
+ public static MmsValue NewEmptyStructure(int size)
+ {
+ if (size < 1)
+ throw new MmsValueException ("structure requires at least one element");
+
+ IntPtr newValue = MmsValue_createEmptyStructure (size);
+
+ return new MmsValue (newValue, true);
+ }
+
+
///
/// Create a new MmsValue instance of type MMS_BINARY_TIME
///
@@ -427,6 +490,29 @@ namespace IEC61850
throw new MmsValueException ("Value is of wrong type");
}
+ ///
+ /// Sets the element of an array of structure
+ ///
+ /// index of the element starting with 0
+ /// MmsValue instance that will be used as element value
+ /// This exception is thrown if the value has the wrong type.
+ /// This exception is thrown if the index is out of range.
+ public void SetElement(int index, MmsValue elementValue)
+ {
+ MmsType elementType = GetType ();
+
+ if ((elementType == MmsType.MMS_ARRAY) || (elementType == MmsType.MMS_STRUCTURE)) {
+
+ if ((index >= 0) && (index < Size ())) {
+ MmsValue_setElement (valueReference, index, elementValue.valueReference);
+
+ } else
+ throw new MmsValueException ("Index out of bounds");
+
+ } else
+ throw new MmsValueException ("Value is of wrong type");
+
+ }
public MmsDataAccessError GetDataAccessError ()
{
diff --git a/dotnet/IEC61850forCSharp/MmsVariableSpecification.cs b/dotnet/IEC61850forCSharp/MmsVariableSpecification.cs
index 159f10e6..1fe97503 100644
--- a/dotnet/IEC61850forCSharp/MmsVariableSpecification.cs
+++ b/dotnet/IEC61850forCSharp/MmsVariableSpecification.cs
@@ -63,7 +63,7 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern int MmsVariableSpecification_getExponentWidth(IntPtr self);
- private IntPtr self;
+ internal IntPtr self;
private bool responsableForDeletion;
internal MmsVariableSpecification (IntPtr self)
diff --git a/dotnet/tests/Test.cs b/dotnet/tests/Test.cs
index ce22168f..d0bb0e40 100644
--- a/dotnet/tests/Test.cs
+++ b/dotnet/tests/Test.cs
@@ -105,6 +105,50 @@ namespace tests
Assert.AreEqual (val.ToFloat (), (float)0.1234);
}
+ [Test()]
+ 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);
+ }
+
+ [Test()]
+ 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);
+ }
+
[Test ()]
public void Timestamps()
{