You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
6.9 KiB
C#
148 lines
6.9 KiB
C#
using Khd.Core.Domain.Models;
|
|
using Khd.Core.EntityFramework;
|
|
using Khd.Core.Library;
|
|
using Khd.Core.Plc.S7;
|
|
using Khd.Core.Wcs.Global;
|
|
using Masuit.Tools.Logging;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Z.EntityFramework.Plus;
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
{
|
|
/// <summary>
|
|
/// 四楼接驳位
|
|
/// </summary>
|
|
public class FourthFloorPoint
|
|
{
|
|
private readonly LoggerUtils _logger = new LoggerUtils();
|
|
private readonly int Floor;
|
|
private readonly IHost _host;
|
|
private readonly BasePlcpoint LineRFID;
|
|
private readonly BasePlcpoint LineSignal;
|
|
public FourthFloorPoint(int floor, Plc.S7.Plc plc, IHost host)
|
|
{
|
|
Floor = floor;
|
|
this._host = host;
|
|
this.LineRFID = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID004");
|
|
this.LineSignal = StaticData.BasePlcpointList.First(t => t.plcpointNo.Contains("linesignal04"));
|
|
}
|
|
|
|
public void StartPoint()
|
|
{
|
|
Thread MonitorInLocatorPointThread = new Thread(MonitorInLocatorPoint);
|
|
MonitorInLocatorPointThread.IsBackground = true;
|
|
MonitorInLocatorPointThread.Name = "FourthFloorPoint";
|
|
MonitorInLocatorPointThread.Start();
|
|
}
|
|
|
|
private void MonitorInLocatorPoint()
|
|
{
|
|
List<int> ITypes = new List<int> { 1, 3, 5, 7 };
|
|
using var scope = _host.Services.CreateScope();
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
//入库任务
|
|
var rfid = StaticData.PlcDic[0].ReadRFID(LineRFID.plcpointAddress);
|
|
var isSignal = StaticData.PlcDic[0].Read(LineSignal.plcpointAddress);
|
|
if (rfid != null && isSignal != null)
|
|
{
|
|
|
|
if (Convert.ToInt32(isSignal) == 1)//托盘到位
|
|
{
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1);
|
|
var wcsTask = dbContext.WcsTask.FirstOrDefault(t => t.containerNo == rfid && t.nextPointId == baseEquip.objid);
|
|
if (wcsTask != null)//如果不是null
|
|
{
|
|
int? floor = 0;
|
|
var wmsProductOutstock = dbContext.WmsProductOutstock.FirstOrDefault(t => t.saleOrderId == wcsTask.orderId);
|
|
if (wmsProductOutstock != null)
|
|
{
|
|
var endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == wmsProductOutstock.endStationCode);
|
|
if (endEquip != null)
|
|
{
|
|
floor = endEquip.floorNo;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var wmsRawOutstock = dbContext.WmsRawOutstock.FirstOrDefault(t => t.rawOutstockId == wcsTask.orderId);
|
|
if (wmsRawOutstock != null)
|
|
{
|
|
var endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == wmsRawOutstock.endStationCode);
|
|
if (endEquip != null)
|
|
{
|
|
floor = endEquip.floorNo;
|
|
}
|
|
}
|
|
}
|
|
if (floor == 0)
|
|
{
|
|
Console.WriteLine($"{DateTime.Now}:4楼接驳位未找到目的地楼层");
|
|
_logger.Info("4楼接驳位未找到目的地楼层");
|
|
Thread.Sleep(1000);
|
|
continue;
|
|
}
|
|
BaseEquip nextEquip = StaticData.BaseEquip.First(t => t.equipType == 2);//提升机
|
|
wcsTask.nextPointId = nextEquip.objid;
|
|
wcsTask.nextPointNo = nextEquip.equipNo;
|
|
wcsTask.currPointId = baseEquip.objid;
|
|
wcsTask.currPointNo = baseEquip.equipNo;
|
|
wcsTask.fromFloorNo = 4;
|
|
wcsTask.taskType = 6;//成品出库
|
|
wcsTask.floorNo = floor;//出库到一楼
|
|
wcsTask.taskStatus = 0;
|
|
wcsTask.updateTime = DateTime.Now;
|
|
dbContext.Update(wcsTask);
|
|
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid)
|
|
.Update(t => new WcsTaskLog
|
|
{
|
|
nextPointId = nextEquip.objid,
|
|
nextPointNo = nextEquip.equipNo,
|
|
currPointId = baseEquip.objid,
|
|
currPointNo = baseEquip.equipNo,
|
|
fromFloorNo = 4,
|
|
floorNo = floor,
|
|
taskStatus = 0,
|
|
updateTime = DateTime.Now,
|
|
});
|
|
dbContext.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex is PlcException)
|
|
{
|
|
try
|
|
{
|
|
foreach (var item in StaticData.PlcDic)
|
|
{
|
|
if (item.Value.IP == ex.Message)
|
|
{
|
|
StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
|
|
StaticData.PlcDic[item.Key].Open();
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
_logger.Error(ex.Message + "\n" + ex.StackTrace);
|
|
}
|
|
finally
|
|
{
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|