From 871c63ad684fcf4fdd1f7bc612b3581a2f990717 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 16 Oct 2018 11:06:25 +0200 Subject: [PATCH] - .NET API: added some additional wrapper code for MmsVariableSpecification functions --- dotnet/IEC61850forCSharp/MmsValue.cs | 25 ++++++++++ .../MmsVariableSpecification.cs | 48 ++++++++++++++++--- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/dotnet/IEC61850forCSharp/MmsValue.cs b/dotnet/IEC61850forCSharp/MmsValue.cs index f85b3218..fd00626f 100644 --- a/dotnet/IEC61850forCSharp/MmsValue.cs +++ b/dotnet/IEC61850forCSharp/MmsValue.cs @@ -179,6 +179,9 @@ namespace IEC61850 [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern void MmsValue_setElement(IntPtr complexValue, int index, IntPtr elementValue); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr MmsVariableSpecification_getChildValue(IntPtr self, IntPtr value, string childId); + internal IntPtr valueReference; /* reference to native MmsValue instance */ private bool responsableForDeletion; /* if .NET wrapper is responsable for the deletion of the native MmsValue instance */ @@ -864,6 +867,28 @@ namespace IEC61850 throw new MmsValueException ("Value type is not float"); } + /// + /// Gets the child value with the given name + /// + /// the child value or null if no matching child has been found. + /// path specifying the child using '.' or '$' as path element separator. + /// the variable specification to use. + public MmsValue GetChildValue(string childPath, MmsVariableSpecification specification) + { + StringBuilder childPathStr = new StringBuilder(childPath); + + childPathStr.Replace('.', '$'); + + IntPtr childPtr = MmsVariableSpecification_getChildValue(specification.self, valueReference, childPathStr.ToString()); + + if (childPtr == IntPtr.Zero) + return null; + else + { + return new MmsValue(childPtr); + } + } + public override bool Equals (object obj) { MmsValue otherValue = (MmsValue) obj; diff --git a/dotnet/IEC61850forCSharp/MmsVariableSpecification.cs b/dotnet/IEC61850forCSharp/MmsVariableSpecification.cs index 1fe97503..f0bfc250 100644 --- a/dotnet/IEC61850forCSharp/MmsVariableSpecification.cs +++ b/dotnet/IEC61850forCSharp/MmsVariableSpecification.cs @@ -26,6 +26,7 @@ using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; +using System.Text; namespace IEC61850 { @@ -39,9 +40,6 @@ namespace IEC61850 [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern void MmsVariableSpecification_destroy(IntPtr self); - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr MmsVariableSpecification_getChildValue(IntPtr self, IntPtr value, string childId); - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr MmsVariableSpecification_getNamedVariableRecursive(IntPtr variable, string nameId); @@ -63,13 +61,20 @@ namespace IEC61850 [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern int MmsVariableSpecification_getExponentWidth(IntPtr self); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern bool MmsVariableSpecification_isValueOfType(IntPtr self, IntPtr value); + internal IntPtr self; private bool responsableForDeletion; - internal MmsVariableSpecification (IntPtr self) + /* only to prevent garbage collector to destroy parent element */ + internal MmsVariableSpecification parent = null; + + internal MmsVariableSpecification (IntPtr self, MmsVariableSpecification parent) { this.self = self; this.responsableForDeletion = false; + this.parent = parent; } internal MmsVariableSpecification (IntPtr self, bool responsableForDeletion) @@ -78,6 +83,27 @@ namespace IEC61850 this.responsableForDeletion = responsableForDeletion; } + /// + /// Get a child variable specification by its name + /// + /// the varibable specification of the child, or null if no such child is existing. + /// The child name (can also be a path separating the elements with '.' or '$') + public MmsVariableSpecification GetChildByName(string name) + { + StringBuilder nameId = new StringBuilder(name); + + nameId.Replace('.', '$'); + + IntPtr varSpecPtr = MmsVariableSpecification_getNamedVariableRecursive(self, nameId.ToString()); + + if (varSpecPtr != IntPtr.Zero) + { + return new MmsVariableSpecification(varSpecPtr, this); + } + else + return null; + } + ~MmsVariableSpecification () { if (responsableForDeletion) @@ -106,7 +132,7 @@ namespace IEC61850 { if (GetType() == MmsType.MMS_ARRAY) { IntPtr varSpecPtr = MmsVariableSpecification.MmsVariableSpecification_getArrayElementSpecification(self); - return new MmsVariableSpecification(varSpecPtr); + return new MmsVariableSpecification(varSpecPtr, this); } else throw new MmsValueException ("specification is of wrong type"); @@ -127,7 +153,7 @@ namespace IEC61850 if ((index >= 0) && (index < Size ())) { IntPtr varSpecPtr = MmsVariableSpecification_getChildSpecificationByIndex(self, index); - return new MmsVariableSpecification(varSpecPtr); + return new MmsVariableSpecification(varSpecPtr, this); } else throw new MmsValueException ("Index out of bounds"); @@ -157,6 +183,16 @@ namespace IEC61850 return MmsVariableSpecification_getSize(self); } + /// + /// Determines whether the given value object matches this type + /// + /// true if the value matches this type; otherwise, false. + /// the value to test. + public bool IsValueOfType(MmsValue value) + { + return MmsVariableSpecification_isValueOfType(self, value.valueReference); + } + IEnumerator IEnumerable.GetEnumerator () { return new MmsVariableSpecificationEnumerator (this);