|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
using Khd.Core.Plc.S7;
|
|
|
|
|
|
using Khd.Core.Wcs.Global;
|
|
|
|
|
|
using Khd.Core.Wcs.MyWcs;
|
|
|
|
|
|
using Masuit.Tools.Logging;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Wcs
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MainCentralControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public static object QingKongDianWei = 0;
|
|
|
|
|
|
public static object WcsChuLiWanCheng = 1;
|
|
|
|
|
|
public static object WcsMoRenQuXiang = 1;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IHost _host;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构造函数
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="host"></param>
|
|
|
|
|
|
public MainCentralControl(IHost host)
|
|
|
|
|
|
{
|
|
|
|
|
|
this._host = host;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动程序
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
StaticData.PlcPoints = dbContext.PlcPoint.GroupBy(t => t.Floor_No).ToDictionary(t => t.Key, t => t.ToDictionary(t => t.PlcPoint_No, t => t));
|
|
|
|
|
|
//设置程序启动时清空点位的数据=>0为 Int16位
|
|
|
|
|
|
QingKongDianWei = GetValue("2", "0");
|
|
|
|
|
|
//设置默认处理完成=>1为 Int16位
|
|
|
|
|
|
WcsChuLiWanCheng = GetValue("2", "1");
|
|
|
|
|
|
//设置默认去向=>1为 Int16位
|
|
|
|
|
|
WcsMoRenQuXiang = GetValue("2", "1");
|
|
|
|
|
|
|
|
|
|
|
|
StaticData.BasePlcpointList = dbContext.BasePlcpoint.Where(t => t.isDelete == 0).ToList();
|
|
|
|
|
|
var baseEquips = dbContext.BaseEquip.ToList();
|
|
|
|
|
|
//加载配置项
|
|
|
|
|
|
foreach (var plcConfig in StaticData.PlcConfigs)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!StaticData.PlcDic.Any(t => t.Key == plcConfig.Code))
|
|
|
|
|
|
{
|
|
|
|
|
|
var plc = new Plc.S7.Plc((CpuType)plcConfig.CpuType, plcConfig.IP, plcConfig.Port, plcConfig.Rack, plcConfig.Slot);
|
|
|
|
|
|
plc.Open();
|
|
|
|
|
|
StaticData.PlcDic.TryAdd(plcConfig.Code, plc);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//连接PLC判断
|
|
|
|
|
|
foreach (var item in baseEquips)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.floorNo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.equipType == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
DockingPositionLogic dockingPositionLogic = new(item.floorNo.Value, item, _host, StaticData.PlcDic[0]);
|
|
|
|
|
|
dockingPositionLogic.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.equipType == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
ElevatorLogic elevatorLogic = new(item.floorNo.Value, item, _host, StaticData.PlcDic[0]);
|
|
|
|
|
|
elevatorLogic.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.equipType == 4 || item.equipType == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
AgvTaskLogic agvTaskLogic = new(item.floorNo.Value, item, baseEquips.First(t => t.equipType == 1 && t.floorNo == item.floorNo), _host, StaticData.PlcDic[0]);
|
|
|
|
|
|
agvTaskLogic.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 电气写入点位高低位转换
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="len">点位地址位长度</param>
|
|
|
|
|
|
/// <param name="value">写入数值</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static object GetValue(string len, string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (len == "2")
|
|
|
|
|
|
{
|
|
|
|
|
|
return Convert.ToInt16(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (len == "4")
|
|
|
|
|
|
{
|
|
|
|
|
|
return Convert.ToInt32(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|