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.

110 lines
3.8 KiB
C#

2 years ago
using Khd.Core.Domain.Dto.wcs;
using Khd.Core.Domain.Dto.webapi;
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
using Khd.Core.Plc.S7;
using Khd.Core.Wcs.Global;
using Khd.Core.Wcs.Wcs;
using Masuit.Tools;
using Masuit.Tools.Logging;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Khd.Core.Wcs
{
public class MainCentralControl
{
public static object QingKongDianWei;
public static object WcsChuLiWanCheng;
public static object WcsMoRenQuXiang;
private readonly IHost _host;
public MainCentralControl(IHost host)
{
this._host = host;
}
public void Start()
{
try
{
using (var scope = _host.Services.CreateScope())
{
using (var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>())
{
//设置程序启动时清空点位的数据=>0为 Int16位
QingKongDianWei = getValue("2", "0");
//设置默认处理完成=>1为 Int16位
WcsChuLiWanCheng = getValue("2", "1");
//设置默认去向=>1为 Int16位
WcsMoRenQuXiang = getValue("2", "1");
2 years ago
2 years ago
StaticData.BasePlcpointList = dbContext.BasePlcpoint.Where(t => t.isDelete == 0).ToList();
2 years ago
//加载配置项
//连接PLC判断
var plc = new Khd.Core.Plc.S7.Plc((CpuType)PlcConfig.CpuType, PlcConfig.IP, PlcConfig.Port,
PlcConfig.Rack, PlcConfig.Slot);
try
{
plc.Open();
if (plc.IsConnected)
if (true)
{
2 years ago
//一楼调度线程
FirstFloor firstFloor = new FirstFloor(this._host,plc, "一楼输送线");
firstFloor.StartPoint();
Console.WriteLine("一楼调度线程开启!");
//二楼楼调度线程
//三楼调度线程
//四楼调度线程
//五楼调度线程
2 years ago
}
}
catch (Exception ex)
{
//Console.WriteLine("PLC连接失败,重新连接");
LogManager.Info($"程序启动失败 >>> {ex.Message}");
return;
}
}
}
}
catch (Exception ex)
{
LogManager.Error(ex);
}
}
2 years ago
2 years ago
/// <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;
}
}
}