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 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); } }