diff --git a/DOAN.ServiceCore/BackgroundService.cs b/DOAN.ServiceCore/BackgroundService.cs index 8ec115b..f55a4d3 100644 --- a/DOAN.ServiceCore/BackgroundService.cs +++ b/DOAN.ServiceCore/BackgroundService.cs @@ -48,39 +48,43 @@ namespace DOAN.ServiceCore Storagelocation storagelocation = await DbScoped.SugarScope.CopyNew() .Queryable().Where(it => it.Id == index).FirstAsync(); + string[] address = storagelocation.PlcAddress2.Split(","); + for (int i = 0; i < address.Length; i++) { + bool result = PLCTool.ReadBit(address[i]); + // 写补料日志 + Inventorylog inventorylog = new Inventorylog(); + inventorylog.Id = SnowFlakeSingle.Instance.NextId().ToString(); + inventorylog.RackCode = storagelocation.RackCode; - bool result = PLCTool.ReadBit(storagelocation.PlcAddress2); - // 写补料日志 - Inventorylog inventorylog = new Inventorylog(); - inventorylog.Id = SnowFlakeSingle.Instance.NextId().ToString(); - inventorylog.RackCode = storagelocation.RackCode; - - if (result) - { - //缺料 - storagelocation.PackageNum = 2; - inventorylog.Operation = 1; - inventorylog.PackageNum = 2; - inventorylog.CreatedBy = "PLC"; - inventorylog.CreatedTime = DateTime.Now.ToLocalTime(); - await DbScoped.SugarScope.CopyNew().Updateable(storagelocation).ExecuteCommandAsync(); - } - else - { - if (storagelocation.PackageNum<=2) + if (result) { - //补料成功 - storagelocation.PackageNum = 4; - inventorylog.Operation = 2; - inventorylog.PackageNum = 4; + //缺料 + storagelocation.PackageNum = 2; + inventorylog.Operation = 1; + inventorylog.PackageNum = 2; inventorylog.CreatedBy = "PLC"; inventorylog.CreatedTime = DateTime.Now.ToLocalTime(); await DbScoped.SugarScope.CopyNew().Updateable(storagelocation).ExecuteCommandAsync(); } - + else + { + if (storagelocation.PackageNum <= 2) + { + //补料成功 + storagelocation.PackageNum = 4; + inventorylog.Operation = 2; + inventorylog.PackageNum = 4; + inventorylog.CreatedBy = "PLC"; + inventorylog.CreatedTime = DateTime.Now.ToLocalTime(); + await DbScoped.SugarScope.CopyNew().Updateable(storagelocation).ExecuteCommandAsync(); + } + + } + + + } - - + await Task.Delay(5000, stoppingToken);