public static void printFiles(IedConnection con, string prefix, string parent) { List <FileDirectoryEntry> files = con.GetFileDirectory(parent); foreach (FileDirectoryEntry file in files) { Console.WriteLine(prefix + file.GetFileName() + "\t" + file.GetFileSize() + "\t" + MmsValue.MsTimeToDateTimeOffset(file.GetLastModified())); if (file.GetFileName().EndsWith("/")) { printFiles(con, prefix + " ", parent + file.GetFileName()); } } }
/// <summary> /// Gets the current owner of the RCB /// </summary> /// <returns>The owner information, or null when no owner information is available.</returns> public byte[] GetOwner() { IntPtr mmsValuePtr = ClientReportControlBlock_getOwner(self); if (mmsValuePtr != IntPtr.Zero) { MmsValue octetStringVal = new MmsValue(mmsValuePtr); return(octetStringVal.getOctetString()); } else { return(null); } }
/// <summary> /// Gets the entryID of RCB /// </summary> /// Returns the EntryID of the last received GetRCBValues service response. /// The EntryID is only present in buffered RCBs (BRCBs). /// /// <returns>The entry ID</returns> public byte[] GetEntryID() { IntPtr entryIdRef = ClientReportControlBlock_getEntryId(self); if (entryIdRef == IntPtr.Zero) { return(null); } else { MmsValue entryId = new MmsValue(entryIdRef); return(entryId.getOctetString()); } }
public void MmsValueClone() { MmsValue boolValue = new MmsValue(true); MmsValue boolClone = boolValue.Clone(); boolValue.Dispose(); boolClone.Dispose(); MmsValue structure = MmsValue.NewEmptyStructure(1); MmsValue structureClone = structure.Clone(); structure.Dispose(); structureClone.Dispose(); }
/// <summary> /// Gets the data set values as MMS_ARRAY instance. /// </summary> /// <returns> /// The data set values. /// </returns> public MmsValue GetDataSetValues() { if (dataSetValues == IntPtr.Zero) { dataSetValues = ClientReport_getDataSetValues(self); if (dataSetValues == IntPtr.Zero) { throw new IedConnectionException("No report values available yet"); } values = new MmsValue(dataSetValues); } return(values); }
private static void reportHandler(Report report, object parameter) { Console.WriteLine("Received report:\n----------------"); Console.WriteLine(" for RCB: " + report.GetRcbReference()); if (report.HasTimestamp()) { Console.WriteLine(" timestamp: " + MmsValue.MsTimeToDateTimeOffset(report.GetTimestamp()).ToString()); } MmsValue values = report.GetDataSetValues(); byte[] entryId = report.GetEntryId(); if (entryId != null) { SoapHexBinary shb = new SoapHexBinary(entryId); Console.WriteLine(" entryID: " + shb.ToString()); } if (report.HasDataSetName()) { Console.WriteLine(" report data set: " + report.GetDataSetName()); } Console.WriteLine(" report dataset contains " + values.Size() + " elements"); for (int i = 0; i < values.Size(); i++) { if (report.GetReasonForInclusion(i) != ReasonForInclusion.REASON_NOT_INCLUDED) { Console.WriteLine(" element " + i + " included for reason " + report.GetReasonForInclusion(i).ToString() + " " + values.GetElement(i)); } if (report.HasDataReference()) { Console.WriteLine(" data-ref: " + report.GetDataReference(i)); } } ReportControlBlock rcb = (ReportControlBlock)parameter; Console.WriteLine(" For RCB: " + rcb.GetObjectReference() + " Buffered: " + rcb.IsBuffered() + " data-set: " + rcb.GetDataSetReference()); }
private static void gooseListener (GooseSubscriber subscriber, object parameter) { Console.WriteLine ("Received GOOSE message:\n-------------------------"); Console.WriteLine (" stNum: " + subscriber.GetStNum ()); Console.WriteLine (" sqNum: " + subscriber.GetSqNum ()); MmsValue values = subscriber.GetDataSetValues (); Console.WriteLine (" values: " +values.Size ().ToString ()); foreach (MmsValue value in values) { Console.WriteLine (" value: " + value.ToString ()); } }
public void WriteAccessPolicy() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IEC61850.Server.DataAttribute opDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.OpDlTmms.setVal"); IEC61850.Server.DataAttribute rsDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.RsDlTmms.setVal"); IedServer iedServer = new IedServer(iedModel); iedServer.HandleWriteAccess(opDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { return(MmsDataAccessError.SUCCESS); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_ALLOW); connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY); connection.WriteValue("simpleIOGenericIO/PDUP1.OpDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); try { connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)999)); } catch (IedConnectionException e) { Assert.AreEqual(IedClientError.IED_ERROR_ACCESS_DENIED, e.GetIedClientError()); } MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms); Assert.AreEqual(1234, rsDlTmmsValue.ToInt32()); connection.Abort(); iedServer.Stop(); iedServer.Dispose(); }
/// <summary> /// Send a select with value command for generic MmsValue instances - asynchronous version /// </summary> /// <param name='ctlVal'>the value to be checked.</param> /// <param name="handler">Callback function to handle the received response or service timeout</param> /// <param name="parameter">User provided callback parameter. Will be passed to the callback function</param> /// <returns>the invoke ID of the sent request</returns> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> public UInt32 SelectWithValueAsync(MmsValue ctlVal, ControlActionHandler handler, object parameter) { int error; Tuple <ControlActionHandler, object> callbackInfo = Tuple.Create(handler, parameter); GCHandle handle = GCHandle.Alloc(callbackInfo); UInt32 invokeId = ControlObjectClient_selectWithValueAsync(self, out error, ctlVal.valueReference, nativeOperateHandler, GCHandle.ToIntPtr(handle)); if (error != 0) { handle.Free(); throw new IedConnectionException("Select with value failed", error); } return(invokeId); }
//reading values of every private void ReadingValues(MmsValue v, Report report) { string x = report.GetRcbReference(); x = x.Replace("GEDeviceF650/LLN0", ""); for (int i = 1; i < v.Size(); i++) { string name = report.GetDataReference(i); name = name.Replace("GEDeviceF650/", ""); if (!(v.GetElement(i).GetType() == MmsType.MMS_STRUCTURE)) { AddIfNotExist(v.GetElement(i).ToFloat(), name, x); } else { ReadingValues(v.GetElement(i), report); } } }
public void MmsValueStructure() { MmsValue val = MmsValue.NewEmptyStructure(2); val.SetElement(0, new MmsValue(true)); val.SetElement(1, MmsValue.NewBitString(10)); Assert.AreEqual(val.GetType(), MmsType.MMS_STRUCTURE); Assert.AreEqual(val.Size(), 2); MmsValue elem0 = val.GetElement(0); Assert.AreEqual(elem0.GetType(), MmsType.MMS_BOOLEAN); Assert.AreEqual(elem0.GetBoolean(), true); MmsValue elem1 = val.GetElement(1); Assert.AreEqual(elem1.GetType(), MmsType.MMS_BIT_STRING); }
/// <summary> /// Sets the element of an array of structure /// </summary> /// <param name="index">index of the element starting with 0</param> /// <param name="elementValue">MmsValue instance that will be used as element value</param> /// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type.</exception> /// <exception cref="MmsValueException">This exception is thrown if the index is out of range.</exception> public void SetElement(int index, MmsValue elementValue) { MmsType elementType = GetType(); if ((elementType == MmsType.MMS_ARRAY) || (elementType == MmsType.MMS_STRUCTURE)) { if ((index >= 0) && (index < Size())) { MmsValue_setElement(valueReference, index, elementValue.valueReference); } else { throw new MmsValueException("Index out of bounds"); } } else { throw new MmsValueException("Value is of wrong type"); } }
public void MmsValaueCreateStructureAndAddElement() { MmsValue structure1 = MmsValue.NewEmptyStructure(1); MmsValue structure2 = MmsValue.NewEmptyStructure(1); MmsValue element = MmsValue.NewEmptyStructure(1); structure1.SetElement(0, element); /* Clone is required when adding the value to another structure or element */ MmsValue elementClone = element.Clone(); structure2.SetElement(0, elementClone); element.Dispose(); structure1.Dispose(); structure2.Dispose(); Assert.AreEqual(true, true); }
public PhyComAddress GetDstAddress() { PhyComAddress addr = new PhyComAddress(); IntPtr value = ClientGooseControlBlock_getDstAddress_addr(self); MmsValue mmsValue = new MmsValue(value); byte[] dstMacAddr = mmsValue.getOctetString(); dstMacAddr.CopyTo(addr.dstAddress, 0); addr.dstAddress = dstMacAddr; addr.appId = ClientGooseControlBlock_getDstAddress_appid(self); addr.vlanId = ClientGooseControlBlock_getDstAddress_vid(self); addr.vlanPriority = ClientGooseControlBlock_getDstAddress_priority(self); return(addr); }
private static void reportHandler(Report report, object parameter) { Console.WriteLine("Received report:\n----------------"); if (report.HasTimestamp()) { Console.WriteLine(" timestamp: " + MmsValue.MsTimeToDateTimeOffset(report.GetTimestamp()).ToString()); } MmsValue values = report.GetDataSetValues(); Console.WriteLine(" report dataset contains " + values.Size() + " elements"); for (int i = 0; i < values.Size(); i++) { if (report.GetReasonForInclusion(i) != ReasonForInclusion.REASON_NOT_INCLUDED) { Console.WriteLine(" element " + i + " included for reason " + report.GetReasonForInclusion(i).ToString() + " " + values.GetElement(i)); } } }
public void MmsValueArray() { MmsValue val = MmsValue.NewEmptyArray(3); val.SetElement(0, new MmsValue(1)); val.SetElement(1, new MmsValue(2)); val.SetElement(2, new MmsValue(3)); Assert.AreEqual(val.GetType(), MmsType.MMS_ARRAY); Assert.AreEqual(val.Size(), 3); MmsValue elem0 = val.GetElement(0); Assert.AreEqual(elem0.GetType(), MmsType.MMS_INTEGER); Assert.AreEqual(elem0.ToInt32(), 1); MmsValue elem2 = val.GetElement(2); Assert.AreEqual(elem2.GetType(), MmsType.MMS_INTEGER); Assert.AreEqual(elem2.ToInt32(), 3); }
public static void printFiles(IedConnection con, string prefix, string parent) { bool moreFollows = false; List <FileDirectoryEntry> files = con.GetFileDirectoryEx(parent, null, out moreFollows); foreach (FileDirectoryEntry file in files) { Console.WriteLine(prefix + file.GetFileName() + "\t" + file.GetFileSize() + "\t" + MmsValue.MsTimeToDateTimeOffset(file.GetLastModified())); if (file.GetFileName().EndsWith("/")) { printFiles(con, prefix + " ", parent + file.GetFileName()); } } if (moreFollows) { Console.WriteLine("-- MORE FILES AVAILABLE --"); } }
public void ReadNonExistingObject() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IedServer iedServer = new IedServer(iedModel); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); MmsValue value = connection.ReadValue("simpleIOGenericIO/GGIO1.SPCSO1.stVal", FunctionalConstraint.MX); Assert.IsNotNull(value); Assert.AreEqual(MmsType.MMS_DATA_ACCESS_ERROR, value.GetType()); iedServer.Stop(); iedServer.Destroy(); }
public void TestCase() { var val = new MmsValue(10.0f); Assert.AreEqual(10.0f, val.ToFloat()); }
public static void Main(string[] args) { IedConnection con = new IedConnection(); string hostname; if (args.Length > 0) { hostname = args[0]; } else { hostname = "localhost"; } Console.WriteLine("Connect to " + hostname); try { con.Connect(hostname, 102); Console.WriteLine("Negotiated PDU size: " + con.GetMmsConnection().GetLocalDetail()); List <string> serverDirectory = con.GetServerDirectory(false); foreach (string deviceName in serverDirectory) { Console.WriteLine("LD: " + deviceName); List <string> deviceDirectory = con.GetLogicalDeviceDirectory(deviceName); foreach (string lnName in deviceDirectory) { Console.WriteLine(" LN: " + lnName); List <string> lcbs = con.GetLogicalNodeDirectory(deviceName + "/" + lnName, IEC61850.Common.ACSIClass.ACSI_CLASS_LCB); foreach (string lcbName in lcbs) { Console.WriteLine(" LCB: " + lcbName); MmsValue lcbValues = con.ReadValue(deviceName + "/" + lnName + "." + lcbName, FunctionalConstraint.LG); Console.WriteLine(" values: " + lcbValues.ToString()); } List <string> logs = con.GetLogicalNodeDirectory(deviceName + "/" + lnName, IEC61850.Common.ACSIClass.ACSI_CLASS_LOG); foreach (string logName in logs) { Console.WriteLine(" LOG: " + logName); } } } bool moreFollows; Console.WriteLine("\nQueryLogAfter:"); List <MmsJournalEntry> journalEntries = con.QueryLogAfter("simpleIOGenericIO/LLN0$EventLog", new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, out moreFollows); PrintJournalEntries(journalEntries); Console.WriteLine("\nQueryLogByTime:"); journalEntries = con.QueryLogByTime("simpleIOGenericIO/LLN0$EventLog", new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), DateTime.UtcNow, out moreFollows); PrintJournalEntries(journalEntries); con.Release(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } // release all resources - do NOT use the object after this call!! con.Dispose(); }
/// <summary>Write the value of a data attribute (DA) or functional constraint data object (FCDO).</summary> /// <description>This function can be used to write simple or complex variables (setpoints, parameters, descriptive values...) /// of the server.</description> /// <param name="objectReference">The object reference of a BDA.</param> /// <param name="fc">The functional constraint (FC) of the object</param> /// <param name="value">MmsValue object representing asimple or complex variable data</param> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> public void WriteValue(string objectReference, FunctionalConstraint fc, MmsValue value) { int error; IedConnection_writeObject (connection, out error, objectReference, (int)fc, value.valueReference); if (error != 0) throw new IedConnectionException ("Write value failed", error); }
public override bool Equals(object obj) { MmsValue otherValue = (MmsValue)obj; return(MmsValue_equals(this.valueReference, otherValue.valueReference)); }
public static void Main(string[] args) { IedConnection con = new IedConnection(); string hostname; if (args.Length > 0) { hostname = args[0]; } else { hostname = "10.0.2.2"; } Console.WriteLine("Connect to " + hostname); try { con.Connect(hostname, 102); List <string> serverDirectory = con.GetServerDirectory(false); foreach (string entry in serverDirectory) { Console.WriteLine("LD: " + entry); } List <string> lnDirectory = con.GetLogicalNodeDirectory("simpleIOGenericIO/LLN0", ACSIClass.ACSI_CLASS_DATA_SET); foreach (string entry in lnDirectory) { Console.WriteLine("Dataset: " + entry); } string vendor = con.ReadStringValue("simpleIOGenericIO/LLN0.NamPlt.vendor", FunctionalConstraint.DC); Console.WriteLine("Vendor: " + vendor); /* read FCDO */ MmsValue value = con.ReadValue("simpleIOGenericIO/GGIO1.AnIn1", FunctionalConstraint.MX); if (value.GetType() == MmsType.MMS_STRUCTURE) { Console.WriteLine("Value is of complex type"); for (int i = 0; i < value.Size(); i++) { Console.WriteLine(" element: " + value.GetElement(i).GetType()); if (value.GetElement(i).GetType() == MmsType.MMS_UTC_TIME) { Console.WriteLine(" -> " + value.GetElement(i).GetUtcTimeAsDateTimeOffset()); } } } DataSet dataSet = con.ReadDataSetValues("simpleIOGenericIO/LLN0.Events", null); Console.WriteLine("Read data set " + dataSet.GetReference()); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } System.Threading.Thread.Sleep(2000); // release all resources - do NOT use the object after this call!! con.Dispose(); }
public bool Operate(MmsValue ctlVal, UInt64 operTime) { return(ControlObjectClient_operate(controlObject, ctlVal.valueReference, operTime)); }
/// <summary> /// Gets the tome of control execution as data time offset. /// </summary> /// <returns>The control execution time as data time offset.</returns> public DateTimeOffset GetControlTimeAsDataTimeOffset() { return(MmsValue.MsTimeToDateTimeOffset(GetControlTime())); }
/// <summary> /// Gets the values associated with the data set object /// </summary> /// <description>This function will return the locally stored values associated with the data set. /// These are the values received by the last request to the server. A call to this method doesn't /// invoke a request to the server! </description> /// <returns> /// The locally stored values of the data set (as MmsValue instance of type MMS_ARRAY) /// </returns> public MmsValue GetValues() { if (values == null) { IntPtr nativeValues = ClientDataSet_getValues (nativeObject); values = new MmsValue (nativeValues, false); } return values; }
/// <summary> /// Gets the data set values as MMS_ARRAY instance. /// </summary> /// <returns> /// The data set values. /// </returns> public MmsValue GetDataSetValues() { if (dataSetValues == IntPtr.Zero) { dataSetValues = ClientReport_getDataSetValues(self); if (dataSetValues == IntPtr.Zero) throw new IedConnectionException("No report values available yet"); values = new MmsValue(dataSetValues); } return values; }
/// <summary> /// Gets the EntryID of this report. /// </summary> /// <returns>The entryID as a byte array representing an MMS octet string.</returns> public byte[] GetEntryId() { IntPtr entryIdRef = ClientReport_getEntryId (self); if (entryIdRef == IntPtr.Zero) return null; else { MmsValue entryId = new MmsValue (entryIdRef); return entryId.getOctetString (); } }
/// <summary>Read the value of a basic data attribute (BDA) of type timestamp (MMS_UTC_TIME).</summary> /// <param name="objectReference">The object reference of a BDA.</param> /// <param name="fc">The functional constraint (FC) of the object</param> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> public UInt64 ReadTimestampValue(string objectReference, FunctionalConstraint fc) { var mmsValuePtr = readObjectInternal (objectReference, fc); var mmsValue = new MmsValue (mmsValuePtr, true); if (mmsValue.GetType () == MmsType.MMS_UTC_TIME) return mmsValue.GetUtcTimeInMs (); else throw new IedConnectionException ("Result is not of type timestamp (MMS_UTC_TIME)", 0); }
/// <summary> /// Send a select with value command for generic MmsValue instances /// </summary> /// <param name='ctlVal'> /// the value to be checked. /// </param> /// <returns>true when the selection has been successful, false otherwise</returns> public bool SelectWithValue(MmsValue ctlVal) { return ControlObjectClient_selectWithValue(controlObject, ctlVal.valueReference); }
/// <summary> /// Operate the control with the specified control value (time activated control). /// </summary> /// <param name='ctlVal'>the new value of the control</param> /// <param name='operTime'>the time when the operation will be executed</param> /// <returns>true when the operation has been successful, false otherwise</returns> public bool Operate(int ctlVal, UInt64 operTime) { MmsValue value = new MmsValue(ctlVal); return Operate (value, operTime); }
/// <summary> /// Operate the control with the specified control value (time activated control). /// </summary> /// <param name='ctlVal'>the new value of the control</param> /// <param name='operTime'>the time when the operation will be executed</param> /// <returns>true when the operation has been successful, false otherwise</returns> public bool Operate(MmsValue ctlVal, UInt64 operTime) { return ControlObjectClient_operate(controlObject, ctlVal.valueReference, operTime); }
public bool Operate(MmsValue ctlVal) { return(Operate(ctlVal, 0)); }
public Timestamp(MmsValue mmsUtcTime) : this() { SetByMmsUtcTime(mmsUtcTime); }
public bool Operate(float ctlVal, UInt64 operTime) { MmsValue value = new MmsValue(ctlVal); return(Operate(value, operTime)); }
public void SetByMmsUtcTime(MmsValue mmsValue) { Timestamp_setByMmsUtcTime(timestampRef, mmsValue.valueReference); }
public void UpdateAttributeValue(DataAttribute dataAttr, MmsValue value) { IedServer_updateAttributeValue(self, dataAttr.self, value.valueReference); }
/// <summary> /// Operate the control with the specified control value. /// </summary> /// <param name='ctlVal'>the new value of the control</param> /// <returns>true when the operation has been successful, false otherwise</returns> public bool Operate(MmsValue ctlVal) { return Operate (ctlVal, 0); }
public MmsValueEnumerator(MmsValue value) { this.value = value; }
/// <summary>Read the value of a basic data attribute (BDA) of type integer (MMS_INTEGER).</summary> /// <description>This function should also be used if enumerations are beeing read. Because /// enumerations are mapped to integer types for the MMS mapping</description> /// <param name="objectReference">The object reference of a BDA.</param> /// <param name="fc">The functional constraint (FC) of the object</param> /// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception> public Int64 ReadIntegerValue(string objectReference, FunctionalConstraint fc) { var mmsValuePtr = readObjectInternal (objectReference, fc); var mmsValue = new MmsValue (mmsValuePtr, true); if (mmsValue.GetType () == MmsType.MMS_INTEGER) return mmsValue.ToInt64 (); else throw new IedConnectionException ("Result is not of type integer (MMS_INTEGER)", 0); }