- added setting of MMS request timeout to .NET

pull/179/head
Michael Zillgith 6 years ago
parent 965cebbe2d
commit 0d025800b4

@ -62,11 +62,14 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern void MmsServerIdentity_destroy(IntPtr self); private static extern void MmsServerIdentity_destroy(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport ("iec61850", CallingConvention=CallingConvention.Cdecl)]
private static extern void MmsConnection_setLocalDetail(IntPtr self, Int32 localDetail); private static extern void MmsConnection_setLocalDetail (IntPtr self, Int32 localDetail);
[DllImport ("iec61850", CallingConvention=CallingConvention.Cdecl)]
private static extern Int32 MmsConnection_getLocalDetail (IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern Int32 MmsConnection_getLocalDetail(IntPtr self); private static extern Int32 MmsConnection_setRequestTimeout(IntPtr self, UInt32 timeoutInMs);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr MmsConnection_readMultipleVariables(IntPtr self, out int mmsError, private static extern IntPtr MmsConnection_readMultipleVariables(IntPtr self, out int mmsError,
@ -162,6 +165,15 @@ namespace IEC61850
return MmsConnection_getLocalDetail(self); return MmsConnection_getLocalDetail(self);
} }
/// <summary>
/// Sets the request timeout
/// </summary>
/// <param name="timeoutMs">request timeout in milliseconds</param>
public void SetRequestTimeout(uint timeoutMs)
{
MmsConnection_setRequestTimeout(self, timeoutMs);
}
/// <summary> /// <summary>
/// Reads multipe MMS variables from the same domain /// Reads multipe MMS variables from the same domain
/// </summary> /// </summary>
@ -378,7 +390,7 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern float MmsValue_toFloat(IntPtr self); static extern float MmsValue_toFloat(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)] [return: MarshalAs(UnmanagedType.I1)]
static extern bool MmsValue_getBoolean(IntPtr self); static extern bool MmsValue_getBoolean(IntPtr self);
@ -405,8 +417,8 @@ namespace IEC61850
static extern IntPtr IedConnection_createWithTlsSupport(IntPtr tlsConfig); static extern IntPtr IedConnection_createWithTlsSupport(IntPtr tlsConfig);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void IedConnection_destroy(IntPtr self); static extern void IedConnection_destroy(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern int Connection_getState(IedConnection self); static extern int Connection_getState(IedConnection self);
@ -444,17 +456,17 @@ namespace IEC61850
static extern IntPtr IedConnection_getLogicalNodeDirectory(IntPtr self, out int error, string logicalNodeReference, int acsiClass); static extern IntPtr IedConnection_getLogicalNodeDirectory(IntPtr self, out int error, string logicalNodeReference, int acsiClass);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_getServerDirectory(IntPtr self, out int error, [MarshalAs(UnmanagedType.I1)] bool getFileNames); static extern IntPtr IedConnection_getServerDirectory(IntPtr self, out int error, [MarshalAs(UnmanagedType.I1)] bool getFileNames);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void IedConnection_getDeviceModelFromServer(IntPtr self, out int error); static extern void IedConnection_getDeviceModelFromServer(IntPtr self, out int error);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_getLogicalDeviceDirectory(IntPtr self, out int error, string logicalDeviceName); static extern IntPtr IedConnection_getLogicalDeviceDirectory(IntPtr self, out int error, string logicalDeviceName);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_getVariableSpecification(IntPtr self, out int error, string objectReference, int fc); static extern IntPtr IedConnection_getVariableSpecification(IntPtr self, out int error, string objectReference, int fc);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void InternalConnectionClosedHandler(IntPtr parameter,IntPtr Iedconnection); private delegate void InternalConnectionClosedHandler(IntPtr parameter,IntPtr Iedconnection);
@ -479,24 +491,24 @@ namespace IEC61850
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool IedConnection_deleteDataSet(IntPtr self, out int error, string dataSetReference); static extern bool IedConnection_deleteDataSet(IntPtr self, out int error, string dataSetReference);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_getDataSetDirectory(IntPtr self, out int error, string dataSetReference, [MarshalAs(UnmanagedType.I1)] out bool isDeletable); static extern IntPtr IedConnection_getDataSetDirectory(IntPtr self, out int error, string dataSetReference, [MarshalAs(UnmanagedType.I1)] out bool isDeletable);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_getMmsConnection(IntPtr self); static extern IntPtr IedConnection_getMmsConnection(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsConnection_getIsoConnectionParameters(IntPtr mmsConnection); static extern IntPtr MmsConnection_getIsoConnectionParameters(IntPtr mmsConnection);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [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)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr static extern IntPtr
IedConnection_getFileDirectoryEx(IntPtr self, out int error, string directoryName, string continueAfter IedConnection_getFileDirectoryEx(IntPtr self, out int error, string directoryName, string continueAfter
, [MarshalAs(UnmanagedType.I1)] out bool moreFollows); , [MarshalAs(UnmanagedType.I1)] out bool moreFollows);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void IedConnection_deleteFile(IntPtr self, out int error, string fileName); static extern void IedConnection_deleteFile(IntPtr self, out int error, string fileName);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
@ -506,7 +518,7 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_queryLogByTime(IntPtr self, out int error, string logReference, static extern IntPtr IedConnection_queryLogByTime(IntPtr self, out int error, string logReference,
ulong startTime, ulong endTime, [MarshalAs(UnmanagedType.I1)] out bool moreFollows); ulong startTime, ulong endTime, [MarshalAs(UnmanagedType.I1)] out bool moreFollows);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_getRCBValues(IntPtr connection, out int error, string rcbReference, IntPtr updateRcb); static extern IntPtr IedConnection_getRCBValues(IntPtr connection, out int error, string rcbReference, IntPtr updateRcb);
@ -632,11 +644,11 @@ namespace IEC61850
IedConnection_deleteFileAsync(IntPtr self, out int error, string fileName, IedConnection_deleteFileAsync(IntPtr self, out int error, string fileName,
IedConnection_GenericServiceHandler handler, IntPtr parameter); IedConnection_GenericServiceHandler handler, IntPtr parameter);
/******************** /********************
* FileDirectoryEntry * FileDirectoryEntry
*********************/ *********************/
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void FileDirectoryEntry_destroy(IntPtr self); static extern void FileDirectoryEntry_destroy(IntPtr self);
/**************** /****************
@ -649,11 +661,11 @@ namespace IEC61850
static extern IntPtr LinkedList_getData(IntPtr self); static extern IntPtr LinkedList_getData(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void LinkedList_destroy(IntPtr self); static extern void LinkedList_destroy(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void LinkedList_destroyStatic(IntPtr self); static extern void LinkedList_destroyStatic(IntPtr self);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void LinkedListValueDeleteFunction(IntPtr pointer); private delegate void LinkedListValueDeleteFunction(IntPtr pointer);
@ -711,8 +723,8 @@ namespace IEC61850
~IedConnection () ~IedConnection ()
{ {
Dispose(); Dispose();
} }
private IsoConnectionParameters isoConnectionParameters = null; private IsoConnectionParameters isoConnectionParameters = null;
/// <summary> /// <summary>
@ -720,16 +732,16 @@ namespace IEC61850
/// </summary> /// </summary>
/// <returns>The connection parameters</returns> /// <returns>The connection parameters</returns>
public IsoConnectionParameters GetConnectionParameters() public IsoConnectionParameters GetConnectionParameters()
{ {
if (isoConnectionParameters == null) if (isoConnectionParameters == null)
{ {
IntPtr mmsConnection = IedConnection_getMmsConnection(connection); IntPtr mmsConnection = IedConnection_getMmsConnection(connection);
IntPtr parameters = MmsConnection_getIsoConnectionParameters(mmsConnection); IntPtr parameters = MmsConnection_getIsoConnectionParameters(mmsConnection);
isoConnectionParameters = new IsoConnectionParameters(parameters); isoConnectionParameters = new IsoConnectionParameters(parameters);
} }
return isoConnectionParameters; return isoConnectionParameters;
} }
@ -833,7 +845,7 @@ namespace IEC61850
ControlObject controlObject = new ControlObject(objectReference, connection, this); ControlObject controlObject = new ControlObject(objectReference, connection, this);
return controlObject; return controlObject;
} }
/// <summary> /// <summary>
/// Creates a new SampledValuesControlBlock instance. /// Creates a new SampledValuesControlBlock instance.
@ -860,15 +872,15 @@ namespace IEC61850
/// <summary> /// <summary>
/// Updates the device model by quering the server. /// Updates the device model by quering the server.
/// </summary> /// </summary>
public void UpdateDeviceModel() public void UpdateDeviceModel()
{ {
int error; int error;
IedConnection_getDeviceModelFromServer(connection, out error); IedConnection_getDeviceModelFromServer(connection, out error);
if (error != 0) if (error != 0)
throw new IedConnectionException("UpdateDeviceModel failed", error); throw new IedConnectionException("UpdateDeviceModel failed", error);
} }
@ -1442,40 +1454,40 @@ namespace IEC61850
} }
return invokeId; return invokeId;
} }
/// <summary>Read the content of a file directory.</summary> /// <summary>Read the content of a file directory.</summary>
/// <param name="directoryName">The name of the directory.</param> /// <param name="directoryName">The name of the directory.</param>
/// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception>
public List<FileDirectoryEntry> GetFileDirectory(string directoryName) public List<FileDirectoryEntry> GetFileDirectory(string directoryName)
{ {
int error; int error;
IntPtr fileEntryList = IedConnection_getFileDirectory(connection, out error, directoryName); IntPtr fileEntryList = IedConnection_getFileDirectory(connection, out error, directoryName);
if (error != 0) if (error != 0)
throw new IedConnectionException("Reading file directory failed", error); throw new IedConnectionException("Reading file directory failed", error);
List<FileDirectoryEntry> fileDirectory = new List<FileDirectoryEntry>(); List<FileDirectoryEntry> fileDirectory = new List<FileDirectoryEntry>();
IntPtr element = LinkedList_getNext(fileEntryList); IntPtr element = LinkedList_getNext(fileEntryList);
while (element != IntPtr.Zero) while (element != IntPtr.Zero)
{ {
IntPtr elementData = LinkedList_getData(element); IntPtr elementData = LinkedList_getData(element);
FileDirectoryEntry entry = new FileDirectoryEntry(elementData); FileDirectoryEntry entry = new FileDirectoryEntry(elementData);
fileDirectory.Add(entry); fileDirectory.Add(entry);
FileDirectoryEntry_destroy(elementData); FileDirectoryEntry_destroy(elementData);
element = LinkedList_getNext(element); element = LinkedList_getNext(element);
} }
LinkedList_destroyStatic(fileEntryList); LinkedList_destroyStatic(fileEntryList);
return fileDirectory; return fileDirectory;
} }
/// <summary>Read the content of a file directory. - single request version</summary> /// <summary>Read the content of a file directory. - single request version</summary>
@ -1513,42 +1525,42 @@ namespace IEC61850
LinkedList_destroyStatic(fileEntryList); LinkedList_destroyStatic(fileEntryList);
return fileDirectory; return fileDirectory;
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)] [return: MarshalAs(UnmanagedType.I1)]
private delegate bool InternalIedClientGetFileHandler(IntPtr parameter,IntPtr buffer,UInt32 bytesRead); private delegate bool InternalIedClientGetFileHandler(IntPtr parameter,IntPtr buffer,UInt32 bytesRead);
private bool iedClientGetFileHandler(IntPtr parameter, IntPtr buffer, UInt32 bytesRead) private bool iedClientGetFileHandler(IntPtr parameter, IntPtr buffer, UInt32 bytesRead)
{ {
GCHandle handle = GCHandle.FromIntPtr(parameter); GCHandle handle = GCHandle.FromIntPtr(parameter);
GetFileCallback getFileCallback = (GetFileCallback)handle.Target; GetFileCallback getFileCallback = (GetFileCallback)handle.Target;
byte[] bytes = new byte[bytesRead]; byte[] bytes = new byte[bytesRead];
Marshal.Copy(buffer, bytes, 0, (int)bytesRead); Marshal.Copy(buffer, bytes, 0, (int)bytesRead);
return getFileCallback.handler(getFileCallback.parameter, bytes); return getFileCallback.handler(getFileCallback.parameter, bytes);
} }
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern UInt32 IedConnection_getFile(IntPtr self, out int error, string fileName, InternalIedClientGetFileHandler handler, static extern UInt32 IedConnection_getFile(IntPtr self, out int error, string fileName, InternalIedClientGetFileHandler handler,
IntPtr handlerParameter); IntPtr handlerParameter);
public delegate bool GetFileHandler(object parameter,byte[] data); public delegate bool GetFileHandler(object parameter,byte[] data);
private class GetFileCallback private class GetFileCallback
{ {
public GetFileCallback(GetFileHandler handler, object parameter) public GetFileCallback(GetFileHandler handler, object parameter)
{ {
this.handler = handler; this.handler = handler;
this.parameter = parameter; this.parameter = parameter;
} }
public GetFileHandler handler; public GetFileHandler handler;
public object parameter; public object parameter;
} }
/// <summary> /// <summary>
@ -1565,20 +1577,20 @@ namespace IEC61850
/// </param> /// </param>
/// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception>
public void GetFile(string fileName, GetFileHandler handler, object parameter) public void GetFile(string fileName, GetFileHandler handler, object parameter)
{ {
int error; int error;
GetFileCallback getFileCallback = new GetFileCallback(handler, parameter); GetFileCallback getFileCallback = new GetFileCallback(handler, parameter);
GCHandle handle = GCHandle.Alloc(getFileCallback); GCHandle handle = GCHandle.Alloc(getFileCallback);
IedConnection_getFile(connection, out error, fileName, new InternalIedClientGetFileHandler(iedClientGetFileHandler), IedConnection_getFile(connection, out error, fileName, new InternalIedClientGetFileHandler(iedClientGetFileHandler),
GCHandle.ToIntPtr(handle)); GCHandle.ToIntPtr(handle));
if (error != 0) if (error != 0)
throw new IedConnectionException("Error reading file", error); throw new IedConnectionException("Error reading file", error);
handle.Free(); handle.Free();
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@ -1942,28 +1954,28 @@ namespace IEC61850
throw new IedConnectionException("Failed to delete data set", error); throw new IedConnectionException("Failed to delete data set", error);
return isDeleted; return isDeleted;
} }
/// <summary> /// <summary>
/// Get the directory of the data set. /// Get the directory of the data set.
/// </summary> /// </summary>
/// <description>This function returns a list of object references with appended functional constraints (FC) of the data set elemenents.</description> /// <description>This function returns a list of object references with appended functional constraints (FC) of the data set elemenents.</description>
/// <param name="dataSetReference">The object reference of the data set</param> /// <param name="dataSetReference">The object reference of the data set</param>
/// <returns>the list of object references</returns> /// <returns>the list of object references</returns>
/// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception>
public List<string> GetDataSetDirectory(string dataSetReference) public List<string> GetDataSetDirectory(string dataSetReference)
{ {
bool isDeletable; bool isDeletable;
return GetDataSetDirectory(dataSetReference, out isDeletable); return GetDataSetDirectory(dataSetReference, out isDeletable);
} }
/// <summary> /// <summary>
/// Get the directory of the data set. /// Get the directory of the data set.
/// </summary> /// </summary>
/// <description>This function returns a list of object references with appended functional constraints (FC) of the data set elemenents.</description> /// <description>This function returns a list of object references with appended functional constraints (FC) of the data set elemenents.</description>
/// <param name="dataSetReference">The object reference of the data set</param> /// <param name="dataSetReference">The object reference of the data set</param>
/// <param name="isDeletable">Indication if this data set is permanent or deletable.</param> /// <param name="isDeletable">Indication if this data set is permanent or deletable.</param>
/// <returns>the list of object references</returns> /// <returns>the list of object references</returns>
/// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception>
public List<string> GetDataSetDirectory(string dataSetReference, out bool isDeletable) public List<string> GetDataSetDirectory(string dataSetReference, out bool isDeletable)
@ -2568,44 +2580,44 @@ namespace IEC61850
{ {
return (IedClientError)this.errorCode; return (IedClientError)this.errorCode;
} }
} }
public class FileDirectoryEntry public class FileDirectoryEntry
{ {
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr FileDirectoryEntry_getFileName(IntPtr self); private static extern IntPtr FileDirectoryEntry_getFileName(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern UInt32 FileDirectoryEntry_getFileSize(IntPtr self); private static extern UInt32 FileDirectoryEntry_getFileSize(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern UInt64 FileDirectoryEntry_getLastModified(IntPtr self); private static extern UInt64 FileDirectoryEntry_getLastModified(IntPtr self);
private string fileName; private string fileName;
private UInt32 fileSize; private UInt32 fileSize;
private UInt64 lastModified; private UInt64 lastModified;
internal FileDirectoryEntry(IntPtr nativeFileDirectoryEntry) internal FileDirectoryEntry(IntPtr nativeFileDirectoryEntry)
{ {
fileName = Marshal.PtrToStringAnsi(FileDirectoryEntry_getFileName(nativeFileDirectoryEntry)); fileName = Marshal.PtrToStringAnsi(FileDirectoryEntry_getFileName(nativeFileDirectoryEntry));
fileSize = FileDirectoryEntry_getFileSize(nativeFileDirectoryEntry); fileSize = FileDirectoryEntry_getFileSize(nativeFileDirectoryEntry);
lastModified = FileDirectoryEntry_getLastModified(nativeFileDirectoryEntry); lastModified = FileDirectoryEntry_getLastModified(nativeFileDirectoryEntry);
} }
public string GetFileName() public string GetFileName()
{ {
return fileName; return fileName;
} }
public UInt32 GetFileSize() public UInt32 GetFileSize()
{ {
return fileSize; return fileSize;
} }
public UInt64 GetLastModified() public UInt64 GetLastModified()
{ {
return lastModified; return lastModified;
} }
} }
/// <summary> /// <summary>

Loading…
Cancel
Save