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); float setMagF = con.ReadFloatValue("ied1Inverter/ZINV1.OutWSet.setMag.f", FunctionalConstraint.SP); Console.WriteLine("ied1Inverter/ZINV1.OutWSet.setMag.f: " + setMagF); setMagF += 1.0f; con.WriteValue("ied1Inverter/ZINV1.OutWSet.setMag.f", FunctionalConstraint.SP, new MmsValue(setMagF)); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine("IED connection excepion: " + e.Message); } }
public ResultDatasetModel ReadDataset(string hostip, Int32 port, string dataaddress) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //read data set DataSet mmsresult = con.ReadDataSetValues(dataaddress, null); //get data set values List <Dataset_Result> valuelist = new List <Dataset_Result>(); data_extract dataExtract = new data_extract(); List <string> DataSetDirectory = con.GetDataSetDirectory(dataaddress); int i = 0; foreach (MmsValue value in mmsresult.GetValues()) { var ValueTuple = dataExtract.ExtractValue(value); valuelist.Add(new Dataset_Result { Address = DataSetDirectory[i], Value = ValueTuple }); i += 1; } //con close con.Abort(); ResultDatasetModel result = new ResultDatasetModel { data = valuelist, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultDatasetModel result = new ResultDatasetModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy result con.Dispose(); //result return(result); } }
public void AccessDataModelClientServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); ModelNode ind1 = iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.Ind1.stVal"); Assert.IsTrue(ind1.GetType().Equals(typeof(IEC61850.Server.DataAttribute))); IedServer iedServer = new IedServer(iedModel); iedServer.Start(10002); iedServer.UpdateBooleanAttributeValue((IEC61850.Server.DataAttribute)ind1, true); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); bool stVal = connection.ReadBooleanValue("simpleIOGenericIO/GGIO1.Ind1.stVal", FunctionalConstraint.ST); Assert.IsTrue(stVal); iedServer.UpdateBooleanAttributeValue((IEC61850.Server.DataAttribute)ind1, false); stVal = connection.ReadBooleanValue("simpleIOGenericIO/GGIO1.Ind1.stVal", FunctionalConstraint.ST); Assert.IsFalse(stVal); connection.Abort(); iedServer.Stop(); iedServer.Destroy(); }
public static void Main(string[] args) { IedConnection con = new IedConnection(); string hostname; if (args.Length > 0) { hostname = args [0]; } else { //hostname = "localhost"; hostname = "172.23.44.10"; } Console.WriteLine("Connect to " + hostname); try { con.Connect(hostname, 102); string rcbReference = "simpleIOGenericIO/LLN0.RP.EventsRCB01"; ReportControlBlock rcb = con.GetReportControlBlock(rcbReference); rcb.GetRCBValues(); // note: the second parameter is not required! rcb.InstallReportHandler(reportHandler, rcb); if (rcb.IsBuffered()) { Console.WriteLine("RCB: " + rcbReference + " is buffered"); } Console.WriteLine(rcb.GetDataSetReference()); rcb.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb.SetIntgPd(5000); rcb.SetRptEna(true); rcb.SetRCBValues(); /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; ReportingExample.running = false; }; while (running) { Thread.Sleep(10); } con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } }
public void ControlWriteAccessToServer() { 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); int opDlTmmsValue = 0; iedServer.HandleWriteAccess(opDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { opDlTmmsValue = value.ToInt32(); return(MmsDataAccessError.SUCCESS); }, null); iedServer.HandleWriteAccess(rsDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { if (value.ToInt32() > 1000) { return(MmsDataAccessError.OBJECT_VALUE_INVALID); } else { return(MmsDataAccessError.SUCCESS); } }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); connection.WriteValue("simpleIOGenericIO/PDUP1.OpDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); try { connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); } catch (IedConnectionException e) { Assert.AreEqual(IedClientError.IED_ERROR_OBJECT_VALUE_INVALID, e.GetIedClientError()); } connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)999)); MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms); Assert.AreEqual(999, rsDlTmmsValue.ToInt32()); connection.Abort(); iedServer.Stop(); Assert.AreEqual((int)1234, opDlTmmsValue); iedServer.Destroy(); }
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); Console.WriteLine("Files in server root directory:"); List <string> serverDirectory = con.GetServerDirectory(true); foreach (string entry in serverDirectory) { Console.WriteLine(entry); } Console.WriteLine(); Console.WriteLine("File directory tree at server:"); printFiles(con, "", ""); Console.WriteLine(); string filename = "IEDSERVER.BIN"; Console.WriteLine("Download file " + filename); /* Download file from server and write it to a new local file */ FileStream fs = new FileStream(filename, FileMode.Create); BinaryWriter w = new BinaryWriter(fs); con.GetFile(filename, new IedConnection.GetFileHandler(getFileHandler), w); fs.Close(); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } // release all resources - do NOT use the object after this call!! con.Dispose(); }
public ResultValueModel WriteValue(string hostip, Int32 port, string varaddress, string FC, dynamic newvalue) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //extract fc data_extract dataExtract = new data_extract(); var FunctionCode = dataExtract.ExtractFC(FC); var Value = dataExtract.ExtractValue(newvalue); dynamic mmsresult = null; //validate datatype mmsresult = con.WriteValue(varaddress, FunctionCode, new MmsValue(Value)); //con close con.Abort(); //result Value_Result listresult = new Value_Result { Address = varaddress, Value = mmsresult, }; ResultValueModel result = new ResultValueModel { data = listresult, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultValueModel result = new ResultValueModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy result con.Dispose(); //result return(result); } }
public void ConnectionHandler() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); int handlerCalled = 0; int connectionCount = 0; IedServer iedServer = new IedServer(iedModel); string ipAddress = null; iedServer.SetConnectionIndicationHandler(delegate(IedServer server, ClientConnection clientConnection, bool connected, object parameter) { handlerCalled++; if (connected) { connectionCount++; } else { connectionCount--; } ipAddress = clientConnection.GetPeerAddress(); }, null); iedServer.Start(10002); IedConnection con1 = new IedConnection(); con1.Connect("localhost", 10002); Assert.AreEqual(1, handlerCalled); Assert.AreEqual(1, connectionCount); IedConnection con2 = new IedConnection(); con2.Connect("localhost", 10002); Assert.AreEqual(2, handlerCalled); Assert.AreEqual(2, connectionCount); con1.Abort(); con2.Abort(); Assert.AreEqual(4, handlerCalled); Assert.AreEqual(0, connectionCount); Assert.AreEqual("127.0.0.1:", ipAddress.Substring(0, 10)); iedServer.Stop(); iedServer.Dispose(); }
public void ControlWriteAccessComplexDAToServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model2.cfg"); IEC61850.Server.DataAttribute setAnVal_setMag = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/LLN0.SetAnVal.setMag"); IedServer iedServer = new IedServer(iedModel); int handlerCalled = 0; MmsValue receivedValue = null; iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY); iedServer.HandleWriteAccessForComplexAttribute(setAnVal_setMag, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { receivedValue = value; handlerCalled++; return(MmsDataAccessError.SUCCESS); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); MmsValue complexValue = MmsValue.NewEmptyStructure(1); complexValue.SetElement(0, new MmsValue((float)1.0)); connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag", FunctionalConstraint.SP, complexValue); Assert.NotNull(receivedValue); Assert.AreEqual(MmsType.MMS_STRUCTURE, receivedValue.GetType()); Assert.AreEqual(1.0, receivedValue.GetElement(0).ToFloat()); receivedValue.Dispose(); receivedValue = null; connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag.f", FunctionalConstraint.SP, new MmsValue((float)2.0)); Assert.NotNull(receivedValue); Assert.AreEqual(MmsType.MMS_FLOAT, receivedValue.GetType()); Assert.AreEqual(2.0, receivedValue.ToFloat()); connection.Abort(); iedServer.Stop(); iedServer.Dispose(); }
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); Console.WriteLine ("Files in server root directory:"); List<string> serverDirectory = con.GetServerDirectory(true); foreach (string entry in serverDirectory) { Console.WriteLine(entry); } Console.WriteLine(); Console.WriteLine ("File directory tree at server:"); printFiles(con, "", ""); Console.WriteLine(); string filename = "IEDSERVER.BIN"; Console.WriteLine("Download file " + filename); /* Download file from server and write it to a new local file */ FileStream fs = new FileStream(filename, FileMode.Create); BinaryWriter w = new BinaryWriter(fs); con.GetFile(filename, new IedConnection.GetFileHandler(getFileHandler), w); fs.Close(); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } }
public void ControlHandler() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); Assert.IsNotNull(spcso1); int handlerCalled = 0; IedServer iedServer = new IedServer(iedModel); iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) { byte [] orIdent = action.GetOrIdent(); string orIdentStr = System.Text.Encoding.UTF8.GetString(orIdent, 0, orIdent.Length); Assert.AreEqual("TEST1234", orIdentStr); Assert.AreEqual(OrCat.MAINTENANCE, action.GetOrCat()); Assert.AreSame(spcso1, action.GetControlObject()); handlerCalled++; return(ControlHandlerResult.OK); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); ControlObject controlClient = connection.CreateControlObject("simpleIOGenericIO/GGIO1.SPCSO1"); controlClient.SetOrigin("TEST1234", OrCat.MAINTENANCE); Assert.IsNotNull(controlClient); controlClient.Operate(true); connection.Abort(); Assert.AreEqual(1, handlerCalled); iedServer.Stop(); iedServer.Destroy(); }
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(); }
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); string objectReference = "IEDM1CPUBHKW/DRCC1.DERStr"; ControlObject control = con.CreateControlObject(objectReference); ControlModel controlModel = control.GetControlModel(); Console.WriteLine(objectReference + " has control model " + controlModel.ToString()); if (!control.Operate(true)) { Console.WriteLine("operate failed!"); } con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } }
public m61850(string host) { _host = host; _conn = new IedConnection(); Console.WriteLine("Connect to " + _host); try { IedConnect(); Console.WriteLine("Files in server root directory:"); List <string> serverDirectory = _conn.GetServerDirectory(true); foreach (string entry in serverDirectory) { Console.WriteLine(entry); } Console.WriteLine(); Console.WriteLine("File directory tree at server:"); printFiles(_conn, "", ""); Console.WriteLine(); if (!Directory.Exists(@"COMTRADE")) { Directory.CreateDirectory(@"COMTRADE"); } DirectoryInfo di = new DirectoryInfo(@"COMTRADE"); foreach (var fi in di.GetFiles()) { fileList.Add($"/COMTRADE/{fi.Name}"); } _conn.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } //_conn.Dispose(); }
public void UpdateComtradeFiles() { IedConnect(); List <string> serverDirectory = _conn.GetServerDirectory(true); foreach (string entry in serverDirectory) { string tmp = entry.Replace("/", "\\"); if (!fileList.Contains(entry)) { string filename = $"{AppDomain.CurrentDomain.BaseDirectory}{tmp}"; Console.WriteLine($"Download file {entry}"); FileStream fs = new FileStream(filename, FileMode.Create); BinaryWriter w = new BinaryWriter(fs); fileList.Add(entry); _conn.GetFile(entry, new IedConnection.GetFileHandler(getFileHandler), w); //fs.Close(); } } _conn.Abort(); }
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); float setMagF = con.ReadFloatValue("ied1Inverter/ZINV1.OutWSet.setMag.f", FunctionalConstraint.SP); Console.WriteLine("ied1Inverter/ZINV1.OutWSet.setMag.f: " + setMagF); setMagF += 1.0f; con.WriteValue("ied1Inverter/ZINV1.OutWSet.setMag.f", FunctionalConstraint.SP, new MmsValue(setMagF)); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine("IED connection excepion: " + e.Message); } // release all resources - do NOT use the object after this call!! con.Dispose(); }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Test implementations public static void TestClient() { IedConnection con = new IedConnection(); try { System.Windows.Forms.MessageBox.Show("Server Start"); con.Connect("localhost", 102); List <string> serverDirectory = con.GetServerDirectory(false); foreach (string entry in serverDirectory) { System.Windows.Forms.MessageBox.Show("LD: " + entry); } con.Abort(); } catch (IedConnectionException e) { System.Windows.Forms.MessageBox.Show(e.Message); } con.Dispose(); }
public void ControlHandler() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); Assert.IsNotNull(spcso1); int handlerCalled = 0; IedServer iedServer = new IedServer(iedModel); iedServer.SetControlHandler(spcso1, delegate(DataObject controlObject, object parameter, MmsValue ctlVal, bool test) { handlerCalled++; return(ControlHandlerResult.OK); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); ControlObject controlClient = connection.CreateControlObject("simpleIOGenericIO/GGIO1.SPCSO1"); Assert.IsNotNull(controlClient); controlClient.Operate(true); connection.Abort(); Assert.AreEqual(1, handlerCalled); iedServer.Stop(); iedServer.Destroy(); }
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); // create a new data set List<string> dataSetElements = new List<string>(); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn1.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn2.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn3.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn4.mag.f[MX]"); // permanent (domain specific) data set //string dataSetReference = "simpleIOGenericIO/LLN0.ds1"; // temporary (association specific) data set string dataSetReference = "@newds"; // Note: this function will throw an exception when a data set with the same name already exists con.CreateDataSet(dataSetReference, dataSetElements); // reconfigure existing RCB with new data set string rcbReference = "simpleIOGenericIO/LLN0.RP.EventsRCB01"; ReportControlBlock rcb = con.GetReportControlBlock(rcbReference); rcb.GetRCBValues(); // note: the second parameter is not required! rcb.InstallReportHandler(reportHandler, rcb); string rcbDataSetReference = dataSetReference.Replace('.', '$'); rcb.SetDataSetReference(rcbDataSetReference); rcb.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb.SetIntgPd(5000); rcb.SetRptEna(true); rcb.SetRCBValues(); /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; while (running) { Thread.Sleep(1000); } // delete the data set con.DeleteDataSet(dataSetReference); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message + " reason: " + e.GetIedClientError().ToString()); } }
public static void Main(string[] args) { Console.WriteLine("Hello World!"); IedConnection con = new IedConnection(); string hostname; if (args.Length > 0) { hostname = args[0]; } else { hostname = "127.0.0.1"; } int port = 102; if (args.Length > 1) { port = Int32.Parse(args [1]); } Console.WriteLine("Connect to " + hostname); try { con.Connect(hostname, port); /* Get variable specification of the SGCB (optional) */ MmsVariableSpecification sgcbVarSpec = con.GetVariableSpecification("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP); /* Read SGCB */ MmsValue sgcbVal = con.ReadValue("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP); Console.WriteLine("NumOfSG: {0}", sgcbVal.GetChildValue("NumOfSG", sgcbVarSpec).ToString()); Console.WriteLine("ActSG: {0}", sgcbVal.GetChildValue("ActSG", sgcbVarSpec).ToString()); Console.WriteLine("EditSG: {0}", sgcbVal.GetChildValue("EditSG", sgcbVarSpec).ToString()); Console.WriteLine("CnfEdit: {0}", sgcbVal.GetChildValue("CnfEdit", sgcbVarSpec).ToString()); /* Set active setting group */ con.WriteValue("DEMOPROT/LLN0.SGCB.ActSG", FunctionalConstraint.SP, new MmsValue((uint)2)); /* Set edit setting group */ con.WriteValue("DEMOPROT/LLN0.SGCB.EditSG", FunctionalConstraint.SP, new MmsValue((uint)1)); /* Change a setting group value */ con.WriteValue("DEMOPROT/PTOC1.StrVal.setMag.f", FunctionalConstraint.SE, new MmsValue(1.0f)); /* Confirm new setting group values */ con.WriteValue("DEMOPROT/LLN0.SGCB.CnfEdit", FunctionalConstraint.SP, new MmsValue(true)); /* Read SGCB again */ sgcbVal = con.ReadValue("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP); Console.WriteLine("ActSG: {0}", sgcbVal.GetChildValue("ActSG", sgcbVarSpec).ToString()); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } // release all resources - do NOT use the object after this call!! con.Dispose(); }
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); /* direct control with normal security or SBO with normal security */ string objectReference = "simpleIOGenericIO/GGIO1.SPCSO1"; ControlObject control = con.CreateControlObject(objectReference); ControlModel controlModel = control.GetControlModel(); Console.WriteLine(objectReference + " has control model " + controlModel.ToString()); switch (controlModel) { case ControlModel.STATUS_ONLY: Console.WriteLine("Control is status-only!"); break; case ControlModel.DIRECT_NORMAL: case ControlModel.DIRECT_ENHANCED: if (!control.Operate(true)) { Console.WriteLine("operate failed!"); } else { Console.WriteLine("operated successfully!"); } break; case ControlModel.SBO_NORMAL: case ControlModel.SBO_ENHANCED: if (control.Select()) { if (!control.Operate(true)) { Console.WriteLine("operate failed!"); } else { Console.WriteLine("operated successfully!"); } } else { Console.WriteLine("Select failed!"); } break; } /* direct control with enhanced security */ objectReference = "simpleIOGenericIO/GGIO1.SPCSO3"; control = con.CreateControlObject(objectReference); controlModel = control.GetControlModel(); Console.WriteLine(objectReference + " has control model " + controlModel.ToString()); if (controlModel == ControlModel.DIRECT_ENHANCED) { control.SetCommandTerminationHandler(commandTerminationHandler, null); control.Operate(true); Thread.Sleep(1000); } con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } // release all resources - do NOT use the object after this call!! con.Dispose(); }
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); // create a new data set List <string> dataSetElements = new List <string>(); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn1.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn2.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn3.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn4.mag.f[MX]"); // permanent (domain specific) data set //string dataSetReference = "simpleIOGenericIO/LLN0.ds1"; // temporary (association specific) data set string dataSetReference = "@newds"; // Note: this function will throw an exception when a data set with the same name already exists con.CreateDataSet(dataSetReference, dataSetElements); // reconfigure existing RCB with new data set string rcbReference = "simpleIOGenericIO/LLN0.RP.EventsRCB01"; ReportControlBlock rcb = con.GetReportControlBlock(rcbReference); rcb.GetRCBValues(); // note: the second parameter is not required! rcb.InstallReportHandler(reportHandler, rcb); string rcbDataSetReference = dataSetReference.Replace('.', '$'); rcb.SetDataSetReference(rcbDataSetReference); rcb.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb.SetIntgPd(5000); rcb.SetRptEna(true); rcb.SetRCBValues(); /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; while (running) { Thread.Sleep(1000); } // delete the data set con.DeleteDataSet(dataSetReference); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message + " reason: " + e.GetIedClientError().ToString()); } // release all resources - do NOT use the object after this call!! con.Dispose(); }
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); } // create a new data set List <string> dataSetElements = new List <string>(); dataSetElements.Add("IEDM1CPUBHKW/DRCS1.ModOnConn.stVal[ST]"); dataSetElements.Add("IEDM1CPUBHKW/DRCS1.ModOnConn.t[ST]"); con.CreateDataSet("IEDM1CPUBHKW/LLN0.ds1", dataSetElements); // get the directory of the data set List <string> dataSetDirectory = con.GetDataSetDirectory("IEDM1CPUBHKW/LLN0.ds1"); foreach (string entry in dataSetDirectory) { Console.WriteLine("DS element: " + entry); } // read the values of the newly created data set DataSet dataSet = con.ReadDataSetValues("IEDM1CPUBHKW/LLN0.ds1", null); MmsValue dataSetValues = dataSet.GetValues(); Console.WriteLine("Data set contains " + dataSetValues.Size() + " elements"); foreach (MmsValue value in dataSetValues) { Console.WriteLine(" DS value: " + value + " type: " + value.GetType()); } // delete the data set con.DeleteDataSet("IEDM1CPUBHKW/LLN0.ds1"); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } }
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); /* direct control with normal security or SBO with normal security */ string objectReference = "simpleIOGenericIO/GGIO1.SPCSO1"; ControlObject control = con.CreateControlObject(objectReference); ControlModel controlModel = control.GetControlModel(); Console.WriteLine(objectReference + " has control model " + controlModel.ToString()); switch (controlModel) { case ControlModel.STATUS_ONLY: Console.WriteLine("Control is status-only!"); break; case ControlModel.DIRECT_NORMAL: case ControlModel.DIRECT_ENHANCED: if (!control.Operate(true)) Console.WriteLine("operate failed!"); else Console.WriteLine("operated successfully!"); break; case ControlModel.SBO_NORMAL: case ControlModel.SBO_ENHANCED: if (control.Select()) { if (!control.Operate(true)) Console.WriteLine("operate failed!"); else Console.WriteLine("operated successfully!"); } else Console.WriteLine("Select failed!"); break; } /* direct control with enhanced security */ objectReference = "simpleIOGenericIO/GGIO1.SPCSO3"; control = con.CreateControlObject(objectReference); controlModel = control.GetControlModel(); Console.WriteLine(objectReference + " has control model " + controlModel.ToString()); if (controlModel == ControlModel.DIRECT_ENHANCED) { control.SetCommandTerminationHandler(commandTerminationHandler, null); control.Operate(true); Thread.Sleep(1000); } con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } }
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); string rcbReference1 = "simpleIOGenericIO/LLN0.RP.EventsRCB01"; string rcbReference2 = "simpleIOGenericIO/LLN0.RP.EventsIndexed01"; string rcbReference3 = "simpleIOGenericIO/LLN0.BR.Measurements01"; ReportControlBlock rcb1 = con.GetReportControlBlock(rcbReference1); ReportControlBlock rcb2 = con.GetReportControlBlock(rcbReference2); ReportControlBlock rcb3 = con.GetReportControlBlock(rcbReference3); rcb1.GetRCBValues(); // note: the second parameter is not required! rcb1.InstallReportHandler(reportHandler, rcb1); if (rcb1.IsBuffered()) { Console.WriteLine("RCB: " + rcbReference1 + " is buffered"); } rcb1.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb1.SetIntgPd(5000); rcb1.SetRptEna(true); rcb2.GetRCBValues(); if (rcb2.IsBuffered()) { Console.WriteLine("RCB: " + rcbReference2 + " is buffered"); } rcb2.InstallReportHandler(reportHandler, rcb2); rcb2.SetOptFlds(ReportOptions.REASON_FOR_INCLUSION | ReportOptions.SEQ_NUM | ReportOptions.TIME_STAMP | ReportOptions.CONF_REV | ReportOptions.ENTRY_ID | ReportOptions.DATA_REFERENCE | ReportOptions.DATA_SET); rcb2.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb2.SetIntgPd(2000); rcb2.SetRptEna(true); rcb2.SetRCBValues(); rcb3.GetRCBValues(); if (rcb3.IsBuffered()) { Console.WriteLine("RCB: " + rcbReference3 + " is buffered"); } rcb3.InstallReportHandler(reportHandler, rcb2); rcb3.SetOptFlds(ReportOptions.REASON_FOR_INCLUSION | ReportOptions.SEQ_NUM | ReportOptions.TIME_STAMP | ReportOptions.CONF_REV | ReportOptions.ENTRY_ID | ReportOptions.DATA_REFERENCE | ReportOptions.DATA_SET); rcb3.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb3.SetIntgPd(2000); rcb3.SetRptEna(true); rcb3.SetRCBValues(); /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; ReportingExample.running = false; }; /* stop main loop when connection is lost */ con.InstallConnectionClosedHandler(delegate(IedConnection connection) { Console.WriteLine("Connection closed"); ReportingExample.running = false; }); while (running) { Thread.Sleep(10); } /* Dispose the RCBs when you no longer need them */ rcb1.Dispose(); rcb2.Dispose(); rcb3.Dispose(); con.Abort(); con.Dispose(); } catch (IedConnectionException e) { Console.WriteLine("Error: " + e.Message); con.Dispose(); } }
public ResultValueModel WriteCMD(string hostip, Int32 port, bool operate, string cmdaddress) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //create control object ControlObject control = con.CreateControlObject(cmdaddress); ControlModel controlModel = control.GetControlModel(); //result variable dynamic ValueTuple = null; //validate control model type if (controlModel == ControlModel.DIRECT_ENHANCED) { control.SetCommandTerminationHandler(commandTerminationHandler, null); ValueTuple = control.Operate(operate); } else if (controlModel == ControlModel.DIRECT_NORMAL) { control.SetCommandTerminationHandler(commandTerminationHandler, null); ValueTuple = control.Operate(operate); } else if (controlModel == ControlModel.SBO_ENHANCED) { //set handler control.SetCommandTerminationHandler(commandTerminationHandler, null); //set SynchroCheck control.SetSynchroCheck(true); //set InterlockCheck control.SetInterlockCheck(true); //validate cmd select if (control.SelectWithValue(true)) { //operate cmd ValueTuple = control.Operate(operate); } else if (control.SelectWithValue(false)) { //operate cmd ValueTuple = control.Operate(operate); } else if (control.Select()) { //operate cmd ValueTuple = control.Operate(operate); } else { ValueTuple = "SBO cmd not selected!"; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = ValueTuple }; _subSvc.Create(dbinsert); } } else { ValueTuple = "CMD type is not DIRECT_ENHANCED or DIRECT_NORMAL or SBO_ENHANCED kindly Check!"; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = ValueTuple }; _subSvc.Create(dbinsert); } //con close con.Abort(); //result Value_Result listresult = new Value_Result { Address = cmdaddress, Value = ValueTuple, }; ResultValueModel result = new ResultValueModel { data = listresult, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultValueModel result = new ResultValueModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy result con.Dispose(); //result return(result); } }
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); string rcbReference1 = "simpleIOGenericIO/LLN0.RP.EventsRCB01"; string rcbReference2 = "simpleIOGenericIO/LLN0.RP.EventsIndexed01"; string rcbReference3 = "simpleIOGenericIO/LLN0.BR.Measurements01"; ReportControlBlock rcb1 = con.GetReportControlBlock(rcbReference1); ReportControlBlock rcb2 = con.GetReportControlBlock(rcbReference2); ReportControlBlock rcb3 = con.GetReportControlBlock(rcbReference3); rcb1.GetRCBValues(); // note: the second parameter is not required! rcb1.InstallReportHandler(reportHandler, rcb1); if (rcb1.IsBuffered()) Console.WriteLine ("RCB: " + rcbReference1 + " is buffered"); rcb1.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb1.SetIntgPd(5000); rcb1.SetRptEna(true); rcb1.SetRCBValues(); rcb2.GetRCBValues(); if (rcb2.IsBuffered()) Console.WriteLine ("RCB: " + rcbReference2 + " is buffered"); rcb2.InstallReportHandler(reportHandler, rcb2); rcb2.SetOptFlds(ReportOptions.REASON_FOR_INCLUSION | ReportOptions.SEQ_NUM | ReportOptions.TIME_STAMP | ReportOptions.CONF_REV | ReportOptions.ENTRY_ID | ReportOptions.DATA_REFERENCE | ReportOptions.DATA_SET); rcb2.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb2.SetIntgPd(2000); rcb2.SetRptEna(true); rcb2.SetRCBValues(); rcb3.GetRCBValues(); if (rcb3.IsBuffered()) Console.WriteLine ("RCB: " + rcbReference3 + " is buffered"); rcb3.InstallReportHandler(reportHandler, rcb2); rcb3.SetOptFlds(ReportOptions.REASON_FOR_INCLUSION | ReportOptions.SEQ_NUM | ReportOptions.TIME_STAMP | ReportOptions.CONF_REV | ReportOptions.ENTRY_ID | ReportOptions.DATA_REFERENCE | ReportOptions.DATA_SET); rcb3.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb3.SetIntgPd(2000); rcb3.SetRptEna(true); rcb3.SetRCBValues(); /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; ReportingExample.running = false; }; while (running) { Thread.Sleep(10); } con.Abort (); } catch (IedConnectionException e) { Console.WriteLine (e.Message); } }
public ResultDatasetModel ReadRCB(string hostip, Int32 port, string dataaddress) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //read data set // create a new data set List <string> dataSetElements = new List <string>(); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn1.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn2.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn3.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn4.mag.f[MX]"); // permanent (domain specific) data set //string dataSetReference = "simpleIOGenericIO/LLN0.ds1"; // temporary (association specific) data set string dataSetReference = "@ss"; // Note: this function will throw an exception when a data set with the same name already exists con.CreateDataSet(dataSetReference, dataSetElements); // reconfigure existing RCB with new data set string rcbReference = "simpleIOGenericIO/LLN0.RP.EventsRCB01"; ReportControlBlock rcb = con.GetReportControlBlock(rcbReference); rcb.GetRCBValues(); // note: the second parameter is not required! rcb.InstallReportHandler(reportHandler, rcb); string rcbDataSetReference = dataSetReference.Replace('.', '$'); rcb.SetDataSetReference(rcbDataSetReference); rcb.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY); rcb.SetIntgPd(5000); rcb.SetRptEna(true); rcb.SetRCBValues(); // Console.WriteLine(mmsresult.GetRCBValues()); List <Dataset_Result> valuelist = new List <Dataset_Result>(); data_extract dataExtract = new data_extract(); //con close con.Abort(); ResultDatasetModel result = new ResultDatasetModel { data = valuelist, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultDatasetModel result = new ResultDatasetModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy result con.Dispose(); //result return(result); } }
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); List<string> serverDirectory = con.GetServerDirectory(false); foreach (string entry in serverDirectory) { Console.WriteLine("LD: " + entry); } // create a new data set List<string> dataSetElements = new List<string>(); string dataSetName = "simpleIOGenericIO/UNKNOWN.ds1"; //string dataSetName = "simpleIOGenericIO/LLN0.ds1"; dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn1.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn2.mag.f[MX]"); con.CreateDataSet(dataSetName, dataSetElements); // get the directory of the data set List<string> dataSetDirectory = con.GetDataSetDirectory(dataSetName); foreach (string entry in dataSetDirectory) { Console.WriteLine("DS element: " + entry); } // read the values of the newly created data set DataSet dataSet = con.ReadDataSetValues(dataSetName, null); MmsValue dataSetValues = dataSet.GetValues(); Console.WriteLine ("Data set contains " + dataSetValues.Size() + " elements"); foreach (MmsValue value in dataSetValues) { Console.WriteLine(" DS value: " + value + " type: " + value.GetType()); } // delete the data set con.DeleteDataSet(dataSetName); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message + " reason: " + e.GetIedClientError().ToString()); } }
public static void Main(string[] args) { IedConnection con = new IedConnection (); string hostname; if (args.Length > 0) hostname = args[0]; else hostname = "localhost"; try { Console.WriteLine("Connect to " + hostname + " ..."); con.Connect(hostname, 102); Console.WriteLine("Connected."); MmsConnection mmsCon = con.GetMmsConnection(); MmsServerIdentity identity = mmsCon.GetServerIdentity(); Console.WriteLine("Vendor: " + identity.vendorName); Console.WriteLine("Model: " + identity.modelName); Console.WriteLine("Revision: " + identity.revision); List<string> serverDirectory = con.GetServerDirectory(false); foreach (string ldName in serverDirectory) { Console.WriteLine("LD: " + ldName); List<string> lnNames = con.GetLogicalDeviceDirectory(ldName); foreach (string lnName in lnNames) { Console.WriteLine(" LN: " + lnName); string logicalNodeReference = ldName + "/" + lnName; // discover data objects List<string> dataObjects = con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_DATA_OBJECT); foreach (string dataObject in dataObjects) { Console.WriteLine(" DO: " + dataObject); List<string> dataDirectory = con.GetDataDirectoryFC(logicalNodeReference + "." + dataObject); foreach (string dataDirectoryElement in dataDirectory) { string daReference = logicalNodeReference + "." + dataObject + "." + ObjectReference.getElementName(dataDirectoryElement); // get the type specification of a variable MmsVariableSpecification specification = con.GetVariableSpecification(daReference, ObjectReference.getFC(dataDirectoryElement)); Console.WriteLine (" DA/SDO: [" + ObjectReference.getFC(dataDirectoryElement) + "] " + ObjectReference.getElementName(dataDirectoryElement) + " : " + specification.GetType() + "(" + specification.Size() + ")"); if (specification.GetType() == MmsType.MMS_STRUCTURE) { foreach (MmsVariableSpecification elementSpec in specification) { Console.WriteLine(" " + elementSpec.GetName() + " : " + elementSpec.GetType()); } } } } // discover data sets List<string> dataSets = con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_DATA_SET); foreach (string dataSet in dataSets) { Console.WriteLine(" Dataset: " + dataSet); } // discover unbuffered report control blocks List<string> urcbs = con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_URCB); foreach (string urcb in urcbs) { Console.WriteLine(" URCB: " + urcb); } // discover buffered report control blocks List<string> brcbs = con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_BRCB); foreach (string brcb in brcbs) { Console.WriteLine(" BRCB: " + brcb); } } } con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } }
public ResultSingleModel ReadSingleGroup(string hostip, Int32 port, string FC, string vargroup) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //exctract fc data_extract dataExtract = new data_extract(); var FunctionCode = dataExtract.ExtractFC(FC); //read group MmsValue mmsresult = con.ReadValue(vargroup, FunctionCode); //con close con.Abort(); //result list dynamic ValueTuple = mmsresult; Read_Result listresult = null; Int16 Quality; DateTimeOffset Timestamp; List <dynamic> valueArray = new List <dynamic>(); if (mmsresult.GetType() == MmsType.MMS_STRUCTURE) { if (mmsresult.Size() == 4) { ValueTuple = dataExtract.ExtractValue(mmsresult.GetElement(0)); Quality = dataExtract.ExtractValue(mmsresult.GetElement(2)); Timestamp = dataExtract.ExtractValue(mmsresult.GetElement(3)); } else { ValueTuple = dataExtract.ExtractValue(mmsresult.GetElement(0)); Quality = dataExtract.ExtractValue(mmsresult.GetElement(1)); Timestamp = dataExtract.ExtractValue(mmsresult.GetElement(2)); } listresult = new Read_Result { Address = vargroup, Value = ValueTuple, Quality = Quality, Timestamp = Timestamp }; } ResultSingleModel result = new ResultSingleModel() { data = listresult, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultSingleModel result = new ResultSingleModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy instance con.Dispose(); //error result return(result); } }
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); List <string> serverDirectory = con.GetServerDirectory(false); foreach (string entry in serverDirectory) { Console.WriteLine("LD: " + entry); } // create a new data set List <string> dataSetElements = new List <string>(); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn1.mag.f[MX]"); dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn2.mag.f[MX]"); con.CreateDataSet("simpleIOGenericIO/LLN0.ds1", dataSetElements); // get the directory of the data set List <string> dataSetDirectory = con.GetDataSetDirectory("simpleIOGenericIO/LLN0.ds1"); foreach (string entry in dataSetDirectory) { Console.WriteLine("DS element: " + entry); } // read the values of the newly created data set DataSet dataSet = con.ReadDataSetValues("simpleIOGenericIO/LLN0.ds1", null); MmsValue dataSetValues = dataSet.GetValues(); Console.WriteLine("Data set contains " + dataSetValues.Size() + " elements"); foreach (MmsValue value in dataSetValues) { Console.WriteLine(" DS value: " + value + " type: " + value.GetType()); } // delete the data set con.DeleteDataSet("simpleIOGenericIO/LLN0.ds1"); con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message + " reason: " + e.GetIedClientError().ToString()); } }
public static void Main(string[] args) { IedConnection con = new IedConnection(); string hostname; if (args.Length > 0) { hostname = args[0]; } else { hostname = "localhost"; } try { Console.WriteLine("Connect to " + hostname + " ..."); con.Connect(hostname, 102); Console.WriteLine("Connected."); List <string> serverDirectory = con.GetServerDirectory(false); foreach (string ldName in serverDirectory) { Console.WriteLine("LD: " + ldName); List <string> lnNames = con.GetLogicalDeviceDirectory(ldName); foreach (string lnName in lnNames) { Console.WriteLine(" LN: " + lnName); string logicalNodeReference = ldName + "/" + lnName; // discover data objects List <string> dataObjects = con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_DATA_OBJECT); foreach (string dataObject in dataObjects) { Console.WriteLine(" DO: " + dataObject); } // discover data sets List <string> dataSets = con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_DATA_SET); foreach (string dataSet in dataSets) { Console.WriteLine(" Dataset: " + dataSet); } // discover unbuffered report control blocks List <string> urcbs = con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_URCB); foreach (string urcb in urcbs) { Console.WriteLine(" URCB: " + urcb); } // discover buffered report control blocks List <string> brcbs = con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_BRCB); foreach (string brcb in brcbs) { Console.WriteLine(" BRCB: " + brcb); } } } con.Abort(); } catch (IedConnectionException e) { Console.WriteLine(e.Message); } }
public ResultDatasetModel ReadMultipleVariableValues(string hostip, Int32 port, string[] valueaddress) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //dataset elements List <string> dataSetElements = new List <string>(); foreach (string address in valueaddress) { dataSetElements.Add(address); } string LDname = dataSetElements[0].Split("/")[0]; string LNname = dataSetElements[0].Split("/")[1].Split(".")[0]; string DSname = "ReadValues"; string dataSetName = LDname + "/" + LNname + "." + DSname; //create dataset con.CreateDataSet(dataSetName, dataSetElements); //read data set DataSet mmsresult = con.ReadDataSetValues(dataSetName, null); List <string> DataSetDirectory = con.GetDataSetDirectory(dataSetName); if (DataSetDirectory != null) { //delete dataset con.DeleteDataSet(dataSetName); } //con close con.Abort(); //get data set values List <Dataset_Result> valuelist = new List <Dataset_Result>(); data_extract dataExtract = new data_extract(); int i = 0; foreach (var value in mmsresult.GetValues()) { var ValueTuple = dataExtract.ExtractValue(value); valuelist.Add(new Dataset_Result { Address = DataSetDirectory[i], Value = ValueTuple }); i += 1; } ResultDatasetModel result = new ResultDatasetModel { data = valuelist, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultDatasetModel result = new ResultDatasetModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy result con.Dispose(); //result return(result); } }
public ResultValueModel ReadVariableValue(string hostip, Int32 port, string datatype, string FC, string valueaddress) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //extract fc data_extract dataExtract = new data_extract(); var FunctionCode = dataExtract.ExtractFC(FC); dynamic mmsresult = null; //validate datatype if (datatype == "BOOLEAN") { mmsresult = con.ReadBooleanValue(valueaddress, FunctionCode); } else if (datatype == "FLOAT") { mmsresult = con.ReadFloatValue(valueaddress, FunctionCode); } else if (datatype == "INT") { mmsresult = con.ReadIntegerValue(valueaddress, FunctionCode); } else if (datatype == "STRING") { mmsresult = con.ReadStringValue(valueaddress, FunctionCode); } else if (datatype == "BITSTRING") { mmsresult = con.ReadBitStringValue(valueaddress, FunctionCode); } //con close con.Abort(); //extract value dynamic ValueTuple = null; ValueTuple = dataExtract.ExtractValue(mmsresult); //result Value_Result listresult = new Value_Result { Address = valueaddress, Value = ValueTuple, }; ResultValueModel result = new ResultValueModel { data = listresult, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultValueModel result = new ResultValueModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy result con.Dispose(); //result return(result); } }
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); }
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 ResultMultipleModel ReadMultipleGroups(string hostip, Int32 port, string logicaldevicename, string[] vargroup) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //list variable group var variable_group = new List <string>(); foreach (string address in vargroup) { variable_group.Add(address); } //mms connecton MmsConnection mmsConnection = con.GetMmsConnection(); //read data MmsValue mmsresult = mmsConnection.ReadMultipleVariables(logicaldevicename, variable_group); //connection close con.Abort(); //result list data_extract dataExtract = new data_extract(); dynamic ValueTuple = null; Int16 Quality; DateTimeOffset Timestamp; Read_Result listresult = null; List <Read_Result> Variableset = new List <Read_Result>(); int i = 0; foreach (MmsValue address in mmsresult) { if (address.Size() == 4) { ValueTuple = dataExtract.ExtractValue(address.GetElement(0)); Quality = dataExtract.ExtractValue(address.GetElement(2)); Timestamp = dataExtract.ExtractValue(address.GetElement(3)); } else { ValueTuple = dataExtract.ExtractValue(address.GetElement(0)); Quality = dataExtract.ExtractValue(address.GetElement(1)); Timestamp = dataExtract.ExtractValue(address.GetElement(2)); } listresult = new Read_Result { Address = variable_group[i], Value = ValueTuple, Quality = Quality, Timestamp = Timestamp }; Variableset.Add(listresult); i = i + 1; } ResultMultipleModel result = new ResultMultipleModel() { data = Variableset, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultMultipleModel result = new ResultMultipleModel() { data = null, error = true, errormessage = e.Message.ToString() }; //insert logs into db Submission dbinsert = new Submission { CreatedAt = DateTime.Now, Content = e.Message.ToString() }; _subSvc.Create(dbinsert); //destroy instance con.Dispose(); //error result return(result); } }