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.

198 lines
8.1 KiB
C#

using CentralControl.BaseData;
using CommonFunc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using CentralControl.DBDAO;
using XGL.Thrift;
namespace CentralControl.App_Code
{
/// <summary>
/// 入库暂存区逻辑
/// </summary>
public class Logic1006EmptyLocator
{
/// <summary>
/// plc 正在读取
/// </summary>
bool IsPlcRead { get; set; }
Thread InputMaterialThread;
PlcHelper plcHelper;
string LineNo { get; set; }
NodeSetting ScanPoint { get; set; }
/// <summary>
/// 是否运行发车中
/// </summary>
bool IsRuning { get; set; }
//NodeSetting OutLocatorPoint { get; set; }
/// <summary>
/// 1号上件点 空车信号
/// </summary>
NodeSetting otherLocatorPoint1 { get; set; }
/// <summary>
/// 2号上件点 空车信号
/// </summary>
NodeSetting otherLocatorPoint2 { get; set; }
public Logic1006EmptyLocator(PlcHelper plc, string nodeno)
{
try
{
this.ScanPoint = StaticData.NodeSettingList.FirstOrDefault(t => t.NodeNo == nodeno);
if (this.ScanPoint != null)
{
this.LineNo = this.ScanPoint.LineCatchArea != null ? this.ScanPoint.LineCatchArea.LineNo : "1";
}
else
{
Logger logger = new Logger();
logger.Log("创建线体,未找到扫描点位");
}
this.LineNo = LineNo;
this.plcHelper = plc;
///回写plc状态处理完成,plc会清理数据
object wcsend = this.plcHelper.Read(ScanPoint.PlcSetting5);
//if (Convert.ToInt32(wcsend) == 1)
//{
//默认启动,清理plc的上位机写入点位值
this.plcHelper.Write(this.ScanPoint.PlcSetting4, 0);
this.plcHelper.Write(this.ScanPoint.PlcSetting5, 0);
// }
}
catch (Exception ex)
{
Console.WriteLine("站点" + nodeno + " 初始化数据异常" + ex.Message);
Logger logger = new Logger();
logger.Error("站点" + nodeno + " 初始化数据异常" + ex.Message);
}
}
/// <summary>
/// 启动上件扫描监听
/// </summary>
public void StartPoint()
{
InputMaterialThread = new Thread(MonitorInLocatorPoint);
InputMaterialThread.Start();
}
/// <summary>
/// 前端点击放行,放行小车队列
/// </summary>
/// <param name="lineNo"></param>
/// <param name="materials"></param>
public void MonitorInLocatorPoint()
{
Logger logger = new Logger();
while (true)
{
try
{
///读取小车号
object carobj = this.plcHelper.Read(this.ScanPoint.PlcSetting1);
string carno = Common.getCarNoByPlcPoint(carobj);
//小车是否到位
object carstate = this.plcHelper.Read(this.ScanPoint.PlcSetting2);
//小车是否离开
object carrun = this.plcHelper.Read(this.ScanPoint.PlcSetting3);
///上位机写入岔道信息
object wcsstate = this.plcHelper.Read(this.ScanPoint.PlcSetting4);
///回写plc状态处理完成,plc会清理数据
object wcsend = this.plcHelper.Read(this.ScanPoint.PlcSetting5);
if (carno != null && carstate != null && carrun != null && wcsstate != null && wcsend != null)
{
if (Convert.ToInt32(carno) > 0 && Convert.ToInt32(wcsend) == 0 && Convert.ToInt32(wcsstate) == 0 && Convert.ToInt32(carstate) == 1 && Convert.ToInt32(carrun) == 0 && IsPlcRead == false)
{
CarRealInfo car = StaticData.CarRealList.Where(t => t.CarNo == carno.ToString()).FirstOrDefault();
/**测试数据**/
//car.LocatorArea = new LineCatchArea();
//car.LocatorArea.AreaNo = "1";
DBService.AddSystemLog(this.ScanPoint.NodeNo, car);
var emptyids1 = StaticData.LineCatchAreaList.Where(t => t.AreaType == 5 && t.LineNo == "1").Select(t => t.Id).ToArray();
var emptyids2 = StaticData.LineCatchAreaList.Where(t => t.AreaType == 5 && t.LineNo == "2").Select(t => t.Id).ToArray();
var locatornum1 = StaticData.CarRealList.Count(t => emptyids1.Contains(t.LocatorId));
var locatornum2 = StaticData.CarRealList.Count(t => emptyids2.Contains(t.LocatorId));
LineCatchArea linearea = null;
//一库区车多,进二库区,, 两个空车区的分发空车逻辑
if (true) ///if (locatornum1 > locatornum2)
{
linearea = StaticData.LineCatchAreaList.FirstOrDefault(t => t.AreaType == 5 && t.LineNo == "1" && t.AreaNo == "1");
}
else //二库区车多,进一库区
{
var locators = StaticData.LineCatchAreaList.Where(t => t.AreaType == 5 && t.LineNo == "1").OrderByDescending(t => t.AreaNo);
foreach (var locator in locators)
{
var locatorempnum1 = StaticData.CarRealList.Count(t => t.LocatorId == locator.Id);
if (locatorempnum1 < locator.MaxNumber)
{
linearea = locator;
break;
}
}
}
if (linearea != null)
{
car.OptDt = DateTime.Now;
car.LocatorId = linearea.Id;
car.LocatorArea = linearea;
DBService.ModifyRealCarinfoRecord(car);
this.plcHelper.Write(this.ScanPoint.PlcSetting4, linearea.AreaNo);
///回写plc状态处理完成,plc会清理数据
this.plcHelper.Write(this.ScanPoint.PlcSetting5, 1);
logger.Log("node:" + this.ScanPoint.NodeNo + " plc:" + this.ScanPoint.PlcSetting4.PlcNo + " mu:" + linearea.AreaNo);
DBService.AddSystemLog(this.ScanPoint.NodeNo, car);
}
else
{
logger.Log("1006分流空车库 ,没有空车库满了");
}
}//小车移动中指定点位后,并且到位了
else if (Convert.ToInt32(carno) > 0 && Convert.ToInt32(carrun) == 1 && Convert.ToInt32(wcsend) == 1)
{
///回写plc状态,,plc会清理数据
this.plcHelper.Write(this.ScanPoint.PlcSetting4, 0);
///回写plc状态处理完成,plc会清理数据
this.plcHelper.Write(this.ScanPoint.PlcSetting5, 0);
}
}
}
catch (Exception ex)
{
logger.Error("Logic1002UpLocator异常: " + this.ScanPoint.NodeNo + " :" + ex.Message + ex.StackTrace);
}
Thread.Sleep(300);
}
}
}
}