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.

218 lines
9.5 KiB
C#

2 years ago
using Khd.Core.Domain.Dto.wcs;
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 System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using Thrift.Server;
using Thrift.Transport;
using ThriftService;
using static AngleSharp.Css.Values.CssRadialGradientValue;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Thrift.Protocol;
using System.Security.Cryptography.Xml;
using Z.EntityFramework.Plus;
using System.Net.NetworkInformation;
namespace Khd.Core.Wcs.Wcs
{
/// <summary>
/// 一楼线程
/// </summary>
public class FirstFloor
{
private readonly IHost _host;
private readonly Plc.S7.Plc _plc;
/// <summary>
/// 一楼RFID 读
/// </summary>
BasePlcpoint? RFID001 { get; set; }
/// <summary>
/// 到位信号 读
/// </summary>
BasePlcpoint? linesignal01 { get; set; }
/// <summary>
/// 是否有托盘 读
/// </summary>
BasePlcpoint? ispallet01 { get; set; }
/// <summary>
/// 去向 写
/// </summary>
BasePlcpoint? wcsrun01 { get; set; }
/// <summary>
/// 流水号 读
/// </summary>
BasePlcpoint? serialno01 { get; set; }
/// <summary>
/// 反馈流水号 写
/// </summary>
BasePlcpoint? feedserialno01 { get; set; }
/// <summary>
/// 一楼提升机流水号 读
/// </summary>
BasePlcpoint? serialno06 { get; set; }
/// <summary>
/// 一楼提升机状态 读
/// </summary>
BasePlcpoint? equipstate06 { get; set; }
/// <summary>
/// 一楼提升机任务状态 读
/// </summary>
BasePlcpoint? taskstate06 { get; set; }
/// <summary>
/// 一楼提升机当前楼层 写
/// </summary>
BasePlcpoint? currentfloor06 { get; set; }
/// <summary>
/// 一楼提升机目的楼层 写
/// </summary>
BasePlcpoint? targetfloor06 { get; set; }
/// <summary>
/// 一楼提升机到位信号 读
/// </summary>
BasePlcpoint? linesignal06 { get; set; }
public FirstFloor(IHost host, Plc.S7.Plc plc, string siteNo)
{
this._host = host;
this._plc = plc;
//一楼RFID 读
this.RFID001 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") &&t.plcpointNo.Contains("RFID001"));
//到位信号 读
this.linesignal01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("linesignal01"));
//是否有托盘 读
this.ispallet01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("ispallet01"));
//去向 写
this.wcsrun01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("wcsrun01"));
//流水号 读
this.serialno01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("serialno01"));
//反馈流水号 写
this.feedserialno01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("feedserialno01"));
//一楼提升机流水号 读
this.serialno06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("serialno06"));
//一楼提升机状态 读
this.equipstate06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("equipstate06"));
//一楼提升机任务状态 读
this.taskstate06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("taskstate06"));
//一楼提升机当前楼层 写
this.currentfloor06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("currentfloor06"));
//一楼提升机目的楼层 写
this.targetfloor06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("targetfloor06"));
//一楼提升机到位信号 读
this.linesignal06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("linesignal06"));
}
/// <summary>
/// 启动线程
/// </summary>
public void StartPoint()
{
Thread firstFloorLine = new Thread(FirstFloorLine);
firstFloorLine.IsBackground = true;
firstFloorLine.Start();
Console.WriteLine("启动一楼接驳位线程");
Thread firstFloorHoister = new Thread(FirstFloorHoister);
firstFloorHoister.IsBackground = true;
firstFloorHoister.Start();
Console.WriteLine("启动一楼提升机线程");
}
/// <summary>
/// 启动一楼接驳位线程
/// </summary>
private void FirstFloorLine()
{
while (true)
{
try
{
var RFID001Value = this._plc.Read(this.RFID001.plcpointAddress); //一楼RFID 读
var linesignal01Value = this._plc.Read(this.linesignal01.plcpointAddress); //到位信号 读
var ispallet01Value = this._plc.Read(this.ispallet01.plcpointAddress); //是否有托盘 读
var wcsrun01Value = this._plc.Read(this.wcsrun01.plcpointAddress); //去向 写
var serialno01Value = this._plc.Read(this.serialno01.plcpointAddress); //流水号 读
var feedserialno01Value = this._plc.Read(this.feedserialno01.plcpointAddress); //反馈流水号 写
using (var scope = _host.Services.CreateScope())
{
using (var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>())
{
//正常读到plc值
if (linesignal01Value != null && RFID001Value != null || ispallet01Value != null || serialno01Value != null)
{
//正常托盘到位
if (Convert.ToInt32(linesignal01Value) != 0 && Convert.ToInt32(serialno01Value) != 0 && Convert.ToInt32(ispallet01Value) == 1 && Convert.ToInt32(ispallet01Value) != 0)
{
//根据托盘号获取物料码
//下发去向
}
}
}
}
}
catch (Exception ex)
{
LogManager.Error(ex);
}
Thread.Sleep(2000);
}
}
/// <summary>
/// 启动一楼提升机线程
/// </summary>
private void FirstFloorHoister()
{
while (true)
{
try
{
var serialno06Value = this._plc.Read(this.serialno06.plcpointAddress); //一楼提升机流水号 读
var equipstate06Value = this._plc.Read(this.equipstate06.plcpointAddress); //一楼提升机状态 读
var taskstate06Value = this._plc.Read(this.taskstate06.plcpointAddress); //一楼提升机任务状态 读
var currentfloor06Value = this._plc.Read(this.currentfloor06.plcpointAddress); //一楼提升机当前楼层 写
var targetfloor06Value = this._plc.Read(this.targetfloor06.plcpointAddress); //一楼提升机目的楼层 写
var linesignal06Value = this._plc.Read(this.linesignal06.plcpointAddress); //一楼提升机到位信号 读
using (var scope = _host.Services.CreateScope())
{
using (var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>())
{
//正常读到plc值
if (serialno06Value != null && equipstate06Value != null || taskstate06Value != null || linesignal06Value != null)
{
//正常托盘到位
if (Convert.ToInt32(serialno06Value) != 0 && Convert.ToInt32(equipstate06Value) != 1 && Convert.ToInt32(linesignal06Value) == 1)
{
//根据流水号查询任务 分配去向
}
}
}
}
}
catch (Exception ex)
{
LogManager.Error(ex);
}
Thread.Sleep(2000);
}
}
}
}