using iWareCC.Common.Helper;
|
using iWareCC.SrmService;
|
using iWareCommon.Common.Globle;
|
using iWareCommon.Utils;
|
using iWareModel;
|
using iWareSql;
|
using iWareSql.DataAccess;
|
using iWareSql.DBModel;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using XiGang.Core.Model;
|
|
namespace iWareCC
|
{
|
/// <summary>
|
/// 四个入库口扫描检测线程
|
/// </summary>
|
public static class LineInSacnResult
|
{
|
/// <summary>
|
/// 四个入库口扫描检测线程
|
/// </summary>
|
public static void HandlerLineInSacnResult(object int_device)
|
{
|
while (true)
|
{
|
var errMsg = "";
|
var showErrMsg = "";
|
try
|
{
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = "";
|
//if (SystemValue.isAllowRuning_LineInScan && SystemValue.isStartedModel)
|
if (true)//注意:不需要启动模式
|
{
|
SingleDo((int)EDevice.一号堆垛机, out errMsg);
|
showErrMsg += errMsg + SysGloble.SPLIT_STR;
|
|
SingleDo((int)EDevice.二号堆垛机, out errMsg);
|
showErrMsg += errMsg + SysGloble.SPLIT_STR;
|
|
SingleDo((int)EDevice.三号堆垛机, out errMsg);
|
showErrMsg += errMsg + SysGloble.SPLIT_STR;
|
|
SingleDo((int)EDevice.四号堆垛机, out errMsg);
|
showErrMsg += errMsg + SysGloble.SPLIT_STR;
|
}
|
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = showErrMsg;
|
}
|
catch (Exception ex)
|
{
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound += "HandlerLineInSacnResult 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
|
Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.DataProcess_RobotBuffer_FinishTaskForOutbound, "HandlerLineInSacnResult 出现异常:" + ex.Message, ex);
|
}
|
Thread.Sleep(1000);//休眠2秒
|
}
|
}
|
|
private static void SingleDo(int int_device, out string errMsg)
|
{
|
errMsg = "";
|
EDevice device = (EDevice)Enum.Parse(typeof(EDevice), int_device.ToString());
|
var stationCode = "";
|
var scanCode = GetScanValueBySrmStationCode(device, ref stationCode);
|
|
var srm = FormCC.srmViewDict[(int)device];
|
if (srm.R_PickReqForInStore)
|
{//必须堆垛机请求了才可以
|
//只有当堆垛机有任务执行时,并且是入库任务的时候才判断
|
var realSrmSourcePlace = int_device + "-" + srm.SrmSourcePlace;
|
|
|
if (string.IsNullOrEmpty(scanCode))
|
{
|
errMsg = "设备:" + device.ToString() + ",输送线扫描的值为空";
|
return;
|
}
|
|
if (srm.R_TaskNo > 0 && (srm.R_State == (int)ESrmState.取货中 || srm.R_State == (int)ESrmState.取货定位中)
|
&& SysGloble.Dict_SpecialPlace_IN.ContainsKey(realSrmSourcePlace))
|
{
|
if (srm.R_TaskNo > 0 && srm.R_TaskNo <= 100)
|
{//手动
|
MyExtendHelper.WriteScanValidateACK(false, "手动任务", stationCode, srm.R_TaskNo, true, "", scanCode);
|
errMsg = "设备:" + device.ToString() + ",判断是手动任务,验证通过";
|
return;
|
}
|
else
|
{
|
using (DbModel context = new DbModel())
|
{
|
//拿到堆垛机要入库时,应该正确的托盘号
|
var queryState = (int)DeviceTaskStatusEnum.已下发;
|
var queryTaskNo = srm.R_TaskNo.ToString();
|
var queryEDeviceType = (int)EDeviceType.堆垛机;
|
var task = context.Task_Part.Where(x => x.DeviceType == queryEDeviceType && x.PlcTaskId == queryTaskNo && x.TaskState == queryState).FirstOrDefault();
|
if (task == null)
|
{
|
errMsg = "设备:" + device.ToString() + ",获取任务为NULL,PLC任务号:" + queryTaskNo;
|
return;
|
/*
|
//表示是手动进去的?
|
WriteScanFailACK("我认为是手动任务", stationCode, srm.R_TaskNo, true, "", scanCode);
|
errMsg = "设备:" + device.ToString() + ",判断是手动任务(系统),验证通过";
|
return;
|
//*/
|
}
|
else
|
{
|
var sysSalverCode = task.SalverCode;
|
//如果是 托盘入库任务,就不校验
|
if (task.MaterialType == (int)MaterialTypeEnum.托盘)
|
{
|
MyExtendHelper.WriteScanValidateACK(false, "自动任务,验证托盘", stationCode, Convert.ToInt32(task.PlcTaskId), true, sysSalverCode, scanCode);
|
errMsg = "设备:" + device.ToString() + ",判断是自动任务,验证通过";
|
return;
|
}
|
else
|
{
|
if (scanCode != sysSalverCode)
|
{//校验不通过
|
//首先要判断 OK信号是否是true,如果是true,就不需要写验证不通过了,否则会影响wcs手动入库口扫码强制验证通过的节奏
|
bool isSMQZYZTG = false;
|
if (ValidateScanSuccessACK(stationCode, ref isSMQZYZTG) == false)
|
{
|
//注意:这里停留1秒,继续判断下
|
Thread.Sleep(2000);
|
if (ValidateScanSuccessACK(stationCode, ref isSMQZYZTG) == false)
|
{
|
MyExtendHelper.WriteScanValidateACK(false, "自动任务,验证发动机", stationCode, Convert.ToInt32(task.PlcTaskId), false, sysSalverCode, scanCode);
|
errMsg = "设备:" + device.ToString() + ",判断是自动任务,验证不通过,系统托盘号:" + sysSalverCode + ",扫描值:" + scanCode + ",任务号:" + task.PlcTaskId;
|
return;
|
}
|
else
|
{
|
if (isSMQZYZTG)
|
{//强制验证通过
|
MyExtendHelper.WriteScanValidateACK(false, "[强制验证通过]自动任务,验证发动机", stationCode, Convert.ToInt32(task.PlcTaskId), true, sysSalverCode, scanCode);
|
}
|
}
|
}
|
else
|
{
|
errMsg = "设备:" + device.ToString() + ",判断是自动任务,本来是验证不通过,但是由于人工手动入库口扫码强制验证通过,所以就不推送验证不通过信号了,系统托盘号:" + sysSalverCode + ",扫描值:" + scanCode + ",任务号:" + task.PlcTaskId;
|
if (isSMQZYZTG)
|
{//强制验证通过
|
MyExtendHelper.WriteScanValidateACK(false, "[强制验证通过]自动任务,验证发动机", stationCode, Convert.ToInt32(task.PlcTaskId), true, sysSalverCode, scanCode);
|
}
|
return;
|
}
|
}
|
else
|
{//校验通过
|
MyExtendHelper.WriteScanValidateACK(false, "自动任务,验证发动机", stationCode, Convert.ToInt32(task.PlcTaskId), true, sysSalverCode, scanCode);
|
errMsg = "设备:" + device.ToString() + ",判断是自动任务,验证通过";
|
return;
|
}
|
}
|
}
|
}
|
}
|
|
}
|
else
|
{
|
errMsg = "设备:" + device.ToString() + "不满足条件,任务号:" + srm.R_TaskNo + ",状态:" + srm.StateName + ",不是取货中或取货定位中";
|
return;
|
}
|
}
|
else
|
{
|
MyExtendHelper.SetSrm_IN_SMQZYZTG(device, false);
|
ResetACK(stationCode, srm, device);
|
|
errMsg = "设备:" + device.ToString() + ",堆垛机没有请求取货";
|
return;
|
}
|
}
|
|
|
/// <summary>
|
/// 验证OK信号的真假
|
/// </summary>
|
/// <param name="stationCode"></param>
|
/// <returns></returns>
|
private static bool ValidateScanSuccessACK(string stationCode, ref bool isSMQZYZTG)
|
{
|
var isOk = false;
|
switch (stationCode)
|
{
|
case "1002":
|
if (FormCC.rgvView.W_1002_ScanSuccessACK || FormCC.Srm1_IN_SMQZYZTG)
|
{
|
isOk = true;
|
}
|
if (FormCC.Srm1_IN_SMQZYZTG) isSMQZYZTG = true;
|
break;
|
case "1004":
|
if (FormCC.rgvView.W_1004_ScanSuccessACK || FormCC.Srm2_IN_SMQZYZTG)
|
{
|
isOk = true;
|
}
|
if (FormCC.Srm2_IN_SMQZYZTG) isSMQZYZTG = true;
|
break;
|
case "1006":
|
if (FormCC.rgvView.W_1006_ScanSuccessACK || FormCC.Srm3_IN_SMQZYZTG)
|
{
|
isOk = true;
|
}
|
if (FormCC.Srm3_IN_SMQZYZTG) isSMQZYZTG = true;
|
break;
|
case "1007":
|
if (FormCC.rgvView.W_1007_ScanSuccessACK || FormCC.Srm4_IN_SMQZYZTG)
|
{
|
isOk = true;
|
}
|
if (FormCC.Srm4_IN_SMQZYZTG) isSMQZYZTG = true;
|
break;
|
}
|
return isOk;
|
}
|
|
private static void ResetACK(string stationCode, SrmView srm, EDevice device)
|
{
|
var isNeedRest = false;
|
switch (stationCode)
|
{
|
case "1002":
|
if (FormCC.rgvView.W_1002_ScanFailACK || FormCC.rgvView.W_1002_ScanSuccessACK)
|
{
|
isNeedRest = true;
|
}
|
break;
|
case "1004":
|
if (FormCC.rgvView.W_1004_ScanFailACK || FormCC.rgvView.W_1004_ScanSuccessACK)
|
{
|
isNeedRest = true;
|
}
|
break;
|
case "1006":
|
if (FormCC.rgvView.W_1006_ScanFailACK || FormCC.rgvView.W_1006_ScanSuccessACK)
|
{
|
isNeedRest = true;
|
}
|
break;
|
case "1007":
|
if (FormCC.rgvView.W_1007_ScanFailACK || FormCC.rgvView.W_1007_ScanSuccessACK)
|
{
|
isNeedRest = true;
|
}
|
break;
|
}
|
if (isNeedRest)
|
{
|
//重置输送线的信号
|
MyExtendHelper.WriteScanValidateACK(true, "重置任务", stationCode, srm.R_TaskNo, false, "", "");
|
}
|
}
|
|
|
/// <summary>
|
/// 根据堆垛机的入库口获取 扫描值
|
/// </summary>
|
/// <param name="srmStationCode"></param>
|
/// <returns></returns>
|
private static string GetScanValueBySrmStationCode(EDevice device, ref string stationCode)
|
{
|
if (FormCC.rgvView == null)
|
{
|
return "";
|
}
|
|
if (device == EDevice.一号堆垛机)
|
{
|
stationCode = "1002";
|
return FormCC.rgvView.R_1002_Scan;
|
}
|
else if (device == EDevice.二号堆垛机)
|
{
|
stationCode = "1004";
|
return FormCC.rgvView.R_1004_Scan;
|
}
|
else if (device == EDevice.三号堆垛机)
|
{
|
stationCode = "1006";
|
return FormCC.rgvView.R_1006_Scan;
|
}
|
else if (device == EDevice.四号堆垛机)
|
{
|
stationCode = "1007";
|
return FormCC.rgvView.R_1007_Scan;
|
}
|
return "";
|
}
|
|
|
|
|
}
|
}
|