ln.ethercat/ln.ethercat.service/Program.cs

64 lines
2.4 KiB
C#

using System.Text;
using ln.application;
using ln.ethercat.controller.remote;
using ln.logging;
namespace ln.ethercat.service
{
class Program
{
[StaticArgument(LongOption = "serial-remote")]
static string SerialRemotePort { get; set; }
static void Main(string[] args)
{
Logging.Log(LogLevel.INFO, ".NET EtherCAT service host");
StringBuilder versionString = new StringBuilder(1024);
ECMBind.ecmbind_version(versionString);
Logging.Log(LogLevel.INFO, "ECMBind version: {0}", versionString.ToString());
EthercatService ethercatService = new EthercatService();
ArgumentContainer argumentContainer = new ArgumentContainer();
argumentContainer.AddStaticOptions<Program>();
argumentContainer.AddOptions(ethercatService);
argumentContainer.Parse(ref args);
ethercatService.Initialize();
ethercatService.ECMaster.OnStateChange += (ECMaster ECMaster, ECSlaveState newState) => {
if (newState == ECSlaveState.SAFE_OP)
{
if (ECMaster.GetSDOValue(1, 0x2012, 32, out SDOValue svEnableDrives))
{
svEnableDrives.SetValue((byte)0x00);
}
} else if (newState == ECSlaveState.PRE_OP)
{
ECMaster.RequestPDOMapping(1, 0x2012, 31, true);
ECMaster.RequestPDOMapping(1, 0x2012, 32, true);
ECMaster.RequestPDOMapping(2, 0x2008, 1, false);
ECMaster.RequestPDOMapping(2, 0x2008, 2, false);
ECMaster.RequestPDOMapping(2, 0x2008, 3, false);
}
};
//ethercatService.ECMaster.Controller.Add(new CLGalaTechBohrautomat());
ethercatService.ECMaster.Controller.Add(new GalaTechControllerLogic());
ethercatService.Start();
if (SerialRemotePort != null)
{
// StupidSerialRemote stupidSerialRemote = new StupidSerialRemote(ethercatService.ECMaster.Controller, SerialRemotePort);
// stupidSerialRemote.Start();
NewSerialRemote serialRemote =
new NewSerialRemote(ethercatService.ECMaster.Controller, SerialRemotePort);
serialRemote.Start();
}
}
}
}