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

63 lines
2.1 KiB
C#

using System;
using System.Data;
using System.Text;
using System.Threading;
using ln.application;
using ln.ethercat.controller;
using ln.ethercat.controller.drives;
using ln.ethercat.controller.remote;
using ln.logging;
using ln.type;
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(args[0]);
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);
}
};
ethercatService.ECMaster.Controller.Add(new CLGalaTechBohrautomat());
ethercatService.Start();
if (SerialRemotePort != null)
{
StupidSerialRemote stupidSerialRemote = new StupidSerialRemote(ethercatService.ECMaster.Controller, SerialRemotePort);
stupidSerialRemote.Start();
}
}
}
}