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.

142 lines
6.1 KiB
C#

2 years ago
using Khd.Core.Domain.Models;
2 years ago
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;
2 years ago
private readonly BasePlcpoint LineRFID;
private readonly BasePlcpoint LineWcsrun;
private readonly BasePlcpoint LineSignal;
private readonly BasePlcpoint LineIsPallet;
private readonly BasePlcpoint LineSerialNO;
2 years ago
int FloorNo { get; set; }
string EquipNo = "";
2 years ago
int EquipID = 2;
2 years ago
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();//加载当前站点所对应的点位
2 years ago
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"));
2 years ago
//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()
{
2 years ago
Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
2 years ago
FlowPointThread.Start();
2 years ago
Console.WriteLine(DateTime.Now + ":二楼接驳位扫描线程启动");
LogManager.Info("二楼接驳位扫描线程启动");
2 years ago
}
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);
2 years ago
//获取任务
2 years ago
var wcsTask = StaticData.WcsTask.Where(t => t.nextPointId == 2 && t.taskType == 3 && t.containerNo == palletNo).FirstOrDefault();
2 years ago
//判断是否为出库任务
2 years ago
if (wcsTask != null)
2 years ago
{
2 years ago
var wmsProductOutstock = dbContext.WmsProductOutstock.Where(t => t.saleOrderId == wcsTask.orderId).FirstOrDefault();
if (wmsProductOutstock != null)
2 years ago
{
2 years ago
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 = "二楼接驳位",
});
}
2 years ago
}
}
}
}
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
{
2 years ago
wcsTask = StaticData.WcsTask.Where(t => t.currPointNo == equipNo).FirstOrDefault();
2 years ago
}
catch (Exception ex)
{
LogManager.Info(floorNo + "楼接驳位异常" + ex.Message);
throw;
}
return wcsTask;
}
}
}