|
|
|
@ -13,6 +13,7 @@ using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
using Z.EntityFramework.Plus;
|
|
|
|
using Z.EntityFramework.Plus;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
|
|
@ -861,15 +862,19 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取Plc的值
|
|
|
|
/// 获取Plc的值 及报警信息同步
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private void BasePlcPointUpdateLogic()
|
|
|
|
private void BasePlcPointUpdateLogic()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
|
|
|
stopwatch.Start(); // 开始计时
|
|
|
|
|
|
|
|
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
List<Plc.S7.Plc> plcs = StaticData.PlcDic.Values.ToList();
|
|
|
|
List<Plc.S7.Plc> plcs = StaticData.PlcDic.Values.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in StaticData.BasePlcpointList.Where(t => !string.IsNullOrEmpty(t.plcpointAddress)))
|
|
|
|
foreach (var item in StaticData.BasePlcpointList.Where(t => !string.IsNullOrEmpty(t.plcpointAddress)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(item.plcpointAddress))
|
|
|
|
if (!string.IsNullOrEmpty(item.plcpointAddress))
|
|
|
|
@ -879,7 +884,24 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
if (item.plcpointNo.Contains("RFID"))
|
|
|
|
if (item.plcpointNo.Contains("RFID"))
|
|
|
|
item.definefield1 = plcs.Where(t => t.IP == item.definefield3).First().ReadRFID(item.plcpointAddress)?.ToString();
|
|
|
|
item.definefield1 = plcs.Where(t => t.IP == item.definefield3).First().ReadRFID(item.plcpointAddress)?.ToString();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
item.definefield1 = plcs.Where(t => t.IP == item.definefield1).First().Read(item.plcpointAddress)?.ToString();
|
|
|
|
{
|
|
|
|
|
|
|
|
item.definefield1 = plcs.Where(t => t.IP == item.definefield3).First().Read(item.plcpointAddress)?.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 提升机报警点位,需要添加报警记录
|
|
|
|
|
|
|
|
if (item.plcpointNo.Contains("提升机报警采集专用点位"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(item.definefield1 == "True" || item.definefield1 == "1")
|
|
|
|
|
|
|
|
{ //添加报警
|
|
|
|
|
|
|
|
SystemData.InsertWaringLog(dbContext, item.plcpointName, item.plcpointName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//如有报警需消除
|
|
|
|
|
|
|
|
SystemData.DeleteWaringLog(dbContext, item.plcpointName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -887,8 +909,12 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dbContext.UpdateRange(StaticData.BasePlcpointList.Where(t => !string.IsNullOrEmpty(t.plcpointAddress)));
|
|
|
|
dbContext.UpdateRange(StaticData.BasePlcpointList.Where(t => !string.IsNullOrEmpty(t.plcpointAddress)));
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stopwatch.Stop(); // 停止计时
|
|
|
|
|
|
|
|
// Console.WriteLine($"BasePlcPointUpdateLogic 方法执行时间: {stopwatch.ElapsedMilliseconds} 毫秒");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|