public void SetControlListener(string ObjRef) { DataObject ControlPoint = (DataObject)iedModel.GetModelNodeByShortObjectReference(ObjRef); iedServer.SetCheckHandler(ControlPoint, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test, bool interlockCheck) { Console.WriteLine("SYSLOG: Received binary control command:"); Console.WriteLine(" ctlNum: " + action.GetCtlNum()); Console.WriteLine(" execution-time: " + action.GetControlTimeAsDataTimeOffset().ToString()); return(CheckHandlerResult.ACCEPTED); }, null); iedServer.SetControlHandler(ControlPoint, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean(); if (val) { Console.WriteLine("CTRL: Execute binary control command: ON"); } else { Console.WriteLine("CTRL: Execute binary control command: OFF"); } return(ControlHandlerResult.OK); }, null); }
public async Task SetControlListener(string ObjRef) { _logger.LogInformation($"SYSLOG: Set Control Listener: {ObjRef}"); DataObject ControlPoint = (DataObject)iedModel.GetModelNodeByShortObjectReference(ObjRef); DataObjectMapping tmp = new DataObjectMapping(ControlPoint, ObjRef); DoMapping.Add(tmp); iedServer.SetCheckHandler(ControlPoint, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test, bool interlockCheck) { _logger.LogInformation($"SYSLOG: Received binary control command:" + $"\n\tctlNum: {action.GetCtlNum()}" + $"\n\texecution-time: {action.GetControlTimeAsDataTimeOffset().ToString()}"); return(CheckHandlerResult.ACCEPTED); }, null); iedServer.SetControlHandler(ControlPoint, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean(); string result = (from v in DoMapping where v.dataObject == ControlPoint select v.tagName).FirstOrDefault(); result = result.Split('.').Last(); if (val) { AddTagout(result); _logger.LogInformation("CTRL: Execute binary control command: ON"); } else { RemoveTagout(result); _logger.LogInformation("CTRL: Execute binary control command: OFF"); } return(ControlHandlerResult.OK); }, null); }
public static void Main(string[] args) { bool running = true; /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg"); if (iedModel == null) { Console.WriteLine("No valid data model found!"); return; } iedModel.SetIedName("TestIED"); DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); IedServerConfig config = new IedServerConfig(); config.ReportBufferSize = 100000; IedServer iedServer = new IedServer(iedModel, config); iedServer.SetCheckHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test, bool interlockCheck) { Console.WriteLine("Received binary control command:"); Console.WriteLine(" ctlNum: " + action.GetCtlNum()); Console.WriteLine(" execution-time: " + action.GetControlTimeAsDataTimeOffset().ToString()); return(CheckHandlerResult.ACCEPTED); }, null); iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean(); if (val) { Console.WriteLine("execute binary control command: on"); } else { Console.WriteLine("execute binary control command: off"); } return(ControlHandlerResult.OK); }, null); DataObject spcso2 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO2"); iedServer.SetSelectStateChangedHandler(spcso2, delegate(ControlAction action, object parameter, bool isSelected, SelectStateChangedReason reason) { DataObject cObj = action.GetControlObject(); Console.WriteLine("Control object " + cObj.GetObjectReference() + (isSelected ? " selected" : " unselected") + " reason: " + reason.ToString()); }, null); iedServer.Start(102); if (iedServer.IsRunning()) { Console.WriteLine("Server started"); GC.Collect(); DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f"); DataAttribute ggio1AnIn1T = (DataAttribute)ggio1AnIn1.GetChild("t"); float floatVal = 1.0f; while (running) { floatVal += 1f; iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now)); iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal); Thread.Sleep(100); } iedServer.Stop(); Console.WriteLine("Server stopped"); } else { Console.WriteLine("Failed to start server"); } iedServer.Destroy(); }
public static void InitHandlers(IedServer iedServer, IedModel iedModel) { foreach (var itemDataObject in UpdateDataObj.UpdateListDestination) { var temp = (DataObject)iedModel.GetModelNodeByShortObjectReference(itemDataObject.NameDataObj); if (itemDataObject.BaseClass.GetType() == typeof(SpcClass)) { object tempParam = ((SpcClass)itemDataObject.BaseClass).ctlModel; iedServer.SetCheckHandler(temp, (controlObject, parameter, ctlVal, test, interlockCheck, connection) => { //controlObject //iedServer. //if(interlockCheck) var result = CheckHandlerResult.ACCEPTED; return(result); }, tempParam); iedServer.SetWaitForExecutionHandler(temp, (controlObject, parameter, ctlVal, test, synchroCheck) => { //ControlHandlerResult.WAITING var result = ControlHandlerResult.OK; return(result); }, tempParam); iedServer.SetControlHandler(temp, (controlObject, parameter, ctlVal, test) => { if (ctlVal.GetType() != MmsType.MMS_BOOLEAN) { return(ControlHandlerResult.FAILED); } if (!test) { var tempValue = new { Key = "stVal", Value = ctlVal.GetBoolean() }; itemDataObject.WriteValue(tempValue); } return(ControlHandlerResult.OK); }, tempParam); } else if (itemDataObject.BaseClass.GetType() == typeof(IncClass)) { iedServer.SetWaitForExecutionHandler(temp, (controlObject, parameter, val, test, check) => test ? ControlHandlerResult.FAILED : ControlHandlerResult.OK, null); iedServer.SetControlHandler(temp, (controlObject, parameter, ctlVal, test) => { if (ctlVal.GetType() != MmsType.MMS_INTEGER) { return(ControlHandlerResult.FAILED); } itemDataObject.WriteValue(ctlVal.ToInt32()); return(ControlHandlerResult.OK); }, null); } } }