diff --git a/dotnet/IEC61850forCSharp/IEC61850.NET.csproj b/dotnet/IEC61850forCSharp/IEC61850.NET.csproj index 750d6a4b..78b3cbcd 100644 --- a/dotnet/IEC61850forCSharp/IEC61850.NET.csproj +++ b/dotnet/IEC61850forCSharp/IEC61850.NET.csproj @@ -7,8 +7,6 @@ Library iec61850dotnet iec61850dotnet - 8.0.30703 - 2.0 true @@ -52,6 +50,7 @@ + \ No newline at end of file diff --git a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs index e8d90bc3..4b95c19e 100644 --- a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs +++ b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs @@ -561,6 +561,9 @@ namespace IEC61850 [DllImport ("iec61850", CallingConvention=CallingConvention.Cdecl)] static extern IntPtr IedServer_create(IntPtr modelRef); + [DllImport ("iec61850", CallingConvention=CallingConvention.Cdecl)] + static extern IntPtr IedServer_createWithConfig(IntPtr modelRef, IntPtr tlsConfiguration, IntPtr serverConfiguratio); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern void IedServer_setLocalIpAddress(IntPtr self, string localIpAddress); @@ -791,6 +794,16 @@ namespace IEC61850 self = IedServer_create(iedModel.self); } + public IedServer(IedModel iedModel, IedServerConfig config) + { + IntPtr nativeConfig = IntPtr.Zero; + + if (config != null) + nativeConfig = config.self; + + self = IedServer_createWithConfig (iedModel.self, IntPtr.Zero, nativeConfig); + } + // causes undefined behavior //~IedServer() //{ diff --git a/dotnet/IEC61850forCSharp/IedServerConfig.cs b/dotnet/IEC61850forCSharp/IedServerConfig.cs new file mode 100644 index 00000000..550c3a26 --- /dev/null +++ b/dotnet/IEC61850forCSharp/IedServerConfig.cs @@ -0,0 +1,111 @@ +/* + * IedServerConfig.cs + * + * Copyright 2018 Michael Zillgith + * + * This file is part of libIEC61850. + * + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . + * + * See COPYING file for the complete license text. + */ + +using System; +using System.Runtime.InteropServices; + +namespace IEC61850.Server +{ + /// + /// IedServer configuration object + /// + public class IedServerConfig : IDisposable + { + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr IedServerConfig_create(); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr IedServerConfig_destroy(IntPtr self); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern void IedServerConfig_setReportBufferSize(IntPtr self, int reportBufferSize); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern int IedServerConfig_getReportBufferSize(IntPtr self); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern void IedServerConfig_setFileServiceBasePath(IntPtr self, string basepath); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr IedServerConfig_getFileServiceBasePath(IntPtr self); + + internal IntPtr self; + + public IedServerConfig () + { + self = IedServerConfig_create (); + } + + /// + /// Gets or sets the size of the report buffer for buffered report control blocks + /// + /// The size of the report buffer. + public int ReportBufferSize + { + get { + return IedServerConfig_getReportBufferSize (self); + } + set { + IedServerConfig_setReportBufferSize (self, value); + } + } + + /// + /// Gets or sets the file service base path. + /// + /// The file service base path. + public string FileServiceBasePath + { + get { + return Marshal.PtrToStringAnsi (IedServerConfig_getFileServiceBasePath (self)); + } + set { + IedServerConfig_setFileServiceBasePath (self, value); + } + } + + /// + /// Releases all resource used by the object. + /// + /// Call when you are finished using the . The + /// method leaves the in an unusable state. After + /// calling , you must release all references to the + /// so the garbage collector can reclaim the memory that the + /// was occupying. + public void Dispose() + { + lock (this) { + if (self != IntPtr.Zero) { + IedServerConfig_destroy (self); + self = IntPtr.Zero; + } + } + } + + ~IedServerConfig() + { + Dispose (); + } + } +} + diff --git a/dotnet/server1/Program.cs b/dotnet/server1/Program.cs index b4d1c66f..62c7c5e3 100644 --- a/dotnet/server1/Program.cs +++ b/dotnet/server1/Program.cs @@ -26,7 +26,10 @@ namespace server1 DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference ("GenericIO/GGIO1.SPCSO1"); - IedServer iedServer = new IedServer (iedModel); + IedServerConfig config = new IedServerConfig (); + config.ReportBufferSize = 100000; + + IedServer iedServer = new IedServer (iedModel, config); iedServer.SetControlHandler (spcso1, delegate(DataObject controlObject, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean();