- .NET API: Added array/structure handlung functions to MmsValue

pull/72/head
Michael Zillgith 7 years ago
parent 71493036dc
commit 4d8e256967

@ -136,6 +136,15 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsValue_newVisibleString(string value); 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)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsValue_newOctetString(int size, int maxSize); static extern IntPtr MmsValue_newOctetString(int size, int maxSize);
@ -164,9 +173,12 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern ulong MmsValue_getBinaryTimeAsUtcMs (IntPtr self); static extern ulong MmsValue_getBinaryTimeAsUtcMs (IntPtr self);
[DllImport ("iec61850", CallingConvention=CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention=CallingConvention.Cdecl)]
static extern int MmsValue_getDataAccessError(IntPtr self); 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 */ internal IntPtr valueReference; /* reference to native MmsValue instance */
private bool responsableForDeletion; /* if .NET wrapper is responsable for the deletion of the 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); valueReference = MmsValue_newIntegerFromInt64 (value);
} }
/// <summary>
/// Create a new <see cref="IEC61850.Common.MmsValue"/> instance of type MMS_VISIBLE_STRING.
/// </summary>
/// <param name="value">Value.</param>
public MmsValue (string value) public MmsValue (string value)
{ {
valueReference = MmsValue_newVisibleString(value); valueReference = MmsValue_newVisibleString(value);
@ -270,6 +286,53 @@ namespace IEC61850
this.setOctetString (octetString); this.setOctetString (octetString);
} }
/// <summary>
/// Create a new MmsValue instance of type MMS_ARRAY. Array elements have the fiven type
/// </summary>
/// <returns>the newly created array</returns>
/// <param name="elementType">array element type</param>
/// <param name="size">number of array elements</param>
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);
}
/// <summary>
/// Create a new MmsValue instance of type MMS_ARRAY. Array elements are not initialized!
/// </summary>
/// <returns>the newly created array</returns>
/// <param name="size">number of array elements</param>
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);
}
/// <summary>
/// Create a new MmsValue instance of type MMS_STRUCTURE. Structure elements are not initialized!
/// </summary>
/// <returns>the newly created array</returns>
/// <param name="size">number of structure elements</param>
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);
}
/// <summary> /// <summary>
/// Create a new MmsValue instance of type MMS_BINARY_TIME /// Create a new MmsValue instance of type MMS_BINARY_TIME
/// </summary> /// </summary>
@ -427,6 +490,29 @@ namespace IEC61850
throw new MmsValueException ("Value is of wrong type"); throw new MmsValueException ("Value is of wrong type");
} }
/// <summary>
/// Sets the element of an array of structure
/// </summary>
/// <param name="index">index of the element starting with 0</param>
/// <param name="elementValue">MmsValue instance that will be used as element value</param>
/// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception>
/// <exception cref="MmsValueException">This exception is thrown if the index is out of range.</exception>
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 () public MmsDataAccessError GetDataAccessError ()
{ {

@ -63,7 +63,7 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern int MmsVariableSpecification_getExponentWidth(IntPtr self); static extern int MmsVariableSpecification_getExponentWidth(IntPtr self);
private IntPtr self; internal IntPtr self;
private bool responsableForDeletion; private bool responsableForDeletion;
internal MmsVariableSpecification (IntPtr self) internal MmsVariableSpecification (IntPtr self)

@ -105,6 +105,50 @@ namespace tests
Assert.AreEqual (val.ToFloat (), (float)0.1234); 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 ()] [Test ()]
public void Timestamps() public void Timestamps()
{ {

Loading…
Cancel
Save