|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
using HslCommunication.Profinet.Siemens;
|
|
|
|
|
using NewLife.Extensions.Hosting.AgentService;
|
|
|
|
|
using NewLife.Log;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using SynPlc;
|
|
|
|
@ -13,13 +12,14 @@ if (!HslCommunication.Authorization.SetAuthorizationCode("12a99167-05ff-4c89-936
|
|
|
|
|
|
|
|
|
|
XTrace.UseConsole();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IHost host = Host.CreateDefaultBuilder(args)
|
|
|
|
|
.ConfigureServices((context,services) =>
|
|
|
|
|
{
|
|
|
|
|
string sqlConect = context.Configuration.GetConnectionString("Sql");
|
|
|
|
|
string Plc = context.Configuration.GetConnectionString("Plc");
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<SiemensS7Net>(_ => new SiemensS7Net(SiemensPLCS.S300)
|
|
|
|
|
services.AddSingleton(new SiemensS7Net(SiemensPLCS.S300)
|
|
|
|
|
{
|
|
|
|
|
IpAddress = Plc,
|
|
|
|
|
Port = 102
|
|
|
|
@ -31,7 +31,7 @@ IHost host = Host.CreateDefaultBuilder(args)
|
|
|
|
|
//Scoped用SqlSugarClient
|
|
|
|
|
SqlSugarClient sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
|
|
|
|
{
|
|
|
|
|
DbType = SqlSugar.DbType.SqlServer,
|
|
|
|
|
DbType = DbType.SqlServer,
|
|
|
|
|
ConnectionString = sqlConect,
|
|
|
|
|
IsAutoCloseConnection = true,
|
|
|
|
|
},
|
|
|
|
@ -57,12 +57,6 @@ IHost host = Host.CreateDefaultBuilder(args)
|
|
|
|
|
services.AddHostedService<Worker>();
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
.UseAgentService(options =>
|
|
|
|
|
{
|
|
|
|
|
options.ServiceName = "TestWorker";
|
|
|
|
|
options.DisplayName = "Worker服务测试";
|
|
|
|
|
options.Description = "Worker服务的测试应用";
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
await host.RunAsync();
|