(LIB61850-513)

->API AcseAuthenticationParameter GetPasswordString
v1.6
Maxson Ramon dos Anjos Medeiros 4 weeks ago
parent edbf23870a
commit 749e603b94

@ -1,7 +1,7 @@
/* /*
* AcseAuthenticationParameter.cs * AcseAuthenticationParameter.cs
* *
* Copyright 2014 Michael Zillgith * Copyright 2025-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -21,7 +21,6 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
@ -94,16 +93,39 @@ namespace IEC61850
return (AcseAuthenticationMechanism)AcseAuthenticationParameter_getAuthMechanism(self); return (AcseAuthenticationMechanism)AcseAuthenticationParameter_getAuthMechanism(self);
} }
public string GetPassword() public string GetPasswordString()
{
try
{
byte[] password = GetPasswordByteArray();
return Encoding.UTF8.GetString(password);
}
catch (Exception)
{
return null;
}
}
public byte[] GetPasswordByteArray()
{ {
IntPtr password = AcseAuthenticationParameter_getPassword(self); IntPtr password = AcseAuthenticationParameter_getPassword(self);
if (password != IntPtr.Zero) if (password != IntPtr.Zero)
return Marshal.PtrToStringAnsi(password); {
int lenght = GetPasswordLenght();
byte[] result = new byte[lenght];
Marshal.Copy(password, result, 0, lenght);
return result;
}
else else
return null; return null;
} }
public int GetPasswordLenght() public int GetPasswordLenght()
{ {
return AcseAuthenticationParameter_getPasswordLength(self); return AcseAuthenticationParameter_getPasswordLength(self);

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

@ -1,7 +1,7 @@
/* /*
* Control.cs * Control.cs
* *
* Copyright 2014 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -21,15 +21,15 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using IEC61850.Common;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using IEC61850.Common;
namespace IEC61850 namespace IEC61850
{ {
// IEC 61850 common API parts (used by client and server API) // IEC 61850 common API parts (used by client and server API)
namespace Common { namespace Common
{
/// <summary> /// <summary>
/// Control model /// Control model
@ -51,7 +51,8 @@ namespace IEC61850
/// <summary> /// <summary>
/// Originator category /// Originator category
/// </summary> /// </summary>
public enum OrCat { public enum OrCat
{
/** Not supported - should not be used */ /** Not supported - should not be used */
NOT_SUPPORTED = 0, NOT_SUPPORTED = 0,
/** Control operation issued from an operator using a client located at bay level */ /** Control operation issued from an operator using a client located at bay level */
@ -92,9 +93,9 @@ namespace IEC61850
internal LastApplError(LastApplErrorInternal lastApplError) internal LastApplError(LastApplErrorInternal lastApplError)
{ {
this.addCause = (ControlAddCause) lastApplError.addCause; addCause = (ControlAddCause)lastApplError.addCause;
this.error = lastApplError.error; error = lastApplError.error;
this.ctlNum = lastApplError.ctlNum; ctlNum = lastApplError.ctlNum;
} }
} }
@ -207,9 +208,9 @@ namespace IEC61850
{ {
this.iedConnection = iedConnection; this.iedConnection = iedConnection;
this.self = ControlObjectClient_create(objectReference, connection); self = ControlObjectClient_create(objectReference, connection);
if (this.self == System.IntPtr.Zero) if (self == System.IntPtr.Zero)
throw new IedConnectionException("Control object not found", 0); throw new IedConnectionException("Control object not found", 0);
intCommandTerminationHandler = new InternalCommandTerminationHandler(MyCommandTerminationHandler); intCommandTerminationHandler = new InternalCommandTerminationHandler(MyCommandTerminationHandler);
@ -259,8 +260,10 @@ namespace IEC61850
/// Gets the error code of the last synchronous control action (operate, select, select-with-value, cancel) /// Gets the error code of the last synchronous control action (operate, select, select-with-value, cancel)
/// </summary> /// </summary>
/// <value>error code.</value> /// <value>error code.</value>
public IedClientError LastError { public IedClientError LastError
get { {
get
{
return (IedClientError)ControlObjectClient_getLastError(self); return (IedClientError)ControlObjectClient_getLastError(self);
} }
} }
@ -760,18 +763,21 @@ namespace IEC61850
/// </param> /// </param>
public void SetCommandTerminationHandler(CommandTerminationHandler handler, Object parameter) public void SetCommandTerminationHandler(CommandTerminationHandler handler, Object parameter)
{ {
this.commandTerminationHandler = handler; commandTerminationHandler = handler;
this.commandTerminationHandlerParameter = parameter; commandTerminationHandlerParameter = parameter;
} }
protected virtual void Dispose(bool disposing) { protected virtual void Dispose(bool disposing)
if (this.self != System.IntPtr.Zero) { {
if (self != System.IntPtr.Zero)
{
ControlObjectClient_destroy(self); ControlObjectClient_destroy(self);
this.self = System.IntPtr.Zero; self = System.IntPtr.Zero;
} }
} }
public void Dispose() { public void Dispose()
{
Dispose(true); Dispose(true);
} }

@ -1,7 +1,7 @@
/* /*
* DataSet.cs * DataSet.cs
* *
* Copyright 2014-2018 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -20,12 +20,10 @@
* *
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using IEC61850.Common;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using IEC61850.Common;
namespace IEC61850 namespace IEC61850
{ {
namespace Client namespace Client

@ -1,7 +1,7 @@
/* /*
* GooseControlBlock.cs * GooseControlBlock.cs
* *
* Copyright 2017 Michael Zillgith * Copyright 2017-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -20,18 +20,17 @@
* *
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using IEC61850.Common;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics;
using IEC61850.Common;
namespace IEC61850 namespace IEC61850
{ {
namespace Client namespace Client
{ {
public class GooseControlBlock : IDisposable { public class GooseControlBlock : IDisposable
{
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ClientGooseControlBlock_create(string dataAttributeReference); static extern IntPtr ClientGooseControlBlock_create(string dataAttributeReference);
@ -120,7 +119,7 @@ namespace IEC61850
public string GetObjectReference() public string GetObjectReference()
{ {
return this.objectReference; return objectReference;
} }
/// <summary> /// <summary>
@ -272,7 +271,8 @@ namespace IEC61850
public void Dispose() public void Dispose()
{ {
if (isDisposed == false) { if (isDisposed == false)
{
isDisposed = true; isDisposed = true;
ClientGooseControlBlock_destroy(self); ClientGooseControlBlock_destroy(self);
self = IntPtr.Zero; self = IntPtr.Zero;

@ -1,7 +1,7 @@
/* /*
* GooseSubscriber.cs * GooseSubscriber.cs
* *
* Copyright 2017 Michael Zillgith * Copyright 2017-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -21,10 +21,10 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using IEC61850.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using IEC61850.Common;
namespace IEC61850 namespace IEC61850
{ {
@ -124,7 +124,8 @@ namespace IEC61850
public void Dispose() public void Dispose()
{ {
if (isDisposed == false) { if (isDisposed == false)
{
isDisposed = true; isDisposed = true;
GooseReceiver_destroy(self); GooseReceiver_destroy(self);
self = IntPtr.Zero; self = IntPtr.Zero;
@ -216,13 +217,16 @@ namespace IEC61850
private void internalGooseListener(IntPtr subscriber, IntPtr parameter) private void internalGooseListener(IntPtr subscriber, IntPtr parameter)
{ {
try { try
{
if (listener != null) { if (listener != null)
{
listener(this, listenerParameter); listener(this, listenerParameter);
} }
} catch (Exception e) }
catch (Exception e)
{ {
// older versions of mono 2.10 (for linux?) cause this exception // older versions of mono 2.10 (for linux?) cause this exception
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
@ -247,9 +251,10 @@ namespace IEC61850
public void SetListener(GooseListener listener, object parameter) public void SetListener(GooseListener listener, object parameter)
{ {
this.listener = listener; this.listener = listener;
this.listenerParameter = parameter; listenerParameter = parameter;
if (internalListener == null) { if (internalListener == null)
{
internalListener = new InternalGooseListener(internalGooseListener); internalListener = new InternalGooseListener(internalGooseListener);
GooseSubscriber_setListener(self, internalListener, IntPtr.Zero); GooseSubscriber_setListener(self, internalListener, IntPtr.Zero);
@ -342,7 +347,8 @@ namespace IEC61850
/// </remarks> /// </remarks>
public void Dispose() public void Dispose()
{ {
if (isDisposed == false) { if (isDisposed == false)
{
isDisposed = true; isDisposed = true;
if (attachedToReceiver == false) if (attachedToReceiver == false)

@ -1,7 +1,7 @@
/* /*
* IEC61850ClientAPI.cs * IEC61850ClientAPI.cs
* *
* Copyright 2014-2023 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -20,14 +20,11 @@
* *
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections;
using IEC61850.Common; using IEC61850.Common;
using IEC61850.TLS; using IEC61850.TLS;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
// IEC 61850 API for the libiec61850 .NET wrapper library // IEC 61850 API for the libiec61850 .NET wrapper library
namespace IEC61850 namespace IEC61850
@ -2936,17 +2933,17 @@ namespace IEC61850
public IedConnectionException(string message) public IedConnectionException(string message)
: base(message) : base(message)
{ {
this.errorCode = 0; errorCode = 0;
} }
public int GetErrorCode() public int GetErrorCode()
{ {
return this.errorCode; return errorCode;
} }
public IedClientError GetIedClientError() public IedClientError GetIedClientError()
{ {
return (IedClientError)this.errorCode; return (IedClientError)errorCode;
} }
} }

@ -1,7 +1,7 @@
/* /*
* IEC61850CommonAPI.cs * IEC61850CommonAPI.cs
* *
* Copyright 2014-2024 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -62,8 +62,8 @@ namespace IEC61850
ulong seconds = msTime / 1000; ulong seconds = msTime / 1000;
ulong millies = msTime % 1000; ulong millies = msTime % 1000;
dateTime.AddSeconds ((double) seconds); dateTime.AddSeconds(seconds);
dateTime.AddMilliseconds((double) millies); dateTime.AddMilliseconds(millies);
return dateTime; return dateTime;
} }
@ -93,7 +93,8 @@ namespace IEC61850
/// <summary> /// <summary>
/// MMS data access error for MmsValue type MMS_DATA_ACCESS_ERROR /// MMS data access error for MmsValue type MMS_DATA_ACCESS_ERROR
/// </summary> /// </summary>
public enum MmsDataAccessError { public enum MmsDataAccessError
{
NO_RESPONSE = -2, /* for server internal purposes only! */ NO_RESPONSE = -2, /* for server internal purposes only! */
SUCCESS = -1, SUCCESS = -1,
OBJECT_INVALIDATED = 0, OBJECT_INVALIDATED = 0,
@ -112,7 +113,8 @@ namespace IEC61850
} }
[Flags] [Flags]
public enum TriggerOptions { public enum TriggerOptions
{
NONE = 0, NONE = 0,
/** send report when value of data changed */ /** send report when value of data changed */
DATA_CHANGED = 1, DATA_CHANGED = 1,
@ -131,7 +133,8 @@ namespace IEC61850
/// <summary> /// <summary>
/// SmpMod values /// SmpMod values
/// </summary> /// </summary>
public enum SmpMod { public enum SmpMod
{
SAMPLES_PER_PERIOD = 0, SAMPLES_PER_PERIOD = 0,
SAMPLES_PER_SECOND = 1, SAMPLES_PER_SECOND = 1,
SECONDS_PER_SAMPLE = 2 SECONDS_PER_SAMPLE = 2
@ -141,7 +144,8 @@ namespace IEC61850
/// Values for Sampled Values (SV) OptFlds /// Values for Sampled Values (SV) OptFlds
/// </summary> /// </summary>
[Flags] [Flags]
public enum SVOptions { public enum SVOptions
{
NONE = 0, NONE = 0,
REFRESH_TIME = 1, REFRESH_TIME = 1,
SAMPLE_SYNC = 2, SAMPLE_SYNC = 2,
@ -152,7 +156,8 @@ namespace IEC61850
} }
[Flags] [Flags]
public enum ReportOptions { public enum ReportOptions
{
NONE = 0, NONE = 0,
SEQ_NUM = 1, SEQ_NUM = 1,
TIME_STAMP = 2, TIME_STAMP = 2,
@ -235,133 +240,145 @@ namespace IEC61850
public bool Overflow public bool Overflow
{ {
get { return ((this.value & QUALITY_DETAIL_OVERFLOW) != 0);} get { return ((value & QUALITY_DETAIL_OVERFLOW) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DETAIL_OVERFLOW; this.value |= QUALITY_DETAIL_OVERFLOW;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DETAIL_OVERFLOW)); this.value = (ushort)(this.value & (~QUALITY_DETAIL_OVERFLOW));
} }
} }
public bool OutOfRange public bool OutOfRange
{ {
get { return ((this.value & QUALITY_DETAIL_OUT_OF_RANGE) != 0);} get { return ((value & QUALITY_DETAIL_OUT_OF_RANGE) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DETAIL_OUT_OF_RANGE; this.value |= QUALITY_DETAIL_OUT_OF_RANGE;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DETAIL_OUT_OF_RANGE)); this.value = (ushort)(this.value & (~QUALITY_DETAIL_OUT_OF_RANGE));
} }
} }
public bool BadReference public bool BadReference
{ {
get { return ((this.value & QUALITY_DETAIL_BAD_REFERENCE) != 0);} get { return ((value & QUALITY_DETAIL_BAD_REFERENCE) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DETAIL_BAD_REFERENCE; this.value |= QUALITY_DETAIL_BAD_REFERENCE;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DETAIL_BAD_REFERENCE)); this.value = (ushort)(this.value & (~QUALITY_DETAIL_BAD_REFERENCE));
} }
} }
public bool Oscillatory public bool Oscillatory
{ {
get { return ((this.value & QUALITY_DETAIL_OSCILLATORY) != 0);} get { return ((value & QUALITY_DETAIL_OSCILLATORY) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DETAIL_OSCILLATORY; this.value |= QUALITY_DETAIL_OSCILLATORY;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DETAIL_OSCILLATORY)); this.value = (ushort)(this.value & (~QUALITY_DETAIL_OSCILLATORY));
} }
} }
public bool Failure public bool Failure
{ {
get { return ((this.value & QUALITY_DETAIL_FAILURE) != 0);} get { return ((value & QUALITY_DETAIL_FAILURE) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DETAIL_FAILURE; this.value |= QUALITY_DETAIL_FAILURE;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DETAIL_FAILURE)); this.value = (ushort)(this.value & (~QUALITY_DETAIL_FAILURE));
} }
} }
public bool OldData public bool OldData
{ {
get { return ((this.value & QUALITY_DETAIL_OLD_DATA) != 0);} get { return ((value & QUALITY_DETAIL_OLD_DATA) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DETAIL_OLD_DATA; this.value |= QUALITY_DETAIL_OLD_DATA;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DETAIL_OLD_DATA)); this.value = (ushort)(this.value & (~QUALITY_DETAIL_OLD_DATA));
} }
} }
public bool Inconsistent public bool Inconsistent
{ {
get { return ((this.value & QUALITY_DETAIL_INCONSISTENT) != 0);} get { return ((value & QUALITY_DETAIL_INCONSISTENT) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DETAIL_INCONSISTENT; this.value |= QUALITY_DETAIL_INCONSISTENT;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DETAIL_INCONSISTENT)); this.value = (ushort)(this.value & (~QUALITY_DETAIL_INCONSISTENT));
} }
} }
public bool Inaccurate public bool Inaccurate
{ {
get { return ((this.value & QUALITY_DETAIL_INACCURATE) != 0);} get { return ((value & QUALITY_DETAIL_INACCURATE) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DETAIL_INACCURATE; this.value |= QUALITY_DETAIL_INACCURATE;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DETAIL_INACCURATE)); this.value = (ushort)(this.value & (~QUALITY_DETAIL_INACCURATE));
} }
} }
public bool Substituted public bool Substituted
{ {
get { return ((this.value & QUALITY_SOURCE_SUBSTITUTED) != 0);} get { return ((value & QUALITY_SOURCE_SUBSTITUTED) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_SOURCE_SUBSTITUTED; this.value |= QUALITY_SOURCE_SUBSTITUTED;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_SOURCE_SUBSTITUTED)); this.value = (ushort)(this.value & (~QUALITY_SOURCE_SUBSTITUTED));
} }
} }
public bool Test public bool Test
{ {
get { return ((this.value & QUALITY_TEST) != 0);} get { return ((value & QUALITY_TEST) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_TEST; this.value |= QUALITY_TEST;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_TEST)); this.value = (ushort)(this.value & (~QUALITY_TEST));
} }
} }
public bool OperatorBlocked public bool OperatorBlocked
{ {
get { return ((this.value & QUALITY_OPERATOR_BLOCKED) != 0);} get { return ((value & QUALITY_OPERATOR_BLOCKED) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_OPERATOR_BLOCKED; this.value |= QUALITY_OPERATOR_BLOCKED;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_OPERATOR_BLOCKED)); this.value = (ushort)(this.value & (~QUALITY_OPERATOR_BLOCKED));
} }
} }
public bool Derived public bool Derived
{ {
get { return ((this.value & QUALITY_DERIVED) != 0); } get { return ((value & QUALITY_DERIVED) != 0); }
set { set
{
if (value) if (value)
this.value |= QUALITY_DERIVED; this.value |= QUALITY_DERIVED;
else else
this.value = (ushort) ((int) this.value & (~QUALITY_DERIVED)); this.value = (ushort)(this.value & (~QUALITY_DERIVED));
} }
} }
} }
@ -440,8 +457,8 @@ namespace IEC61850
internal Timestamp(IntPtr timestampRef, bool selfAllocated) internal Timestamp(IntPtr timestampRef, bool selfAllocated)
{ {
this.self = timestampRef; self = timestampRef;
this.responsibleForDeletion = selfAllocated; responsibleForDeletion = selfAllocated;
} }
public Timestamp(DateTime timestamp) : this() public Timestamp(DateTime timestamp) : this()
@ -505,7 +522,8 @@ namespace IEC61850
SetTimeInMilliseconds(timeVal); SetTimeInMilliseconds(timeVal);
} }
public bool LeapSecondKnown { public bool LeapSecondKnown
{
get { return IsLeapSecondKnown(); } get { return IsLeapSecondKnown(); }
set { SetLeapSecondKnow(value); } set { SetLeapSecondKnow(value); }
} }
@ -520,7 +538,8 @@ namespace IEC61850
Timestamp_setLeapSecondKnown(self, value); Timestamp_setLeapSecondKnown(self, value);
} }
public bool ClockFailure { public bool ClockFailure
{
get { return HasClockFailure(); } get { return HasClockFailure(); }
set { SetClockFailure(value); } set { SetClockFailure(value); }
} }
@ -535,33 +554,40 @@ namespace IEC61850
Timestamp_setClockFailure(self, value); Timestamp_setClockFailure(self, value);
} }
public bool ClockNotSynchronized { public bool ClockNotSynchronized
{
get { return IsClockNotSynchronized(); } get { return IsClockNotSynchronized(); }
set { SetClockNotSynchronized(value); } set { SetClockNotSynchronized(value); }
} }
public bool IsClockNotSynchronized() { public bool IsClockNotSynchronized()
{
return Timestamp_isClockNotSynchronized(self); return Timestamp_isClockNotSynchronized(self);
} }
public void SetClockNotSynchronized(bool value) { public void SetClockNotSynchronized(bool value)
{
Timestamp_setClockNotSynchronized(self, value); Timestamp_setClockNotSynchronized(self, value);
} }
public int SubsecondPrecision { public int SubsecondPrecision
{
get { return GetSubsecondPrecision(); } get { return GetSubsecondPrecision(); }
set { SetSubsecondPrecision(value); } set { SetSubsecondPrecision(value); }
} }
public int GetSubsecondPrecision() { public int GetSubsecondPrecision()
{
return Timestamp_getSubsecondPrecision(self); return Timestamp_getSubsecondPrecision(self);
} }
public void SetSubsecondPrecision(int subsecondPrecision) { public void SetSubsecondPrecision(int subsecondPrecision)
{
Timestamp_setSubsecondPrecision(self, subsecondPrecision); Timestamp_setSubsecondPrecision(self, subsecondPrecision);
} }
public UInt32 TimeInSeconds { public UInt32 TimeInSeconds
{
get { return GetTimeInSeconds(); } get { return GetTimeInSeconds(); }
set { SetTimeInSeconds(value); } set { SetTimeInSeconds(value); }
} }
@ -576,7 +602,8 @@ namespace IEC61850
Timestamp_setTimeInSeconds(self, secondsSinceEpoch); Timestamp_setTimeInSeconds(self, secondsSinceEpoch);
} }
public UInt64 TimeInMilliseconds { public UInt64 TimeInMilliseconds
{
get { return GetTimeInMilliseconds(); } get { return GetTimeInMilliseconds(); }
set { SetTimeInMilliseconds(value); } set { SetTimeInMilliseconds(value); }
} }
@ -586,7 +613,8 @@ namespace IEC61850
return Timestamp_getTimeInMs(self); return Timestamp_getTimeInMs(self);
} }
public void SetTimeInMilliseconds(UInt64 millisSinceEpoch) { public void SetTimeInMilliseconds(UInt64 millisSinceEpoch)
{
Timestamp_setTimeInMilliseconds(self, millisSinceEpoch); Timestamp_setTimeInMilliseconds(self, millisSinceEpoch);
} }
@ -599,7 +627,7 @@ namespace IEC61850
{ {
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime retVal = epoch.AddMilliseconds ((double) GetTimeInMilliseconds ()); DateTime retVal = epoch.AddMilliseconds(GetTimeInMilliseconds());
return retVal; return retVal;
} }
@ -695,7 +723,8 @@ namespace IEC61850
/// Definition for LastAppError error type for control models /// Definition for LastAppError error type for control models
/// Used in LastApplError and CommandTermination messages. /// Used in LastApplError and CommandTermination messages.
/// </summary> /// </summary>
public enum ControlLastApplError { public enum ControlLastApplError
{
NO_ERROR = 0, NO_ERROR = 0,
UNKNOWN = 1, UNKNOWN = 1,
TIMEOUT_TEST = 2, TIMEOUT_TEST = 2,
@ -706,7 +735,8 @@ namespace IEC61850
/// AddCause - additional cause information for control model errors /// AddCause - additional cause information for control model errors
/// Used in LastApplError and CommandTermination messages. /// Used in LastApplError and CommandTermination messages.
/// </summary> /// </summary>
public enum ControlAddCause { public enum ControlAddCause
{
ADD_CAUSE_UNKNOWN = 0, ADD_CAUSE_UNKNOWN = 0,
ADD_CAUSE_NOT_SUPPORTED = 1, ADD_CAUSE_NOT_SUPPORTED = 1,
ADD_CAUSE_BLOCKED_BY_SWITCHING_HIERARCHY = 2, ADD_CAUSE_BLOCKED_BY_SWITCHING_HIERARCHY = 2,
@ -740,7 +770,8 @@ namespace IEC61850
/// <summary> /// <summary>
/// Object reference. Helper function to handle object reference strings. /// Object reference. Helper function to handle object reference strings.
/// </summary> /// </summary>
public static class ObjectReference { public static class ObjectReference
{
/// <summary> /// <summary>
/// Get the name part of an object reference with appended FC /// Get the name part of an object reference with appended FC

@ -22,9 +22,7 @@
*/ */
using IEC61850.Server; using IEC61850.Server;
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
// IEC 61850 API for the libiec61850 .NET wrapper library // IEC 61850 API for the libiec61850 .NET wrapper library
namespace IEC61850 namespace IEC61850
@ -67,7 +65,7 @@ namespace IEC61850
public SVControlBlock(string name, IedModel parent, string svID, string dataSet, UInt32 confRev, uint smpMod, public SVControlBlock(string name, IedModel parent, string svID, string dataSet, UInt32 confRev, uint smpMod,
UInt16 smpRate, uint optFlds, bool isUnicast) UInt16 smpRate, uint optFlds, bool isUnicast)
{ {
this.self = SVControlBlock_create(name, parent.self, svID, dataSet, confRev, smpMod, smpRate, optFlds, isUnicast); self = SVControlBlock_create(name, parent.self, svID, dataSet, confRev, smpMod, smpRate, optFlds, isUnicast);
this.parent = parent; this.parent = parent;
} }

@ -1,7 +1,7 @@
/* /*
* IEC61850ServerAPI.cs * IEC61850ServerAPI.cs
* *
* Copyright 2016-2024 Michael Zillgith * Copyright 2016-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -25,10 +25,7 @@ using IEC61850.Model;
using IEC61850.TLS; using IEC61850.TLS;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Common;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Principal;
// IEC 61850 API for the libiec61850 .NET wrapper library // IEC 61850 API for the libiec61850 .NET wrapper library
namespace IEC61850 namespace IEC61850
@ -47,7 +44,8 @@ namespace IEC61850
public static IedModel CreateModelFromConfigFile(string filePath) public static IedModel CreateModelFromConfigFile(string filePath)
{ {
IntPtr retVal = ConfigFileParser_createModelFromConfigFileEx(filePath); IntPtr retVal = ConfigFileParser_createModelFromConfigFileEx(filePath);
if (retVal == IntPtr.Zero) { if (retVal == IntPtr.Zero)
{
return null; return null;
} }
@ -334,7 +332,7 @@ namespace IEC61850
public LogicalDevice(IntPtr self, IedModel iedModel) : base(self) public LogicalDevice(IntPtr self, IedModel iedModel) : base(self)
{ {
this.IedModel = iedModel; IedModel = iedModel;
} }
/// <summary> /// <summary>
@ -344,7 +342,7 @@ namespace IEC61850
/// <param name="parent">Model containing this logical device</param> /// <param name="parent">Model containing this logical device</param>
public LogicalDevice(string inst, IedModel parent) public LogicalDevice(string inst, IedModel parent)
{ {
this.IedModel = parent; IedModel = parent;
self = LogicalDevice_create(inst, parent.self); self = LogicalDevice_create(inst, parent.self);
} }
@ -357,7 +355,7 @@ namespace IEC61850
/// <param name="ldName">LD name (for functional naming). When set, the exernally visible domain name for this LD</param> /// <param name="ldName">LD name (for functional naming). When set, the exernally visible domain name for this LD</param>
public LogicalDevice(string inst, IedModel parent, string ldName) public LogicalDevice(string inst, IedModel parent, string ldName)
{ {
this.IedModel = parent; IedModel = parent;
self = LogicalDevice_createEx(inst, parent.self, ldName); self = LogicalDevice_createEx(inst, parent.self, ldName);
} }
@ -368,7 +366,7 @@ namespace IEC61850
/// <returns>the SGCB instance or NULL if no SGCB is available</returns> /// <returns>the SGCB instance or NULL if no SGCB is available</returns>
public SettingGroupControlBlock GetSettingGroupControlBlock() public SettingGroupControlBlock GetSettingGroupControlBlock()
{ {
IntPtr sgcb = LogicalDevice_getSettingGroupControlBlock(this.self); IntPtr sgcb = LogicalDevice_getSettingGroupControlBlock(self);
if (sgcb == IntPtr.Zero) if (sgcb == IntPtr.Zero)
return null; return null;
@ -410,12 +408,14 @@ namespace IEC61850
} }
} }
public enum AccessPolicy { public enum AccessPolicy
{
ACCESS_POLICY_ALLOW = 0, ACCESS_POLICY_ALLOW = 0,
ACCESS_POLICY_DENY = 1 ACCESS_POLICY_DENY = 1
} }
public enum DataAttributeType { public enum DataAttributeType
{
BOOLEAN = 0, BOOLEAN = 0,
INT8 = 1, INT8 = 1,
INT16 = 2, INT16 = 2,
@ -968,7 +968,7 @@ namespace IEC61850
public DataAttribute GetChildWithFc(string objRef, FunctionalConstraint fc) public DataAttribute GetChildWithFc(string objRef, FunctionalConstraint fc)
{ {
DataAttribute dataAttribute = null; DataAttribute dataAttribute = null;
IntPtr da = ModelNode_getChildWithFc(this.self, objRef, (int)fc); IntPtr da = ModelNode_getChildWithFc(self, objRef, (int)fc);
if (da != IntPtr.Zero) if (da != IntPtr.Zero)
{ {
@ -1155,7 +1155,7 @@ namespace IEC61850
} }
else else
{ {
if (this.parent != null) if (parent != null)
return parent.GetIedModel(); return parent.GetIedModel();
else else
return null; return null;
@ -1327,14 +1327,16 @@ namespace IEC61850
IntPtr objRefPtr = ModelNode_getObjectReferenceEx(self, nativeMemory, withoutIedName); IntPtr objRefPtr = ModelNode_getObjectReferenceEx(self, nativeMemory, withoutIedName);
if (objRefPtr != IntPtr.Zero) { if (objRefPtr != IntPtr.Zero)
{
string objRef = Marshal.PtrToStringAnsi(objRefPtr); string objRef = Marshal.PtrToStringAnsi(objRefPtr);
Marshal.FreeHGlobal(nativeMemory); Marshal.FreeHGlobal(nativeMemory);
return objRef; return objRef;
} }
else { else
{
Marshal.FreeHGlobal(nativeMemory); Marshal.FreeHGlobal(nativeMemory);
return null; return null;
@ -1795,7 +1797,7 @@ namespace IEC61850
if (token != IntPtr.Zero) if (token != IntPtr.Zero)
{ {
GCHandle handle = GCHandle.FromIntPtr(token); GCHandle handle = GCHandle.FromIntPtr(token);
return handle as object; return handle;
} }
} }
} }
@ -1915,7 +1917,7 @@ namespace IEC61850
if (lnModelNode != null && lnModelNode is LogicalNode) if (lnModelNode != null && lnModelNode is LogicalNode)
{ {
this.ln = lnModelNode as LogicalNode; ln = lnModelNode as LogicalNode;
} }
} }
@ -2132,7 +2134,8 @@ namespace IEC61850
IntPtr conPtr = ControlAction_getClientConnection(self); IntPtr conPtr = ControlAction_getClientConnection(self);
if (conPtr != IntPtr.Zero) { if (conPtr != IntPtr.Zero)
{
iedServer.clientConnections.TryGetValue(conPtr, out con); iedServer.clientConnections.TryGetValue(conPtr, out con);
} }
@ -2261,7 +2264,8 @@ namespace IEC61850
/// <summary> /// <summary>
/// Return type of ControlHandler and ControlWaitForExecutionHandler /// Return type of ControlHandler and ControlWaitForExecutionHandler
/// </summary> /// </summary>
public enum ControlHandlerResult { public enum ControlHandlerResult
{
/// <summary> /// <summary>
/// check or operation failed /// check or operation failed
/// </summary> /// </summary>
@ -2280,7 +2284,8 @@ namespace IEC61850
public delegate ControlHandlerResult ControlHandler(ControlAction action, object parameter, MmsValue ctlVal, bool test); public delegate ControlHandlerResult ControlHandler(ControlAction action, object parameter, MmsValue ctlVal, bool test);
public enum CheckHandlerResult { public enum CheckHandlerResult
{
/// <summary> /// <summary>
/// check passed /// check passed
/// </summary> /// </summary>
@ -2849,7 +2854,8 @@ namespace IEC61850
// hold references to managed LogStorage instances to avoid problems with GC // hold references to managed LogStorage instances to avoid problems with GC
private Dictionary<string, LogStorage> logStorages = new Dictionary<string, LogStorage>(); private Dictionary<string, LogStorage> logStorages = new Dictionary<string, LogStorage>();
internal class ControlHandlerInfo { internal class ControlHandlerInfo
{
public DataObject controlObject = null; public DataObject controlObject = null;
public GCHandle handle; public GCHandle handle;
@ -2868,12 +2874,12 @@ namespace IEC61850
public ControlHandlerInfo(DataObject controlObject) public ControlHandlerInfo(DataObject controlObject)
{ {
this.controlObject = controlObject; this.controlObject = controlObject;
this.handle = GCHandle.Alloc(this); handle = GCHandle.Alloc(this);
} }
~ControlHandlerInfo() ~ControlHandlerInfo()
{ {
this.handle.Free(); handle.Free();
} }
} }
@ -2904,7 +2910,8 @@ namespace IEC61850
ControlAction controlAction = new ControlAction(action, info, this); ControlAction controlAction = new ControlAction(action, info, this);
return (int)info.checkHandler(controlAction, info.checkHandlerParameter, new MmsValue(ctlVal), test, interlockCheck); return (int)info.checkHandler(controlAction, info.checkHandlerParameter, new MmsValue(ctlVal), test, interlockCheck);
} else }
else
return (int)CheckHandlerResult.OBJECT_UNDEFINED; return (int)CheckHandlerResult.OBJECT_UNDEFINED;
} }
@ -2938,7 +2945,8 @@ namespace IEC61850
} }
} }
private struct WriteAccessHandlerInfo { private struct WriteAccessHandlerInfo
{
public WriteAccessHandler handler; public WriteAccessHandler handler;
public InternalWriteAccessHandler internalHandler; public InternalWriteAccessHandler internalHandler;
public object parameter; public object parameter;
@ -2992,7 +3000,7 @@ namespace IEC61850
{ {
ClientConnection con = null; ClientConnection con = null;
this.clientConnections.TryGetValue(connection, out con); clientConnections.TryGetValue(connection, out con);
ModelNode ldModelNode = iedModel.GetModelNodeFromNodeRef(ld); ModelNode ldModelNode = iedModel.GetModelNodeFromNodeRef(ld);
ModelNode lnModelNode = iedModel.GetModelNodeFromNodeRef(ln); ModelNode lnModelNode = iedModel.GetModelNodeFromNodeRef(ln);
@ -3054,7 +3062,7 @@ namespace IEC61850
{ {
ClientConnection con = null; ClientConnection con = null;
this.clientConnections.TryGetValue(connection, out con); clientConnections.TryGetValue(connection, out con);
return dataSetAccessHandler(dataSetAccessHandlerParameter, con, (DataSetOperation)operation, datasetRef); return dataSetAccessHandler(dataSetAccessHandlerParameter, con, (DataSetOperation)operation, datasetRef);
} }
@ -3094,7 +3102,7 @@ namespace IEC61850
{ {
ClientConnection con = null; ClientConnection con = null;
this.clientConnections.TryGetValue(connection, out con); clientConnections.TryGetValue(connection, out con);
return activeSettingGroupChangedHandler(activeSettingGroupChangedHandlerParameter, new SettingGroupControlBlock(sgcb), newActSg, con); return activeSettingGroupChangedHandler(activeSettingGroupChangedHandlerParameter, new SettingGroupControlBlock(sgcb), newActSg, con);
} }
@ -3129,7 +3137,7 @@ namespace IEC61850
{ {
ClientConnection con = null; ClientConnection con = null;
this.clientConnections.TryGetValue(connection, out con); clientConnections.TryGetValue(connection, out con);
return editSettingGroupChangedHandler(editSettingGroupChangedHandlerParameter, new SettingGroupControlBlock(sgcb), newEditSg, con); return editSettingGroupChangedHandler(editSettingGroupChangedHandlerParameter, new SettingGroupControlBlock(sgcb), newEditSg, con);
} }
@ -3181,12 +3189,12 @@ namespace IEC61850
public SVCHandlerInfo(SVControlBlock sampledValuesControlBlock) public SVCHandlerInfo(SVControlBlock sampledValuesControlBlock)
{ {
this.sampledValuesControlBlock = sampledValuesControlBlock; this.sampledValuesControlBlock = sampledValuesControlBlock;
this.handle = GCHandle.Alloc(this); handle = GCHandle.Alloc(this);
} }
~SVCHandlerInfo() ~SVCHandlerInfo()
{ {
this.handle.Free(); handle.Free();
} }
} }
@ -3256,7 +3264,7 @@ namespace IEC61850
AcseAuthenticationParameter acseAuthenticationParameter = new AcseAuthenticationParameter(authParameter); AcseAuthenticationParameter acseAuthenticationParameter = new AcseAuthenticationParameter(authParameter);
IsoApplicationReference isoApplicationReference = new IsoApplicationReference(appReference); IsoApplicationReference isoApplicationReference = new IsoApplicationReference(appReference);
GCHandle token = GCHandle.FromIntPtr(securityToken); GCHandle token = GCHandle.FromIntPtr(securityToken);
return acseAuthenticatorHandler(acseAuthenticatorHandlerParameter, acseAuthenticationParameter, token as object, isoApplicationReference); return acseAuthenticatorHandler(acseAuthenticatorHandlerParameter, acseAuthenticationParameter, token, isoApplicationReference);
} }
return false; return false;
@ -3289,7 +3297,7 @@ namespace IEC61850
{ {
ClientConnection con = null; ClientConnection con = null;
this.clientConnections.TryGetValue(connection, out con); clientConnections.TryGetValue(connection, out con);
ModelNode ldModelNode = iedModel.GetModelNodeFromNodeRef(ld); ModelNode ldModelNode = iedModel.GetModelNodeFromNodeRef(ld);
ModelNode lnModelNode = iedModel.GetModelNodeFromNodeRef(ln); ModelNode lnModelNode = iedModel.GetModelNodeFromNodeRef(ln);
@ -3339,7 +3347,7 @@ namespace IEC61850
{ {
ClientConnection con = null; ClientConnection con = null;
this.clientConnections.TryGetValue(connection, out con); clientConnections.TryGetValue(connection, out con);
ModelNode ldModelNode = null; ModelNode ldModelNode = null;
@ -3357,19 +3365,23 @@ namespace IEC61850
private void ConnectionIndicationHandlerImpl(IntPtr iedServer, IntPtr clientConnection, bool connected, IntPtr parameter) private void ConnectionIndicationHandlerImpl(IntPtr iedServer, IntPtr clientConnection, bool connected, IntPtr parameter)
{ {
if (connected == false) { if (connected == false)
{
ClientConnection con = null; ClientConnection con = null;
clientConnections.TryGetValue(clientConnection, out con); clientConnections.TryGetValue(clientConnection, out con);
if (con != null) { if (con != null)
{
if (connectionHandler != null) if (connectionHandler != null)
connectionHandler(this, con, false, connectionHandlerParameter); connectionHandler(this, con, false, connectionHandlerParameter);
clientConnections.Remove(clientConnection); clientConnections.Remove(clientConnection);
} }
} else { }
else
{
ClientConnection con = new ClientConnection(clientConnection); ClientConnection con = new ClientConnection(clientConnection);
clientConnections.Add(clientConnection, con); clientConnections.Add(clientConnection, con);
@ -3402,7 +3414,7 @@ namespace IEC61850
public IedServer(IedModel iedModel, TLSConfiguration tlsConfig, IedServerConfig config = null) public IedServer(IedModel iedModel, TLSConfiguration tlsConfig, IedServerConfig config = null)
{ {
this.iedModel = iedModel; this.iedModel = iedModel;
this.tlsConfiguration = tlsConfig; tlsConfiguration = tlsConfig;
IntPtr nativeConfig = IntPtr.Zero; IntPtr nativeConfig = IntPtr.Zero;
IntPtr nativeTLSConfig = IntPtr.Zero; IntPtr nativeTLSConfig = IntPtr.Zero;
@ -3491,8 +3503,8 @@ namespace IEC61850
IedServer_destroy(self); IedServer_destroy(self);
self = IntPtr.Zero; self = IntPtr.Zero;
internalConnectionHandler = null; internalConnectionHandler = null;
this.iedModel = null; iedModel = null;
this.tlsConfiguration = null; tlsConfiguration = null;
} }
} }
} }
@ -3537,7 +3549,8 @@ namespace IEC61850
controlHandlers.TryGetValue(controlObject, out info); controlHandlers.TryGetValue(controlObject, out info);
if (info == null) { if (info == null)
{
info = new ControlHandlerInfo(controlObject); info = new ControlHandlerInfo(controlObject);
controlHandlers.Add(controlObject, info); controlHandlers.Add(controlObject, info);
} }
@ -3939,7 +3952,7 @@ namespace IEC61850
if (connection != IntPtr.Zero) if (connection != IntPtr.Zero)
{ {
this.clientConnections.TryGetValue(connection, out con); clientConnections.TryGetValue(connection, out con);
} }
ReportControlBlock reportControlBlock = null; ReportControlBlock reportControlBlock = null;

@ -1,7 +1,7 @@
/* /*
* IedServerConfig.cs * IedServerConfig.cs
* *
* Copyright 2018 Michael Zillgith * Copyright 2018-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -21,9 +21,9 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using IEC61850.Common;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using IEC61850.Common;
namespace IEC61850.Server namespace IEC61850.Server
{ {

@ -1,7 +1,7 @@
/* /*
* IsoConnectionParameters.cs * IsoConnectionParameters.cs
* *
* Copyright 2014 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -29,7 +29,8 @@ namespace IEC61850
namespace Client namespace Client
{ {
public enum AcseAuthenticationMechanism { public enum AcseAuthenticationMechanism
{
/** don't use authentication */ /** don't use authentication */
ACSE_AUTH_NONE = 0, ACSE_AUTH_NONE = 0,
/** use password authentication */ /** use password authentication */
@ -242,7 +243,8 @@ namespace IEC61850
/// </param> /// </param>
public void UsePasswordAuthentication(string password) public void UsePasswordAuthentication(string password)
{ {
if (authParameter == IntPtr.Zero) { if (authParameter == IntPtr.Zero)
{
authParameter = AcseAuthenticationParameter_create(); authParameter = AcseAuthenticationParameter_create();
AcseAuthenticationParameter_setAuthMechanism(authParameter, (int)AcseAuthenticationMechanism.ACSE_AUTH_PASSWORD); AcseAuthenticationParameter_setAuthMechanism(authParameter, (int)AcseAuthenticationMechanism.ACSE_AUTH_PASSWORD);
AcseAuthenticationParameter_setPassword(authParameter, password); AcseAuthenticationParameter_setPassword(authParameter, password);

@ -1,7 +1,7 @@
/* /*
* MmsValue.cs * MmsValue.cs
* *
* Copyright 2014 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -21,11 +21,8 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using System; using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections; using System.Collections;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace IEC61850 namespace IEC61850
@ -224,18 +221,18 @@ namespace IEC61850
internal MmsValue(IntPtr value) internal MmsValue(IntPtr value)
{ {
valueReference = value; valueReference = value;
this.responsableForDeletion = false; responsableForDeletion = false;
} }
public int EncodeMmsData(byte[] buffer, int bufPos, bool encode) public int EncodeMmsData(byte[] buffer, int bufPos, bool encode)
{ {
return MmsValue_encodeMmsData(this.valueReference, buffer, bufPos, encode); return MmsValue_encodeMmsData(valueReference, buffer, bufPos, encode);
} }
public int DecodeMmsData(int bufPos, int bufferLength, IntPtr endBufPo) public int DecodeMmsData(int bufPos, int bufferLength, IntPtr endBufPo)
{ {
return MmsValue_decodeMmsData(this.valueReference, bufPos, bufferLength, endBufPo); return MmsValue_decodeMmsData(valueReference, bufPos, bufferLength, endBufPo);
} }
internal MmsValue(IntPtr value, bool responsableForDeletion) internal MmsValue(IntPtr value, bool responsableForDeletion)
@ -285,8 +282,10 @@ namespace IEC61850
public void Dispose() public void Dispose()
{ {
lock (this) { lock (this)
if (valueReference != IntPtr.Zero) { {
if (valueReference != IntPtr.Zero)
{
if (responsableForDeletion) if (responsableForDeletion)
MmsValue_delete(valueReference); MmsValue_delete(valueReference);
@ -343,7 +342,7 @@ namespace IEC61850
valueReference = MmsValue_newOctetString(octetString.Length, octetString.Length); valueReference = MmsValue_newOctetString(octetString.Length, octetString.Length);
this.setOctetString (octetString); setOctetString(octetString);
} }
/// <summary> /// <summary>
@ -409,8 +408,9 @@ namespace IEC61850
/// Sets the binary time. /// Sets the binary time.
/// </summary> /// </summary>
/// <param name="timestamp">Timestamp.</param> /// <param name="timestamp">Timestamp.</param>
public void SetBinaryTime(UInt64 timestamp) { public void SetBinaryTime(UInt64 timestamp)
MmsValue_setBinaryTime (this.valueReference, timestamp); {
MmsValue_setBinaryTime(valueReference, timestamp);
} }
/// <summary> /// <summary>
@ -426,9 +426,11 @@ namespace IEC61850
/// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception> /// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception>
public ulong GetBinaryTimeAsUtcMs() public ulong GetBinaryTimeAsUtcMs()
{ {
if (GetType () == MmsType.MMS_BINARY_TIME) { if (GetType() == MmsType.MMS_BINARY_TIME)
{
return MmsValue_getBinaryTimeAsUtcMs(valueReference); return MmsValue_getBinaryTimeAsUtcMs(valueReference);
} else }
else
throw new MmsValueException("Value is not a time type"); throw new MmsValueException("Value is not a time type");
} }
@ -489,12 +491,16 @@ namespace IEC61850
/// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception> /// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception>
public int Size() public int Size()
{ {
if ((GetType () == MmsType.MMS_ARRAY) || (GetType () == MmsType.MMS_STRUCTURE)) { if ((GetType() == MmsType.MMS_ARRAY) || (GetType() == MmsType.MMS_STRUCTURE))
{
return MmsValue_getArraySize(valueReference); return MmsValue_getArraySize(valueReference);
} else if (GetType () == MmsType.MMS_BIT_STRING) { }
else if (GetType() == MmsType.MMS_BIT_STRING)
{
return MmsValue_getBitStringSize(valueReference); return MmsValue_getBitStringSize(valueReference);
} }
else if (GetType () == MmsType.MMS_OCTET_STRING) { else if (GetType() == MmsType.MMS_OCTET_STRING)
{
return MmsValue_getOctetStringSize(valueReference); return MmsValue_getOctetStringSize(valueReference);
} }
else else
@ -509,7 +515,8 @@ namespace IEC61850
/// </returns> /// </returns>
public int MaxSize() public int MaxSize()
{ {
if (GetType () == MmsType.MMS_OCTET_STRING) { if (GetType() == MmsType.MMS_OCTET_STRING)
{
return MmsValue_getOctetStringMaxSize(valueReference); return MmsValue_getOctetStringMaxSize(valueReference);
} }
else else
@ -527,9 +534,10 @@ namespace IEC61850
/// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception> /// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception>
public byte[] getOctetString() public byte[] getOctetString()
{ {
if (GetType () == MmsType.MMS_OCTET_STRING) { if (GetType() == MmsType.MMS_OCTET_STRING)
{
IntPtr buffer = MmsValue_getOctetStringBuffer(valueReference); IntPtr buffer = MmsValue_getOctetStringBuffer(valueReference);
int bufferSize = this.Size(); int bufferSize = Size();
byte[] octetString = new byte[bufferSize]; byte[] octetString = new byte[bufferSize];
@ -548,9 +556,10 @@ namespace IEC61850
/// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type or the byte array is too large.</exception> /// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type or the byte array is too large.</exception>
public void setOctetString(byte[] octetString) public void setOctetString(byte[] octetString)
{ {
if (GetType () == MmsType.MMS_OCTET_STRING) { if (GetType() == MmsType.MMS_OCTET_STRING)
{
if (this.MaxSize() < octetString.Length) if (MaxSize() < octetString.Length)
throw new MmsValueException("octet string is to large"); throw new MmsValueException("octet string is to large");
MmsValue_setOctetString(valueReference, octetString, octetString.Length); MmsValue_setOctetString(valueReference, octetString, octetString.Length);
@ -594,17 +603,21 @@ namespace IEC61850
{ {
MmsType type = GetType(); MmsType type = GetType();
if ((type == MmsType.MMS_ARRAY) || (type == MmsType.MMS_STRUCTURE)) { if ((type == MmsType.MMS_ARRAY) || (type == MmsType.MMS_STRUCTURE))
if ((index >= 0) && (index < Size ())) { {
if ((index >= 0) && (index < Size()))
{
IntPtr value = MmsValue_getElement(valueReference, index); IntPtr value = MmsValue_getElement(valueReference, index);
if (value == IntPtr.Zero) if (value == IntPtr.Zero)
return null; return null;
else else
return new MmsValue(value); return new MmsValue(value);
} else }
else
throw new MmsValueException("Index out of bounds"); throw new MmsValueException("Index out of bounds");
} else }
else
throw new MmsValueException("Value is of wrong type"); throw new MmsValueException("Value is of wrong type");
} }
@ -692,9 +705,11 @@ namespace IEC61850
/// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception> /// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception>
public void SetUtcTimeMs(ulong timeval) public void SetUtcTimeMs(ulong timeval)
{ {
if (GetType () == MmsType.MMS_UTC_TIME) { if (GetType() == MmsType.MMS_UTC_TIME)
{
MmsValue_setUtcTimeMs(valueReference, timeval); MmsValue_setUtcTimeMs(valueReference, timeval);
} else }
else
throw new MmsValueException("Value is not a time type"); throw new MmsValueException("Value is not a time type");
} }
@ -711,9 +726,11 @@ namespace IEC61850
/// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception> /// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception>
public ulong GetUtcTimeInMs() public ulong GetUtcTimeInMs()
{ {
if (GetType () == MmsType.MMS_UTC_TIME) { if (GetType() == MmsType.MMS_UTC_TIME)
{
return MmsValue_getUtcTimeInMs(valueReference); return MmsValue_getUtcTimeInMs(valueReference);
} else }
else
throw new MmsValueException("Value is not a time type"); throw new MmsValueException("Value is not a time type");
} }
@ -795,7 +812,7 @@ namespace IEC61850
{ {
DateTimeOffset retVal = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero); DateTimeOffset retVal = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
return retVal.AddMilliseconds ((double) msTime); return retVal.AddMilliseconds(msTime);
} }
/// <summary> /// <summary>
@ -1087,13 +1104,14 @@ namespace IEC61850
{ {
MmsValue otherValue = (MmsValue)obj; MmsValue otherValue = (MmsValue)obj;
return MmsValue_equals(this.valueReference, otherValue.valueReference); return MmsValue_equals(valueReference, otherValue.valueReference);
} }
// override standard ToString() method // override standard ToString() method
public override string ToString() public override string ToString()
{ {
switch (GetType ()) { switch (GetType())
{
case MmsType.MMS_VISIBLE_STRING: case MmsType.MMS_VISIBLE_STRING:
case MmsType.MMS_STRING: case MmsType.MMS_STRING:
return Marshal.PtrToStringAnsi(MmsValue_toString(valueReference)); return Marshal.PtrToStringAnsi(MmsValue_toString(valueReference));
@ -1119,12 +1137,16 @@ namespace IEC61850
bool first = true; bool first = true;
foreach (MmsValue element in this) { foreach (MmsValue element in this)
if (first) { {
if (first)
{
retString += element.ToString(); retString += element.ToString();
first = false; first = false;
} else { }
else
{
retString += ", " + element.ToString(); retString += ", " + element.ToString();
} }
} }
@ -1139,12 +1161,16 @@ namespace IEC61850
bool first = true; bool first = true;
foreach (MmsValue element in this) { foreach (MmsValue element in this)
if (first) { {
if (first)
{
retString += element.ToString(); retString += element.ToString();
first = false; first = false;
} else { }
else
{
retString += ", " + element.ToString(); retString += ", " + element.ToString();
} }
} }
@ -1182,7 +1208,8 @@ namespace IEC61850
index = -1; index = -1;
} }
public object Current { public object Current
{
get { return value.GetElement(index); } get { return value.GetElement(index); }
} }

@ -1,7 +1,7 @@
/* /*
* MmsVariableSpecification.cs * MmsVariableSpecification.cs
* *
* Copyright 2014-2024 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -21,11 +21,9 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using System; using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace IEC61850 namespace IEC61850
@ -73,7 +71,7 @@ namespace IEC61850
internal MmsVariableSpecification(IntPtr self, MmsVariableSpecification parent) internal MmsVariableSpecification(IntPtr self, MmsVariableSpecification parent)
{ {
this.self = self; this.self = self;
this.responsableForDeletion = false; responsableForDeletion = false;
this.parent = parent; this.parent = parent;
} }

@ -1,7 +1,7 @@
/* /*
* ReportControlBlock.cs * ReportControlBlock.cs
* *
* Copyright 2014-2018 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -20,11 +20,9 @@
* *
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using IEC61850.Common;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics;
using IEC61850.Common;
namespace IEC61850 namespace IEC61850
{ {
@ -199,7 +197,8 @@ namespace IEC61850
private void internalReportHandler(IntPtr parameter, IntPtr report) private void internalReportHandler(IntPtr parameter, IntPtr report)
{ {
try { try
{
if (this.report == null) if (this.report == null)
this.report = new Report(report); this.report = new Report(report);
@ -207,7 +206,8 @@ namespace IEC61850
if (reportHandler != null) if (reportHandler != null)
reportHandler(this.report, reportHandlerParameter); reportHandler(this.report, reportHandlerParameter);
} catch (Exception e) }
catch (Exception e)
{ {
// older versions of mono 2.10 (for linux?) cause this exception // older versions of mono 2.10 (for linux?) cause this exception
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
@ -218,7 +218,8 @@ namespace IEC61850
{ {
self = ClientReportControlBlock_create(objectReference); self = ClientReportControlBlock_create(objectReference);
if (self != IntPtr.Zero) { if (self != IntPtr.Zero)
{
this.iedConnection = iedConnection; this.iedConnection = iedConnection;
this.objectReference = objectReference; this.objectReference = objectReference;
} }
@ -234,8 +235,10 @@ namespace IEC61850
/// <see cref="IEC61850.Client.ReportControlBlock"/> was occupying.</remarks> /// <see cref="IEC61850.Client.ReportControlBlock"/> was occupying.</remarks>
public void Dispose() public void Dispose()
{ {
lock (this) { lock (this)
if (self != IntPtr.Zero) { {
if (self != IntPtr.Zero)
{
iedConnection.UninstallReportHandler(objectReference); iedConnection.UninstallReportHandler(objectReference);
@ -255,7 +258,7 @@ namespace IEC61850
public string GetObjectReference() public string GetObjectReference()
{ {
return this.objectReference; return objectReference;
} }
/// <summary> /// <summary>
@ -276,11 +279,12 @@ namespace IEC61850
{ {
this.reportHandler = new ReportHandler(reportHandler); this.reportHandler = new ReportHandler(reportHandler);
this.reportHandlerParameter = parameter; reportHandlerParameter = parameter;
if (reportHandlerInstalled == false) { if (reportHandlerInstalled == false)
{
string reportId = this.GetRptId (); string reportId = GetRptId();
if (internalHandler == null) if (internalHandler == null)
{ {
@ -418,11 +422,13 @@ namespace IEC61850
if (error != 0) if (error != 0)
throw new IedConnectionException("setRCBValues service failed", error); throw new IedConnectionException("setRCBValues service failed", error);
if (flagRptId) { if (flagRptId)
{
if (reportHandlerInstalled) { if (reportHandlerInstalled)
{
reportHandlerInstalled = false; reportHandlerInstalled = false;
InstallReportHandler(this.reportHandler, this.reportHandlerParameter); InstallReportHandler(reportHandler, reportHandlerParameter);
} }
} }
} }
@ -483,7 +489,8 @@ namespace IEC61850
if (entryIdRef == IntPtr.Zero) if (entryIdRef == IntPtr.Zero)
return null; return null;
else { else
{
MmsValue entryId = new MmsValue(entryIdRef); MmsValue entryId = new MmsValue(entryIdRef);
return entryId.getOctetString(); return entryId.getOctetString();

@ -1,7 +1,7 @@
/* /*
* Reporting.cs * Reporting.cs
* *
* Copyright 2014-2018 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -20,11 +20,10 @@
* *
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using System;
using System.Runtime.InteropServices;
using IEC61850.Common; using IEC61850.Common;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace IEC61850 namespace IEC61850
{ {

@ -1,7 +1,7 @@
/* /*
* SampledValuesControlBlock.cs * SampledValuesControlBlock.cs
* *
* Copyright 2017 Michael Zillgith * Copyright 2017-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -20,11 +20,9 @@
* *
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using IEC61850.Common;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics;
using IEC61850.Common;
namespace IEC61850 namespace IEC61850
{ {
@ -106,7 +104,7 @@ namespace IEC61850
public string GetObjectReference() public string GetObjectReference()
{ {
return this.objectReference; return objectReference;
} }
public IedClientError GetLastComError() public IedClientError GetLastComError()
@ -185,7 +183,8 @@ namespace IEC61850
public void Dispose() public void Dispose()
{ {
if (isDisposed == false) { if (isDisposed == false)
{
isDisposed = true; isDisposed = true;
ClientSVControlBlock_destroy(self); ClientSVControlBlock_destroy(self);
self = IntPtr.Zero; self = IntPtr.Zero;

@ -1,7 +1,7 @@
/* /*
* SampledValuedSubscriber.cs * SampledValuedSubscriber.cs
* *
* Copyright 2017 Michael Zillgith * Copyright 2017-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -21,9 +21,9 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using IEC61850.Common;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using IEC61850.Common;
namespace IEC61850 namespace IEC61850
{ {
@ -145,7 +145,8 @@ namespace IEC61850
/// <see cref="IEC61850.SV.Subscriber.SVReceiver"/> was occupying.</remarks> /// <see cref="IEC61850.SV.Subscriber.SVReceiver"/> was occupying.</remarks>
public void Dispose() public void Dispose()
{ {
if (isDisposed == false) { if (isDisposed == false)
{
isDisposed = true; isDisposed = true;
SVReceiver_destroy(self); SVReceiver_destroy(self);
self = IntPtr.Zero; self = IntPtr.Zero;
@ -199,14 +200,17 @@ namespace IEC61850
private void internalSVUpdateListener(IntPtr subscriber, IntPtr parameter, IntPtr asdu) private void internalSVUpdateListener(IntPtr subscriber, IntPtr parameter, IntPtr asdu)
{ {
try { try
{
if (listener != null) { if (listener != null)
{
listener(this, listenerParameter, new SVSubscriberASDU(asdu)); listener(this, listenerParameter, new SVSubscriberASDU(asdu));
} }
} }
catch (Exception e) { catch (Exception e)
{
// older versions of mono 2.10 (for linux?) cause this exception // older versions of mono 2.10 (for linux?) cause this exception
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
} }
@ -214,9 +218,12 @@ namespace IEC61850
public SVSubscriber(byte[] ethAddr, UInt16 appID) public SVSubscriber(byte[] ethAddr, UInt16 appID)
{ {
if (ethAddr == null) { if (ethAddr == null)
{
self = SVSubscriber_create(IntPtr.Zero, appID); self = SVSubscriber_create(IntPtr.Zero, appID);
} else { }
else
{
if (ethAddr.Length != 6) if (ethAddr.Length != 6)
throw new ArgumentException("ethAddr argument has to be of 6 byte size"); throw new ArgumentException("ethAddr argument has to be of 6 byte size");
@ -228,9 +235,10 @@ namespace IEC61850
public void SetListener(SVUpdateListener listener, object parameter) public void SetListener(SVUpdateListener listener, object parameter)
{ {
this.listener = listener; this.listener = listener;
this.listenerParameter = parameter; listenerParameter = parameter;
if (internalListener == null) { if (internalListener == null)
{
internalListener = new InternalSVUpdateListener(internalSVUpdateListener); internalListener = new InternalSVUpdateListener(internalSVUpdateListener);
SVSubscriber_setListener(self, internalListener, IntPtr.Zero); SVSubscriber_setListener(self, internalListener, IntPtr.Zero);
@ -239,7 +247,8 @@ namespace IEC61850
public void Dispose() public void Dispose()
{ {
if (isDisposed == false) { if (isDisposed == false)
{
isDisposed = true; isDisposed = true;
SVSubscriber_destroy(self); SVSubscriber_destroy(self);
self = IntPtr.Zero; self = IntPtr.Zero;
@ -357,7 +366,7 @@ namespace IEC61850
public UInt16 GetSmpRate() public UInt16 GetSmpRate()
{ {
return (UInt16)SVSubscriber_ASDU_getSmpRate (self); return SVSubscriber_ASDU_getSmpRate(self);
} }
public bool HasDatSet() public bool HasDatSet()

@ -21,14 +21,9 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
using System; using System;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using IEC61850.Common;
/// <summary> /// <summary>
/// IEC 61850 API for the libiec61850 .NET wrapper library /// IEC 61850 API for the libiec61850 .NET wrapper library
@ -114,7 +109,7 @@ namespace IEC61850
{ {
if (isValid) if (isValid)
{ {
return (TLSConfigVersion)TLSConnection_getTLSVersion((IntPtr)self); return (TLSConfigVersion)TLSConnection_getTLSVersion(self);
} }
else else
{ {
@ -136,7 +131,7 @@ namespace IEC61850
if (isValid) if (isValid)
{ {
IntPtr peerAddrBuf = Marshal.AllocHGlobal(130); IntPtr peerAddrBuf = Marshal.AllocHGlobal(130);
IntPtr peerAddrStr = TLSConnection_getPeerAddress(this.self, peerAddrBuf); IntPtr peerAddrStr = TLSConnection_getPeerAddress(self, peerAddrBuf);
string peerAddr = null; string peerAddr = null;
@ -331,8 +326,8 @@ namespace IEC61850
public void SetEventHandler(TLSEventHandler handler, object parameter) public void SetEventHandler(TLSEventHandler handler, object parameter)
{ {
this.eventHandler = handler; eventHandler = handler;
this.eventHandlerParameter = parameter; eventHandlerParameter = parameter;
if (internalTLSEventHandlerRef == null) if (internalTLSEventHandlerRef == null)
{ {

@ -374,8 +374,11 @@ namespace server_access_control
if (acseAuthenticationMechanism == IEC61850.AcseAuthenticationMechanism.ACSE_AUTH_PASSWORD) if (acseAuthenticationMechanism == IEC61850.AcseAuthenticationMechanism.ACSE_AUTH_PASSWORD)
{ {
int passwordLenght = authParameter.GetPasswordLenght(); byte[] passArray = authParameter.GetPasswordByteArray();
string password = authParameter.GetPassword(); int passwordLenght = passArray.Length;
string password = authParameter.GetPasswordString();
if (passwordLenght == passwords.First().Length) if (passwordLenght == passwords.First().Length)
{ {
if (password == passwords.First()) if (password == passwords.First())

@ -60,7 +60,7 @@ main(int argc, char** argv)
IsoConnectionParameters_setRemoteAddresses(parameters, remotePSelector, remoteSSelector, localTSelector); IsoConnectionParameters_setRemoteAddresses(parameters, remotePSelector, remoteSSelector, localTSelector);
IsoConnectionParameters_setLocalAddresses(parameters, localPSelector, localSSelector, remoteTSelector); IsoConnectionParameters_setLocalAddresses(parameters, localPSelector, localSSelector, remoteTSelector);
char* password = "top secret"; char* password = "user1@testpw";
/* use authentication */ /* use authentication */
AcseAuthenticationParameter auth = AcseAuthenticationParameter_create(); AcseAuthenticationParameter auth = AcseAuthenticationParameter_create();

@ -1,7 +1,7 @@
/* /*
* reporting.c * reporting.c
* *
* Copyright 2013-2024 Michael Zillgith * Copyright 2013-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *

@ -1,7 +1,7 @@
/* /*
* config_file_parser.c * config_file_parser.c
* *
* Copyright 2014-2024 Michael Zillgith * Copyright 2014-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *

@ -57,6 +57,8 @@ AcseAuthenticationParameter_setPassword(AcseAuthenticationParameter self, char*
self->value.password.passwordLength = strlen(password); self->value.password.passwordLength = strlen(password);
} }
/* TODO
->One function returning as string and another as by array*/
const char* const char*
AcseAuthenticationParameter_getPassword(AcseAuthenticationParameter self) AcseAuthenticationParameter_getPassword(AcseAuthenticationParameter self)
{ {

@ -1,7 +1,7 @@
/* /*
* mms_server.c * mms_server.c
* *
* Copyright 2013-2024 Michael Zillgith * Copyright 2013-2025 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *

Loading…
Cancel
Save