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.

551 lines
34 KiB
C#

1 year ago
using Khd.Core.Domain.Models;
2 years ago
using Khd.Core.EntityFramework;
2 years ago
using Khd.Core.Library.Mapper;
2 years ago
using Khd.Core.Plc.S7;
2 years ago
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>
2 years ago
/// 一楼线程(包括接驳位,提升机调度)
2 years ago
/// </summary>
public class FirstFloor
{
private readonly IHost _host;
2 years ago
private Plc.S7.Plc _plc;
private readonly long F01 = 1;
private readonly long T01 = 6;
2 years ago
/// <summary>
/// 一楼RFID 读
/// </summary>
2 years ago
private readonly BasePlcpoint RFID001;
2 years ago
private readonly BasePlcpoint automatic;
2 years ago
/// <summary>
/// 到位信号 读
/// </summary>
2 years ago
private readonly BasePlcpoint linesignal01;
2 years ago
/// <summary>
2 years ago
/// 提升机流水号 读
2 years ago
/// </summary>
2 years ago
private readonly BasePlcpoint serialno06;
2 years ago
/// <summary>
2 years ago
/// 提升机状态 读
2 years ago
/// </summary>
2 years ago
private readonly BasePlcpoint equipstate06;
2 years ago
/// <summary>
2 years ago
/// 提升机任务状态 读
2 years ago
/// </summary>
2 years ago
private readonly BasePlcpoint hoistertrayin06;
2 years ago
/// <summary>
2 years ago
/// 提升机当前楼层 写
2 years ago
/// </summary>
2 years ago
private readonly BasePlcpoint currentfloor06;
2 years ago
/// <summary>
2 years ago
/// 提升机目的楼层 写
2 years ago
/// </summary>
2 years ago
private readonly BasePlcpoint targetfloor06;
2 years ago
/// <summary>
2 years ago
/// 提升机反馈流水号
2 years ago
/// </summary>
2 years ago
private readonly BasePlcpoint reserialno06;
1 year ago
private readonly BasePlcpoint mesClose;
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
public FirstFloor(IHost host, Plc.S7.Plc plc)
2 years ago
{
this._host = host;
this._plc = plc;
//一楼RFID 读
2 years ago
this.RFID001 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("RFID001"));
2 years ago
//到位信号 读
2 years ago
this.linesignal01 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("linesignal01"));
2 years ago
2 years ago
//一楼提升机流水号 读
2 years ago
this.serialno06 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("serialno06"));
1 year ago
this.mesClose = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("mesclose"));
2 years ago
this.automatic = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("automatic"));
2 years ago
//一楼提升机状态 读
2 years ago
this.equipstate06 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("equipstate06"));
2 years ago
//一楼提升机任务状态 读
2 years ago
this.hoistertrayin06 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("hoistertrayin06"));
2 years ago
//一楼提升机当前楼层 写
2 years ago
this.currentfloor06 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("currentfloor06"));
2 years ago
//一楼提升机目的楼层 写
2 years ago
this.targetfloor06 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("targetfloor06"));
2 years ago
//一楼提升机到位信号 读
2 years ago
this.reserialno06 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("reserialno06"));
2 years ago
2 years ago
}
2 years ago
2 years ago
/// <summary>
2 years ago
/// 启动上件扫描监听
2 years ago
/// </summary>
public void StartPoint()
{
1 year ago
//Thread firstFloorLine = new(FirstFloorLine)
//{
// IsBackground = true
//};
//firstFloorLine.Start();
2 years ago
Console.WriteLine(DateTime.Now + ":一楼接驳位线程启动成功");
LogManager.Info("一楼接驳位线程启动成功");
2 years ago
2 years ago
Thread firstFloorHoister = new(FirstFloorHoister)
{
IsBackground = true
};
2 years ago
firstFloorHoister.Start();
2 years ago
1 year ago
//Thread CallEmptyThread = new Thread(CallEmpty)
//{
// IsBackground = true
//};
//CallEmptyThread.Start();
2 years ago
2 years ago
Console.WriteLine(DateTime.Now + ":一楼提升机线程启动成功");
LogManager.Info("一楼提升机线程启动成功");
2 years ago
}
2 years ago
2 years ago
private void CallEmpty()
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
BasePlcpoint oneOutPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "oneOut");
BasePlcpoint someOutPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "someOut");
BaseEquip mdjEquip = StaticData.BaseEquip.First(t => t.objid == 40);
while (true)
{
try
{
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
var linesignal = this._plc.Read(this.linesignal01.plcpointAddress);
int taskCount = dbContext.WcsTask.Where(t => t.nextPointId == 6 && t.taskStatus > 0 && t.endPointId == 1).Count();
int firstFloorCount = dbContext.WcsTask.Where(t => t.currPointId == 1).Count();
if (Convert.ToInt32(linesignal) == 0 && taskCount == 0 && firstFloorCount == 0)
{
1 year ago
bool canSend = dbContext.WcsTask.Where(t => t.floorNo == 1).Where(t => t.taskStatus > 0).Any();
if (!canSend)
2 years ago
{
1 year ago
WcsTaskManual? wcsTaskManual = dbContext.WcsTaskManual.Where(t => t.nextPointId == 40).FirstOrDefault();
if (wcsTaskManual != null)
2 years ago
{
1 year ago
if (wcsTaskManual.taskType == 53)
2 years ago
{
1 year ago
this._plc.WriteToPoint(someOutPoint.plcpointAddress, "1", someOutPoint.plcpointLength.ToString());
WcsTask wcsTask = CoreMapper.Map<WcsTask>(wcsTaskManual);
wcsTask.createTime = DateTime.Now;
wcsTask.createBy = "一楼接驳位线程";
wcsTask.taskStatus = 0;
wcsTask.useFlag = 1;
wcsTask.isEmpty = "1";
wcsTask.qty = mdjEquip.emptyCount;
wcsTask.remark = "一楼创建入库任务";
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
2 years ago
mdjEquip.emptyCount = 0;
1 year ago
dbContext.Update(mdjEquip);
dbContext.Add(wcsTaskLog);
dbContext.Add(wcsTask);
dbContext.SaveChanges();
LogManager.Info("一楼接驳位线程:空托盘任务下发成功");
Console.WriteLine(DateTime.Now + ":一楼接驳位线程:空托盘任务下发成功");
2 years ago
}
}
}
}
}
catch
{
}
Thread.Sleep(1000);
}
}
1 year ago
public static bool ReadEmptyLocation()
1 year ago
{
var oneOutPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "oneOut");
var someOutPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "someOut");
var oneInPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "oneIn");
var someInPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "someIn");
1 year ago
var oneOutValue = StaticData.PlcDic[0].Read(oneOutPoint.plcpointAddress);
var someOutValue = StaticData.PlcDic[0].Read(someOutPoint.plcpointAddress);
var oneInValue = StaticData.PlcDic[0].Read(oneInPoint.plcpointAddress);
var someInValue = StaticData.PlcDic[0].Read(someInPoint.plcpointAddress);
1 year ago
if (oneOutValue != null && someOutValue != null && oneInValue != null && someInValue != null)
{
if (Convert.ToInt32(oneOutValue) == 0 && Convert.ToInt32(someOutValue) == 0 && Convert.ToInt32(oneInValue) == 0 && Convert.ToInt32(someInValue) == 0)
{
return true;
}
}
return false;
}
2 years ago
/// <summary>
/// 启动一楼接驳位线程
/// </summary>
private void FirstFloorLine()
{
1 year ago
List<int?> Outtpyes = new() { 2, 4, 8, 6 };
2 years ago
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
2 years ago
while (true)
{
try
{
2 years ago
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
2 years ago
var RFID001Value = this._plc.ReadRFID(this.RFID001.plcpointAddress); //一楼RFID 读
2 years ago
var linesignal01Value = this._plc.Read(this.linesignal01.plcpointAddress); //到位信号 读
2 years ago
//正常读到plc值
if (linesignal01Value != null && RFID001Value != null)
2 years ago
{
2 years ago
//正常托盘到位
1 year ago
BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == 1);
2 years ago
if (Convert.ToInt32(linesignal01Value) == 1)
2 years ago
{
2 years ago
//判断task表里没有该rfid的未完成的入库
//信息,未下发去向
1 year ago
var task = dbContext.WcsTask.Where(t => t.nextPointId == 1).OrderBy(t => t.createTime).FirstOrDefault();
2 years ago
if (task == null)
2 years ago
{
2 years ago
//根据托盘号获取物料码
2 years ago
var material = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID001Value).FirstOrDefault();
1 year ago
WcsTaskLog? taskLog = dbContext.WcsTaskLog.Where(t => t.containerNo == RFID001Value).OrderByDescending(t => t.createTime).FirstOrDefault();
2 years ago
if (material != null)
{
1 year ago
if (taskLog != null)
2 years ago
{
1 year ago
if (taskLog.materialBarcode == material.materialBarcode)
2 years ago
{
1 year ago
if (baseEquip.containerNo == "0")
{
baseEquip.containerNo = null;
dbContext.Update(baseEquip);
dbContext.SaveChanges();
LogManager.Info("一楼接驳位线程:托盘" + RFID001Value + "解绑信息更新成功");
}
else if (baseEquip.containerNo != RFID001Value)
{
baseEquip.containerNo = RFID001Value;
dbContext.Update(baseEquip);
dbContext.SaveChanges();
LogManager.Info("一楼接驳位线程:托盘" + RFID001Value + "绑定信息更新成功");
Console.WriteLine(DateTime.Now + ":一楼接驳位线程:托盘" + RFID001Value + "绑定信息更新成功");
Thread.Sleep(3000);
continue;
}
else
{
Thread.Sleep(3000);
continue;
}
2 years ago
}
}
1 year ago
2 years ago
var warehouseId = dbContext.WmsWarehouseMaterial.Where(t => t.storageType == "1" && t.storageId == material.materialId).FirstOrDefault()?.warehouseId;
if (warehouseId != null)
2 years ago
{
2 years ago
var TargetFloor = dbContext.WmsBaseWarehouse.Where(t => t.warehouseId == warehouseId).FirstOrDefault();
if (TargetFloor != null)
2 years ago
{
2 years ago
//插入task表
2 years ago
2 years ago
var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.agvType == "I" && t.dicField == TargetFloor.warehouseInstockType).FirstOrDefault();
2 years ago
if (dic != null)
2 years ago
{
2 years ago
var newTask = new WcsTask()
{
objid = StaticData.SnowId.NextId(),
2 years ago
serialNo = SystemData.GetSerialNo(dbContext),
2 years ago
equipmentNo = "F01",
taskType = Convert.ToInt32(dic.dicValue),
taskStatus = 0,
2 years ago
containerNo = RFID001Value,
1 year ago
materialBarcode = material.materialBarcode,
2 years ago
materialId = material.materialId,
qty = Convert.ToInt32(material.bindAmount),
currPointId = F01,
2 years ago
currPointNo = "TSJ_01",
2 years ago
nextPointId = T01,
2 years ago
nextPointNo = "TSJ_01",
2 years ago
endPointId = warehouseId,
fromFloorNo = 1,
floorNo = TargetFloor.warehouseFloor,
useFlag = 1,
createBy = "一楼接驳位",
createTime = DateTime.Now,
remark = "一楼创建入库任务"
};
2 years ago
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(newTask);
dbContext.Add(wcsTaskLog);
2 years ago
dbContext.Add(newTask);
2 years ago
dbContext.SaveChanges();
2 years ago
}
}
2 years ago
}
2 years ago
}
}
1 year ago
else
2 years ago
{
1 year ago
if (string.IsNullOrEmpty(task.containerNo))
2 years ago
{
1 year ago
if (task.qty > 1)//多个托盘
1 year ago
{
1 year ago
if (task.useFlag == 1)
{
}
}
else if (task.qty == 1)
{
1 year ago
}
}
2 years ago
}
2 years ago
}
}
}
catch (Exception ex)
{
2 years ago
if (ex is PlcException)
{
2 years ago
foreach (var item in StaticData.PlcDic)
2 years ago
{
2 years ago
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();
}
2 years ago
}
}
2 years ago
LogManager.Error(ex);
}
2 years ago
Thread.Sleep(1000);
2 years ago
}
}
/// <summary>
2 years ago
/// 提升机线程
2 years ago
/// </summary>
private void FirstFloorHoister()
{
1 year ago
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
2 years ago
while (true)
{
try
{
1 year ago
var mesCloseValue = this._plc.Read(this.mesClose.plcpointAddress); //MES关闭状态 读
2 years ago
var serialno06Value = this._plc.Read(this.serialno06.plcpointAddress); //提升机流水号 读
var equipstate06Value = this._plc.Read(this.equipstate06.plcpointAddress); //提升机状态 读
var hoisterTrayIn06Value = this._plc.Read(this.hoistertrayin06.plcpointAddress); //提升机货物到位状态 读
var currentfloor06Value = this._plc.Read(this.currentfloor06.plcpointAddress); //提升机当前楼层 读
var targetfloor06Value = this._plc.Read(this.targetfloor06.plcpointAddress); //提升机目的楼层 写
var reserialno06 = this._plc.Read(this.reserialno06.plcpointAddress); //反馈流水号
1 year ago
if (mesCloseValue != null && Convert.ToInt32(mesCloseValue) == 0)
2 years ago
{
1 year ago
//正常读到plc值
if (targetfloor06Value != null && serialno06Value != null && equipstate06Value != null && currentfloor06Value != null && reserialno06 != null && hoisterTrayIn06Value != null)
2 years ago
{
1 year ago
//提升机空闲
if (Convert.ToInt32(equipstate06Value) == 0)
2 years ago
{
1 year ago
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
var wcsTasks = dbContext.WcsTask.Where(t => t.nextPointId == T01).OrderBy(t => t.createTime).ToList();
foreach (var wcsTask in wcsTasks)
2 years ago
{
1 year ago
wcsTask.serialNo ??= SystemData.GetSerialNo(dbContext);
1 year ago
if (wcsTasks.Where(t => t.taskStatus > 0).Where(t => t.objid != wcsTask.objid).Any())
2 years ago
{
1 year ago
LogManager.Info("提升机线程:有其他任务正在执行,跳过当前任务");
2 years ago
continue;
}
1 year ago
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == wcsTask.floorNo);
if (wcsTask.taskStatus == 0 && Convert.ToInt32(hoisterTrayIn06Value) == 0)//创建状态,并且里面没有货物
2 years ago
{
1 year ago
if (lineEquip.equipStatus == 1)
2 years ago
{
1 year ago
LogManager.Info("提升机线程:" + wcsTask.floorNo + "楼接驳位有AGV任务跳过当前任务");
continue;
2 years ago
}
1 year ago
BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress))
2 years ago
{
1 year ago
if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)
{
wcsTask.taskStatus = 2;
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
wcsTask.remark = "提升机任务执行中";
BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun"));
this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString());
dbContext.Update(wcsTask);
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 2, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
lineEquip.equipStatus = 1;
dbContext.Update(lineEquip);
dbContext.SaveChanges();
}
else
{
wcsTask.taskStatus = 1;
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
wcsTask.remark = "提升机任务执行中";
this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, wcsTask.fromFloorNo.ToString(), this.targetfloor06.plcpointLength.ToString());//目的地楼层
this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString());
dbContext.Update(wcsTask);
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 1, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
lineEquip.equipStatus = 1;
dbContext.Update(lineEquip);
dbContext.SaveChanges();
}
}
}
if (wcsTask.taskStatus == 1 && Convert.ToInt32(reserialno06) == wcsTask.serialNo)
{
BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress))
{
if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)//提升机当前楼层为初始地楼层
{
wcsTask.taskStatus = 2;
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
wcsTask.remark = "提升机任务执行中";
BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun"));
this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString());
dbContext.Update(wcsTask);
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 2, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
dbContext.SaveChanges();
}
}
}
if (wcsTask.taskStatus == 2 && Convert.ToInt32(reserialno06) == wcsTask.serialNo)
{
if (Convert.ToInt32(hoisterTrayIn06Value) == 1)//托盘已经进提升机
{
wcsTask.taskStatus = 3;
2 years ago
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
1 year ago
wcsTask.remark = "提升机任务执行完成";
this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, wcsTask.floorNo.ToString(), this.targetfloor06.plcpointLength.ToString());//目的地楼层
2 years ago
dbContext.Update(wcsTask);
1 year ago
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 3, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
2 years ago
dbContext.SaveChanges();
}
2 years ago
}
1 year ago
if (wcsTask.taskStatus == 3 && Convert.ToInt32(currentfloor06Value) == wcsTask.floorNo && Convert.ToInt32(reserialno06) == wcsTask.serialNo)//任务状态为3且当前楼层为任务的目的楼层
2 years ago
{
1 year ago
if (wcsTask.floorNo == 1)
2 years ago
{
1 year ago
if (ReadEmptyLocation())
1 year ago
{
var linesignal = _plc.Read(StaticData.BasePlcpointList.First(t => t.plcpointNo == $"linesignal0{wcsTask.floorNo}").plcpointAddress);
if (linesignal != null && Convert.ToInt32(linesignal) == 0)
{
wcsTask.taskStatus = 4;
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
wcsTask.remark = "提升机任务执行完成";
BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.floorNo && t.plcpointNo.Contains("wcsrun"));
this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "2", basePlcpoint.plcpointLength.ToString());//去向为2表示提升机已到达目的地让货出去
dbContext.Update(wcsTask);
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 4, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
dbContext.SaveChanges();
}
else
{
BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.equipmentNo == $"clear0{wcsTask.floorNo}");
this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
}
}
}
else
{
var linesignal = _plc.Read(StaticData.BasePlcpointList.First(t => t.plcpointNo == $"linesignal0{wcsTask.floorNo}").plcpointAddress);
if (linesignal != null && Convert.ToInt32(linesignal) == 0)
1 year ago
{
wcsTask.taskStatus = 4;
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
wcsTask.remark = "提升机任务执行完成";
1 year ago
BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.floorNo && t.plcpointNo.Contains("wcsrun"));
1 year ago
this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "2", basePlcpoint.plcpointLength.ToString());//去向为2表示提升机已到达目的地让货出去
dbContext.Update(wcsTask);
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 4, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
dbContext.SaveChanges();
}
1 year ago
else
{
BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.equipmentNo == $"clear0{wcsTask.floorNo}");
this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
}
2 years ago
}
2 years ago
}
1 year ago
else if (wcsTask.taskStatus == 4)
2 years ago
{
1 year ago
BaseEquip floorEquip = StaticData.BaseEquip.First(t => t.objid == wcsTask.floorNo);
wcsTask.nextPointId = floorEquip.objid;
wcsTask.nextPointNo = floorEquip.equipNo;
wcsTask.taskStatus = 5;
2 years ago
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
wcsTask.remark = "提升机任务执行完成";
1 year ago
lineEquip.equipStatus = 0;
dbContext.Update(lineEquip);
2 years ago
dbContext.Update(wcsTask);
1 year ago
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 5, nextPointId = floorEquip.objid, nextPointNo = floorEquip.equipNo, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
2 years ago
dbContext.SaveChanges();
2 years ago
}
1 year ago
break;
2 years ago
}
2 years ago
}
}
}
1 year ago
else
{
if (currentfloor06Value != null && targetfloor06Value != null)
{
this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, Convert.ToString(currentfloor06Value), this.targetfloor06.plcpointLength.ToString());
continue;
}
}
2 years ago
}
catch (Exception ex)
{
2 years ago
if (ex is PlcException)
{
try
{
2 years ago
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();
}
}
2 years ago
}
catch
{
}
}
2 years ago
LogManager.Error(ex);
}
2 years ago
Thread.Sleep(5000);
2 years ago
}
}
}
}