61 lines
1.3 KiB
C#
61 lines
1.3 KiB
C#
|
|
|
|
using System.Threading;
|
|
using ln.ethercat.service.api.v1;
|
|
using ln.http;
|
|
using ln.http.router;
|
|
using ln.logging;
|
|
using ln.type;
|
|
|
|
namespace ln.ethercat.service
|
|
{
|
|
public class EthercatService
|
|
{
|
|
|
|
public ECMaster ECMaster { get; }
|
|
|
|
|
|
HTTPServer httpServer;
|
|
LoggingRouter httpLoggingRouter;
|
|
SimpleRouter httpRouter;
|
|
|
|
EthercatApiController apiController;
|
|
|
|
|
|
public EthercatService(string interfaceName)
|
|
{
|
|
ECMaster = new ECMaster(interfaceName);
|
|
|
|
Initialize();
|
|
}
|
|
|
|
void Initialize()
|
|
{
|
|
httpRouter = new SimpleRouter();
|
|
httpLoggingRouter = new LoggingRouter(httpRouter);
|
|
|
|
apiController = new EthercatApiController(ECMaster);
|
|
httpRouter.AddSimpleRoute("/api/v1/*", apiController);
|
|
|
|
httpServer = new HTTPServer(httpLoggingRouter);
|
|
httpServer.AddEndpoint(new Endpoint(IPv6.ANY, 7676));
|
|
|
|
}
|
|
|
|
|
|
public void Start()
|
|
{
|
|
httpServer.Start();
|
|
|
|
ECMaster.Start();
|
|
|
|
while (ECMaster.MasterState != ECMasterState.RUNNING)
|
|
Thread.Sleep(100);
|
|
|
|
Logging.Log(LogLevel.INFO,"ECMaster is ready (ExpectedWorkCounter={0})", ECMaster.ExpectedWorkCounter);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |