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.
239 lines
11 KiB
C#
239 lines
11 KiB
C#
using CentralControl.BaseData;
|
|
using CentralControl.DBDAO;
|
|
using CommonFunc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using XGL.Thrift;
|
|
|
|
namespace CentralControl.App_Code
|
|
{
|
|
/// <summary>
|
|
/// 出库汇总分发点逻辑 空车 :1001 ,下件正确:1007, 调库或者非下件有料小车:1007
|
|
/// </summary>
|
|
public class Logic1005MiddleLine
|
|
{
|
|
/// <summary>
|
|
/// plc 正在读取
|
|
/// </summary>
|
|
bool IsPlcRead { get; set; }
|
|
|
|
Thread InputMaterialThread;
|
|
PlcHelper plcHelper;
|
|
string LineNo { get; set; }
|
|
NodeSetting ScanPoint { get; set; }
|
|
|
|
NodeSetting OutLocatorPoint { get; set; }
|
|
/// <summary>
|
|
/// 是否运行发车中
|
|
/// </summary>
|
|
bool IsRuning { get; set; }
|
|
|
|
|
|
public Logic1005MiddleLine(PlcHelper plc, string LineNo)
|
|
{
|
|
NodeSetting linenode1 = StaticData.NodeSettingList.FirstOrDefault(t => t.LineCatchArea != null && t.LineCatchArea.LineNo == LineNo && t.LineCatchArea.AreaType == 6);
|
|
this.OutLocatorPoint = StaticData.NodeSettingList.FirstOrDefault(t => t.LineCatchArea != null && t.NodeType == 5 && t.LineCatchArea.LineNo == LineNo && t.LineCatchArea.AreaType == 3);
|
|
|
|
if (linenode1 != null)
|
|
{
|
|
this.ScanPoint = linenode1;
|
|
}
|
|
else
|
|
{
|
|
Logger logger = new Logger();
|
|
logger.Log("创建线体,未找到扫描点位");
|
|
}
|
|
this.LineNo = LineNo;
|
|
this.plcHelper = plc;
|
|
///回写plc状态处理完成,plc会清理数据
|
|
|
|
//默认启动,清理plc的上位机写入点位值
|
|
this.plcHelper.Write(this.ScanPoint.PlcSetting4, 0);
|
|
this.plcHelper.Write(this.ScanPoint.PlcSetting5, 0);
|
|
|
|
}
|
|
|
|
/// <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 carno = this.plcHelper.Read(this.ScanPoint.PlcSetting1);
|
|
//小车是否到位
|
|
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 (Convert.ToInt32(carno) > 0 && Convert.ToInt32(wcsend) == 0 && Convert.ToInt32(wcsstate) == 0 && Convert.ToInt32(carstate) == 1 && Convert.ToInt32(carrun) == 0)
|
|
{
|
|
|
|
CarRealInfo car = StaticData.CarRealList.Where(t => t.CarNo == carno.ToString()).FirstOrDefault();
|
|
//调度逻辑 空车: 1001 ,下件正确: 1007, 调库或者非下件有料小车: 1007
|
|
if (car != null)
|
|
{
|
|
|
|
|
|
DBService.AddSystemLog(this.ScanPoint.NodeNo, car);
|
|
logger.Log("中枢节点 " + "源于点位:" + car.CurrNodeId + " 车号:" + car.CarNo + " 状态:" + car.IsProOutLocator);
|
|
|
|
//写入出库点位
|
|
NodePrecuss nextpro = null;
|
|
|
|
|
|
////空车: 1001
|
|
//ispro=0 ,offid=0 空车下件
|
|
// if (car.IsProOutLocator == 0 && car.OffMaterialId == 0)
|
|
if (car.MaterialNo.Trim() == "")
|
|
{
|
|
//1号库区 1005逻辑 ,T03为1 直接向 1001的前缓存区派车 ,否则就进入1002
|
|
if (this.LineNo == "1")
|
|
{
|
|
//object needState = this.plcHelper.Read(this.OutLocatorPoint.PlcSetting3);
|
|
//if (needState != null && Convert.ToInt32(needState) > 0)
|
|
//{
|
|
|
|
// nextpro = StaticData.NodeRelation.FirstOrDefault(t => t.PreNodeId == this.ScanPoint.Id && t.NodeValue == 1001);
|
|
|
|
//}
|
|
//else//就进入1002
|
|
//{
|
|
|
|
nextpro = StaticData.NodeRelation.FirstOrDefault(t => t.PreNodeId == this.ScanPoint.Id && t.NodeValue == 1002);
|
|
|
|
// }
|
|
}
|
|
else
|
|
{
|
|
//2号库区的合并线1009点
|
|
//正常模式 ,强制进入上件点,不能进入库区
|
|
|
|
nextpro = new NodePrecuss();
|
|
nextpro.NodeValue =1;
|
|
//if (StaticData.RuningModel == 0)
|
|
//{
|
|
// nextpro = StaticData.NodeRelation.FirstOrDefault(t => t.PreNodeId == this.ScanPoint.Id && t.NodeValue == 1003);
|
|
//}
|
|
//else
|
|
//{
|
|
// object needState = this.plcHelper.Read(this.OutLocatorPoint.PlcSetting3);
|
|
// if (needState != null && Convert.ToInt32(needState) > 0&&car.LocatorNodeId==0)
|
|
// {
|
|
|
|
// nextpro = StaticData.NodeRelation.FirstOrDefault(t => t.PreNodeId == this.ScanPoint.Id && t.NodeValue == 1003);
|
|
|
|
// }
|
|
// else//就进入1004
|
|
// {
|
|
|
|
// nextpro = StaticData.NodeRelation.FirstOrDefault(t => t.PreNodeId == this.ScanPoint.Id && t.NodeValue == 1004);
|
|
|
|
// }
|
|
//}
|
|
}
|
|
|
|
|
|
}
|
|
//手动设置拉到下件点的 ispro=1 ,offid=0 强制下件 offid>0 自动匹配下件
|
|
// else if (car.IsProOutLocator == 1 && car.OffMaterialId == 0)
|
|
else if (car.IsProOutLocator == 1)
|
|
{
|
|
if (this.LineNo == "1")
|
|
{
|
|
nextpro = StaticData.NodeRelation.FirstOrDefault(t => t.PreNodeId == this.ScanPoint.Id && t.NodeValue == 1007);
|
|
//car.MaterialNo = "";
|
|
//car.MaterialBarNo = "";
|
|
//car.IsProOutLocator = 0;
|
|
}
|
|
|
|
}// 1号库区避让的小车ispro=2 ,offid=0 避让
|
|
//else if (car.IsProOutLocator == 2 && car.OffMaterialId == 0)
|
|
else
|
|
{
|
|
|
|
logger.Log(" 物料编码:"+car.MaterialNo+" 小车状态: "+car.IsProOutLocator);
|
|
if (this.LineNo == "1")
|
|
{
|
|
nextpro = StaticData.NodeRelation.FirstOrDefault(t => t.PreNodeId == this.ScanPoint.Id && t.NodeValue == 1002);
|
|
}
|
|
else
|
|
{
|
|
nextpro = StaticData.NodeRelation.FirstOrDefault(t => t.PreNodeId == this.ScanPoint.Id && t.NodeValue == 1004);
|
|
}
|
|
}
|
|
//car.LocatorNodeId = car.LocatorId;
|
|
//car.ProLocatorArea = car.LocatorArea;
|
|
car.CurrNodeId = this.ScanPoint.Id;
|
|
car.CurrNodeSetting = this.ScanPoint;
|
|
car.LocatorArea = null;
|
|
car.LocatorId = 0;
|
|
//car.IsProOutLocator = 0;
|
|
car.OptDt = DateTime.Now;
|
|
car.IsOver = 0;
|
|
DBService.ModifyRealCarinfoRecord(car);
|
|
//写入出库点位
|
|
this.plcHelper.Write(this.ScanPoint.PlcSetting4, nextpro.NodeValue);
|
|
///回写plc状态处理完成,plc会清理数据
|
|
this.plcHelper.Write(this.ScanPoint.PlcSetting5, 1);
|
|
// IsPlcRead = true;
|
|
DBService.AddSystemLog(this.ScanPoint.NodeNo, car);
|
|
logger.Log("node:" + this.ScanPoint.NodeNo + " plc:" + this.ScanPoint.PlcSetting4.PlcNo + "" + nextpro.NodeValue);
|
|
}
|
|
|
|
}//小车移动中指定点位后,并且到位了
|
|
else if (Convert.ToInt32(carno) > 0 && Convert.ToInt32(carrun) == 1 && Convert.ToInt32(wcsend) == 1)
|
|
{
|
|
// IsPlcRead = false;
|
|
//CarRealInfo ocar = StaticData.CarRealList.Where(t => t.CarNo == carno.ToString()).FirstOrDefault();
|
|
//if (ocar != null)
|
|
//{
|
|
// car.IsOver = 1;
|
|
logger.Log(" 小车离开了 [" + this.LineNo + "]号上件点");
|
|
///回写plc状态,,plc会清理数据
|
|
this.plcHelper.Write(this.ScanPoint.PlcSetting4, 0);
|
|
///回写plc状态处理完成,plc会清理数据
|
|
this.plcHelper.Write(this.ScanPoint.PlcSetting5, 0);
|
|
|
|
// }
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error("Logic1005MiddleLine异常: " + this.ScanPoint.NodeNo + " :" + ex.Message + ex.StackTrace);
|
|
}
|
|
Thread.Sleep(300);
|
|
}
|
|
}
|
|
}
|
|
}
|