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.

128 lines
4.5 KiB
C#

using Jc.SnowId;
2 years ago
using Khd.Core.Domain.Dto.TaskType;
using Khd.Core.Domain.Models;
2 years ago
using Khd.Core.EntityFramework;
2 years ago
using Khd.Core.Library;
2 years ago
using Khd.Core.Wcs.Global;
2 years ago
using Khd.Core.Wcs.Wcs;
using Microsoft.EntityFrameworkCore;
2 years ago
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
2 years ago
using System.Data;
2 years ago
using Z.EntityFramework.Plus;
2 years ago
namespace Khd.Core.Wcs
{
public class MainCentralControl
{
2 years ago
public static object QingKongDianWei = 0;
public static object WcsChuLiWanCheng = 1;
public static object WcsMoRenQuXiang = 1;
2 years ago
private readonly IHost _host;
2 years ago
/// <summary>
/// 构造函数
/// </summary>
/// <param name="host"></param>
2 years ago
public MainCentralControl(IHost host)
{
this._host = host;
}
2 years ago
/// <summary>
/// 启动程序
/// </summary>
2 years ago
public void Start()
{
2 years ago
2 years ago
LoggerUtils logger = new LoggerUtils();
2 years ago
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
2 years ago
try
{
2 years ago
StaticData.BasePlcpointList = dbContext.BasePlcpoint.Where(t => t.isDelete == 0).ToList();//设备交互用
StaticData.basePlcs = dbContext.BasePlc.ToList();//陈工Agv和设备信息推送
StaticData.BaseEquip = dbContext.BaseEquip.ToList();//设备信息
StaticData.BaseDictionary = dbContext.BaseDictionary.ToList();//字典表Agv任务模板
StaticData.DmsBaseAlarmRuleList = dbContext.DmsBaseAlarmRule.ToList();
2 years ago
2 years ago
foreach (var plcConfig in StaticData.PlcConfigs)
{
if (!StaticData.PlcDic.Any(t => t.Key == plcConfig.Code))
{
Plc.S7.Plc plc;
plc = new Plc.S7.Plc(plcConfig.CpuType, plcConfig.IP, plcConfig.Port, plcConfig.Rack, plcConfig.Slot);
2 years ago
try
{
2 years ago
plc.Open();
2 years ago
Console.WriteLine(DateTime.Now + ":连接PLC" + plcConfig.IP);
2 years ago
}
catch
{
Console.WriteLine(DateTime.Now + ":连接Plc" + plcConfig.IP + "失败~~~~~~~");
}
2 years ago
StaticData.PlcDic.TryAdd(plcConfig.Code, plc);
}
}
2 years ago
//创建定时器
2 years ago
SystemTimer systemTimer = new(_host);
2 years ago
systemTimer.Start();
2 years ago
//创建任务
CreateTaskByRecord createTaskByRecord = new(_host);
createTaskByRecord.StartPoint();
2 years ago
2 years ago
//一楼提升机以及接驳位
2 years ago
FirstFloor firstFloor = new(_host);
2 years ago
firstFloor.StartPoint();
2 years ago
2 years ago
//二层接驳位
2 years ago
SecondFloorPoint secondFloorPoint = new(_host, 2);
2 years ago
secondFloorPoint.StartPoint();
2 years ago
2 years ago
////二层AGV
SecondFloorAGV secondFloorAGV = new(_host, 2);
2 years ago
secondFloorAGV.StartPoint();
2 years ago
// //二楼线体
2 years ago
SecondFloorLine secondFloorLine = new(_host, 2);
2 years ago
secondFloorLine.StartPoint();
2 years ago
2 years ago
//三层接驳位
2 years ago
ThirdFloorPoint thirdFloorPoint = new(_host, 3);
2 years ago
thirdFloorPoint.StartPoint();
2 years ago
2 years ago
// 三层AGV
2 years ago
ThirdFloorAGV thirdFloorAGV = new(_host, 3);
2 years ago
thirdFloorAGV.StartPoint();
2 years ago
2 years ago
//四楼接驳位
2 years ago
FourthFloorPoint fourthFloorPoint = new(_host, 4);
2 years ago
fourthFloorPoint.StartPoint();
2 years ago
//五层接驳位
2 years ago
FiveFloorPoint fifthFloorPoint = new(_host, 5);
2 years ago
fifthFloorPoint.StartPoint();
2 years ago
2 years ago
//五层CTU
FiveFloorCTU fiveFloorCTU = new(_host, 5);
2 years ago
fiveFloorCTU.StartPoint();
2 years ago
2 years ago
//五层AGV
2 years ago
FiveFloorAGV fifthFloorAGV = new(_host, 5);
2 years ago
fifthFloorAGV.StartPoint();
2 years ago
2 years ago
////背负式Agv
FiveFloorBearAgv fiveFloorBearAgv = new(_host, 5);
2 years ago
fiveFloorBearAgv.StartPoint();
2 years ago
}
catch (Exception ex)
{
2 years ago
Console.WriteLine(ex.Message);
2 years ago
logger.Error(ex.Message + "\n" + ex.StackTrace);
2 years ago
}
}
2 years ago
2 years ago
}
}