|
|
|
|
|
using Khd.Core.Domain.Models;
|
|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
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 SecondFloorLine
|
|
|
|
|
|
{
|
|
|
|
|
|
List<BasePlcpoint> ScanPoint { get; set; }//点位信息
|
|
|
|
|
|
private readonly IHost _host;
|
|
|
|
|
|
private readonly Plc.S7.Plc _plc;
|
|
|
|
|
|
private readonly BasePlcpoint LineRFID;
|
|
|
|
|
|
private readonly BasePlcpoint LineWcsrun;
|
|
|
|
|
|
private readonly BasePlcpoint LineSignal;
|
|
|
|
|
|
private readonly BasePlcpoint LineIsPallet;
|
|
|
|
|
|
private readonly BasePlcpoint LineSerialNO;
|
|
|
|
|
|
int FloorNo { get; set; }
|
|
|
|
|
|
string EquipNo = "";
|
|
|
|
|
|
int EquipID = 2;
|
|
|
|
|
|
public SecondFloorLine(IHost host, Plc.S7.Plc plc, int floor, string equipNo)
|
|
|
|
|
|
{
|
|
|
|
|
|
this._host = host;
|
|
|
|
|
|
this._plc = plc;
|
|
|
|
|
|
FloorNo = floor;
|
|
|
|
|
|
EquipNo = equipNo;
|
|
|
|
|
|
this.ScanPoint = StaticData.BasePlcpointList.Where(t => t.floorNo == floor).ToList();//加载当前站点所对应的点位
|
|
|
|
|
|
this.LineRFID = this.ScanPoint.First(t => t.plcpointNo.Contains("RFID"));
|
|
|
|
|
|
this.LineWcsrun = this.ScanPoint.First(t => t.plcpointNo.Contains("wcsrun"));
|
|
|
|
|
|
this.LineSignal = this.ScanPoint.First(t => t.plcpointNo.Contains("linesignal"));
|
|
|
|
|
|
this.LineIsPallet = this.ScanPoint.First(t => t.plcpointNo.Contains("ispallet"));
|
|
|
|
|
|
this.LineSerialNO = this.ScanPoint.First(t => t.plcpointNo.Contains("serialno"));
|
|
|
|
|
|
|
|
|
|
|
|
//var lineRFID = this._plc.Read(NodeSettingCarNo.plcpointAddress);
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
//默认启动,清理plc的上位机写入点位值
|
|
|
|
|
|
this._plc.Write(LineRFID.plcpointAddress, MainCentralControl.QingKongDianWei);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("楼层" + floor + " 初始化数据异常" + ex.Message);
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动上件扫描监听
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void StartPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
|
|
|
|
|
|
FlowPointThread.Start();
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼接驳位扫描线程启动");
|
|
|
|
|
|
LogManager.Info("二楼接驳位扫描线程启动");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MonitorInLocatorPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
//入库任务
|
|
|
|
|
|
var rfid = this._plc.Read(LineRFID.plcpointAddress);
|
|
|
|
|
|
var isSignal = this._plc.Read(LineSignal.plcpointAddress);
|
|
|
|
|
|
var isPallet = this._plc.Read(LineIsPallet.plcpointAddress);
|
|
|
|
|
|
if (rfid != null && isSignal != null && isPallet != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//正常读到输送线信息 有到位信号,并且有托盘,获取条码信息
|
|
|
|
|
|
if (Convert.ToInt32(isSignal) > 0 && Convert.ToInt32(isPallet) == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
//获取条码信息
|
|
|
|
|
|
var palletNo = Convert.ToString(rfid);
|
|
|
|
|
|
//获取任务
|
|
|
|
|
|
var wcsTask = StaticData.WcsTask.Where(t => t.nextPointId == 2 && t.taskType == 3 && t.containerNo == palletNo).FirstOrDefault();
|
|
|
|
|
|
//判断是否为出库任务
|
|
|
|
|
|
if (wcsTask != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsProductOutstock = dbContext.WmsProductOutstock.Where(t => t.saleOrderId == wcsTask.orderId).FirstOrDefault();
|
|
|
|
|
|
if (wmsProductOutstock != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
long? endStationCode = wmsProductOutstock.endStationCode;
|
|
|
|
|
|
//找到目的地楼层
|
|
|
|
|
|
int floorNo=0;
|
|
|
|
|
|
//下发去提升机的去向
|
|
|
|
|
|
this._plc.Write(LineWcsrun.plcpointAddress, 1);
|
|
|
|
|
|
//更新任务
|
|
|
|
|
|
dbContext.WcsTask.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
currPointId = 2,
|
|
|
|
|
|
currPointNo = "F02",
|
|
|
|
|
|
floorNo = floorNo,
|
|
|
|
|
|
nextPointId = 6,
|
|
|
|
|
|
nextPointNo = "T01",
|
|
|
|
|
|
updateTime = DateTime.Now,
|
|
|
|
|
|
updateBy = "二楼接驳位",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//获取输送线上的任务
|
|
|
|
|
|
public WcsTask GetTask(string containerNo, int floorNo, string equipNo)
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
var wcsTask = new WcsTask();
|
|
|
|
|
|
var wareHouseList = StaticData.WmsBaseWarehouse.ToList();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsTask = StaticData.WcsTask.Where(t => t.currPointNo == equipNo).FirstOrDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info(floorNo + "楼接驳位异常" + ex.Message);
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
return wcsTask;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|