|
|
|
|
|
using Khd.Core.Domain.Dto.webapi;
|
|
|
|
|
|
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 Newtonsoft.Json;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 五楼CTU调度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class FiveFloorCTU
|
|
|
|
|
|
{
|
|
|
|
|
|
List<BasePlcpoint> ScanPoint { get; set; }//点位信息
|
|
|
|
|
|
private readonly IHost _host;
|
|
|
|
|
|
private readonly Plc.S7.Plc _plc;
|
|
|
|
|
|
BasePlcpoint? LineRFID { get; set; }
|
|
|
|
|
|
BasePlcpoint? LineWcsrun { get; set; }
|
|
|
|
|
|
BasePlcpoint? LineSignal { get; set; }
|
|
|
|
|
|
BasePlcpoint? LineIsPallet { get; set; }
|
|
|
|
|
|
BasePlcpoint? LineSerialNO { get; set; }
|
|
|
|
|
|
BasePlcpoint? LineFeedSeriaNo { get; set; }
|
|
|
|
|
|
Thread FlowPointThread;
|
|
|
|
|
|
int FloorNo { get; set; }
|
|
|
|
|
|
string EquipNo = "";
|
|
|
|
|
|
int CTUID = 11;
|
|
|
|
|
|
public FiveFloorCTU(IHost host, Plc.S7.Plc plc, int floor, string equipNo)
|
|
|
|
|
|
{
|
|
|
|
|
|
this._host = host;
|
|
|
|
|
|
this._plc = plc;
|
|
|
|
|
|
FloorNo = floor;
|
|
|
|
|
|
EquipNo = equipNo;
|
|
|
|
|
|
|
|
|
|
|
|
//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()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
FlowPointThread = new Thread(MonitorInLocatorPoint);
|
|
|
|
|
|
FlowPointThread.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MonitorInLocatorPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var taskList = dbContext.WcsTask.Where(t => t.nextPointId == CTUID &&( t.taskType==7 || t.taskType == 8)).GroupBy(t=>t.orderId).ToList();
|
|
|
|
|
|
if (taskList.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info(FloorNo + "楼CTU无任务");
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var item in taskList)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
SendTask(item.FirstOrDefault().orderId);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 下发任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="task"></param>
|
|
|
|
|
|
public void SendTask(long? orderId)
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
var taskList = dbContext.WcsTask.Where(t => t.orderId == orderId).ToList();
|
|
|
|
|
|
//获取
|
|
|
|
|
|
if (taskList.Count == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
//首先判断是否已下发指令
|
|
|
|
|
|
var cmd = dbContext.WcsCmd.Where(t => taskList.Select(t => t.objid).ToList().Contains(t.taskId.GetValueOrDefault())).FirstOrDefault();
|
|
|
|
|
|
//指令表存在说明已下发
|
|
|
|
|
|
if (cmd != null) return;
|
|
|
|
|
|
//获取下发agv指令
|
|
|
|
|
|
string ip = ""; int port = 0; string url = "";
|
|
|
|
|
|
RequestAGVTaskDto agvtask = new RequestAGVTaskDto();
|
|
|
|
|
|
agvtask.reqCode = orderId.ToString();
|
|
|
|
|
|
var json = JsonConvert.SerializeObject(agvtask);
|
|
|
|
|
|
HttpHelper.SendPostMessage(ip, port, url, json);
|
|
|
|
|
|
foreach (var item in taskList)
|
|
|
|
|
|
{
|
|
|
|
|
|
//未下发给agv下发指令
|
|
|
|
|
|
WcsCmd taskCmd = new WcsCmd()
|
|
|
|
|
|
{
|
|
|
|
|
|
taskId = item.objid,
|
|
|
|
|
|
cmdType = item.taskType,
|
|
|
|
|
|
serialNo = item.serialNo,
|
|
|
|
|
|
equipmentNo = item.equipmentNo,
|
|
|
|
|
|
cmdStatus = 1,
|
|
|
|
|
|
createBy = FloorNo + "楼CTU",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(taskCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|