From 66f571f03de7002df8f14d3205f23c06570c59ec Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Sat, 8 Dec 2018 11:13:12 +0100 Subject: [PATCH] - .NET API: add GetFileDirectoryEx function --- dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs | 45 ++++++++++++++++++- dotnet/files/FileServicesExample.cs | 8 +++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs b/dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs index 935eef56..b283db4c 100644 --- a/dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs +++ b/dotnet/IEC61850forCSharp/IEC61850ClientAPI.cs @@ -436,7 +436,11 @@ namespace IEC61850 static extern IntPtr MmsConnection_getIsoConnectionParameters(IntPtr mmsConnection); [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr IedConnection_getFileDirectory(IntPtr self, out int error, string directoryName); + static extern IntPtr IedConnection_getFileDirectory(IntPtr self, out int error, string directoryName); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr IedConnection_getFileDirectoryEx(IntPtr self, out int error, string directoryName, string continueAfter, + [MarshalAs(UnmanagedType.I1)] out bool moreFollows); [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern void IedConnection_deleteFile(IntPtr self, out int error, string fileName); @@ -1202,7 +1206,44 @@ namespace IEC61850 LinkedList_destroyStatic(fileEntryList); return fileDirectory; - } + } + + /// Read the content of a file directory. - single request version + /// The name of the directory. + /// The last directory when request is a continuation, or null otherwise + /// true, when more files are available, false otherwise + /// This exception is thrown if there is a connection or service error + public List GetFileDirectoryEx(string directoryName, string continueAfter, out bool moreFollows) + { + int error; + + IntPtr fileEntryList = IedConnection_getFileDirectoryEx(connection, out error, directoryName, continueAfter, out moreFollows); + + if (error != 0) + throw new IedConnectionException("Reading file directory failed", error); + + List fileDirectory = new List(); + + IntPtr element = LinkedList_getNext(fileEntryList); + + while (element != IntPtr.Zero) + { + IntPtr elementData = LinkedList_getData(element); + + FileDirectoryEntry entry = new FileDirectoryEntry(elementData); + + fileDirectory.Add(entry); + + FileDirectoryEntry_destroy(elementData); + + element = LinkedList_getNext(element); + } + + LinkedList_destroyStatic(fileEntryList); + + return fileDirectory; + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool InternalIedClientGetFileHandler(IntPtr parameter, IntPtr buffer, UInt32 bytesRead); diff --git a/dotnet/files/FileServicesExample.cs b/dotnet/files/FileServicesExample.cs index f77743fc..20cc1910 100644 --- a/dotnet/files/FileServicesExample.cs +++ b/dotnet/files/FileServicesExample.cs @@ -15,7 +15,9 @@ namespace files { public static void printFiles (IedConnection con, string prefix, string parent) { - List files = con.GetFileDirectory (parent); + bool moreFollows = false; + + List files = con.GetFileDirectoryEx (parent, null, out moreFollows); foreach (FileDirectoryEntry file in files) { Console.WriteLine (prefix + file.GetFileName () + "\t" + file.GetFileSize () + "\t" + @@ -26,6 +28,8 @@ namespace files } } + if (moreFollows) + Console.WriteLine("-- MORE FILE AVAILABLE --"); } static bool getFileHandler (object parameter, byte[] data) @@ -48,7 +52,7 @@ namespace files if (args.Length > 0) hostname = args [0]; else - hostname = "10.0.2.2"; + hostname = "127.0.0.1"; Console.WriteLine ("Connect to " + hostname);