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

Loading…
Cancel
Save