using System; using System.IO; using ln.ethercat.controller; using ln.json; using ln.json.mapping; namespace ln.ethercat.service { public class CLGalaTechBohrautomat : ControllerLogic { public MyParameters Parameters { get; set; } SDOValue svRelais; SDOValue svEnable; public CLGalaTechBohrautomat() { Parameters = new MyParameters(); if (File.Exists("mafcl.json")) { JSONValue configValue = JSONParser.ParseFile("mafcl.json"); JSONMapper.DefaultMapper.Apply(configValue as JSONObject, Parameters); } } public void Save() { if (JSONMapper.DefaultMapper.Serialize(Parameters, out JSONValue configObject)) { using (StreamWriter sw = new StreamWriter("mafcl.json")) { sw.Write(configObject.ToString()); sw.Flush(); } } } public override void Initialize(Controller controller) { if (!( controller.ECMaster.GetSDOValue(1, 0x2012, 31, out svRelais) && controller.ECMaster.GetSDOValue(1, 0x2012, 32, out svEnable) )) throw new Exception("could not retrieve needed SDOValues"); } public override void Cycle(Controller controller) { switch (controller.ControllerState) { case ControllerStates.FAULT: svEnable.SetValue((byte)0x00); break; case ControllerStates.NOTREADY: svEnable.SetValue((byte)0x01); break; } if (controller.ControllerState == ControllerStates.OPERATIONAL) { svRelais.SetValue((byte)0x01); } else { svRelais.SetValue((byte)0x00); } } public class MyParameters { } } }