|
|
using Mesnac.Compressor.Data;
|
|
|
using Mesnac.Compressor.Entity;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using static System.Collections.Specialized.BitVector32;
|
|
|
|
|
|
namespace Mesnac.Compressor.Station
|
|
|
{
|
|
|
public class NormarlStation : Common, IStation
|
|
|
{
|
|
|
|
|
|
public bool PrepareWork(StationInfo station)
|
|
|
{
|
|
|
//防止PLC没给直线条码,导致程序崩溃
|
|
|
if (station.Data.subLineList == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
|
|
|
return false;
|
|
|
}
|
|
|
if (station.stationID == "4")
|
|
|
{
|
|
|
//锁螺丝机
|
|
|
if (string.IsNullOrEmpty(station.Data.subLineList[2].barcode) || station.Data.subLineList[2].barcode.Equals("ERROR"))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
//if (station.stationID == "9")
|
|
|
//{
|
|
|
// //锁螺丝机
|
|
|
// if (string.IsNullOrEmpty(station.Data.subLineList[1].barcode) || station.Data.subLineList[1].barcode.Equals("ERROR"))
|
|
|
// {
|
|
|
// ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
|
|
|
// this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
|
|
|
// return false;
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// ICSharpCode.Core.LoggingService.Debug("工位:" + station.StationCode + ",RFID:" + station.Data.RFIDNo + ",条码号:" + station.Data.subLineList[1].barcode);
|
|
|
// }
|
|
|
//}
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + ",打印托盘号:" + station.Data.RFIDNo);
|
|
|
#region 测试暂时去掉
|
|
|
bool iflag = IsOpen(station.stationID);
|
|
|
if (iflag)
|
|
|
{
|
|
|
//查询是否NG物料放行
|
|
|
string semibarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
//根据托盘号判断上工位是否为NG,如果NG则放行
|
|
|
bool StationState = GetStateStationByRFID(station.Data.RFIDNo);
|
|
|
if (!StationState)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error(station.StationCode + "检测上工位信息NG放行");
|
|
|
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.TakeNG);
|
|
|
Thread.Sleep(1000);
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
bool ReSatrtWork = JudgeStationReWork(station);
|
|
|
|
|
|
//如果是重投并且到了重做工位(此处并不是重投口,而是对应拆解台选择的重做工位)
|
|
|
if (ReSatrtWork)
|
|
|
{
|
|
|
WritePLC_Result(station);
|
|
|
return false;
|
|
|
}
|
|
|
//不是重投
|
|
|
else
|
|
|
{
|
|
|
string preStationID = GetFirstStationIDByStationID(station.stationID);
|
|
|
if (!string.IsNullOrEmpty(preStationID))
|
|
|
{
|
|
|
bool iPreflag = IsOpen(preStationID);
|
|
|
if (iPreflag)
|
|
|
{
|
|
|
//判断上工位是否NG,根据托盘号查询A码
|
|
|
string barcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
if (!string.IsNullOrEmpty(barcode))
|
|
|
{
|
|
|
if (station.stationID == "4")
|
|
|
{
|
|
|
string JPCode = SelectJingPanCodeBySemiBarcodeA(barcode);
|
|
|
//根据静盘码查询螺丝机工位信息
|
|
|
string LastWorkInfo = LastWorkProductionInfo(JPCode, station.PreTableName, "ScanBarcode");
|
|
|
if (!string.IsNullOrEmpty(LastWorkInfo))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.DebugFormatted("查询上工位工作信息:{0}", LastWorkInfo);
|
|
|
if (LastWorkInfo != "1")
|
|
|
{
|
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error(station.StationCode + "检测上工位信息不合格,NG物料拿取");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.TakeNG);
|
|
|
Thread.Sleep(1000);
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error(station.StationCode + "检测上工位信息为空,上工序未完成");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.PreNoWork);
|
|
|
Thread.Sleep(1000);
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//查询托盘当前的工位
|
|
|
if (!this.PreStationInfo(station, station.Data.RFIDNo))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error(station.StationCode + "检测无上工位信息");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.PreNoWork);
|
|
|
Thread.Sleep(1000);
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
//查询上一工位是否NG
|
|
|
//根据托盘号判断上工位是否为NG,如果NG则放行
|
|
|
bool PreStationState = GetStateStationByRFID(station.Data.RFIDNo);
|
|
|
if (!PreStationState)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error(station.StationCode + "检测上工位信息不合格");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.PreNoWork);
|
|
|
Thread.Sleep(1000);
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.OK);
|
|
|
//这里加一个物料是否匹配=======//还要加判断,当前工位是否需要判断
|
|
|
return true;
|
|
|
}
|
|
|
public bool JudgeStationReWork(StationInfo station)
|
|
|
{
|
|
|
bool bFlag = false;
|
|
|
try
|
|
|
{
|
|
|
if (station.stationID == "4")
|
|
|
{
|
|
|
//string productcode = "";
|
|
|
//productcode = station.Data.subLineList[2].barcode;
|
|
|
|
|
|
//根据条码查询是否重投
|
|
|
//bFlag = IsReStartWorkByBarCode(station, productcode);
|
|
|
//根据条码查询是否有历史记录
|
|
|
//string IsReWork = GetReStartInfo("SemiBarcode", station.Data.subLineList[2].barcode, station.TableName, "ScanBarcode");
|
|
|
if (station.Data.Restart)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.DebugFormatted("{0}查询{1}托盘的产品为重投,条码:{2}", station.StationName, station.Data.RFIDNo, station.Data.subLineList[2].barcode);
|
|
|
bFlag = true;
|
|
|
}
|
|
|
}
|
|
|
else if (station.stationID == "5")
|
|
|
{
|
|
|
//重投到当前工位
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "收到PLC传递的托盘号:" + station.Data.RFIDNo);
|
|
|
string isrestart = ReStartWork(station);
|
|
|
if (!string.IsNullOrEmpty(isrestart))
|
|
|
{
|
|
|
if (isrestart == "2" || isrestart == "3")
|
|
|
{
|
|
|
bFlag = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if (station.stationID == "6")
|
|
|
{
|
|
|
//重投到当前工位
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "收到PLC传递的托盘号:" + station.Data.RFIDNo);
|
|
|
//bFlag = IsReStartWork(station);
|
|
|
string isrestart = ReStartWork(station);
|
|
|
if (!string.IsNullOrEmpty(isrestart))
|
|
|
{
|
|
|
if (isrestart == "3")
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "查询[" + station.Data.RFIDNo + "]托盘的产品为重投");
|
|
|
bFlag = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else if (station.stationID == "7")
|
|
|
{
|
|
|
//重投到当前工位
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "收到PLC传递的托盘号:" + station.Data.RFIDNo);
|
|
|
//bFlag = IsReStartWork(station);
|
|
|
string isrestart = ReStartWork(station);
|
|
|
if (!string.IsNullOrEmpty(isrestart))
|
|
|
{
|
|
|
if (isrestart == "3")
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "查询[" + station.Data.RFIDNo + "]托盘的产品为重投");
|
|
|
bFlag = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//else if (station.stationID == "9")
|
|
|
//{
|
|
|
// ICSharpCode.Core.LoggingService.DebugFormatted("{0}收到PLC传递的托盘号:{1},条码:{2}", station.StationCode, station.Data.RFIDNo, station.Data.subLineList[1].barcode);
|
|
|
// //bool ReSatrtWork = IsReStartWorkByBarCode(station, station.Data.subLineList[1].barcode);
|
|
|
// //bFlag = IsReStartWork(station);
|
|
|
// string IsReWork = GetReStartInfo("SemiBarcode", station.Data.subLineList[1].barcode, station.TableName, "ScanBarcode");
|
|
|
// if (!string.IsNullOrEmpty(IsReWork))
|
|
|
// {
|
|
|
// ICSharpCode.Core.LoggingService.DebugFormatted("{0}查询{1}托盘的产品为重投,条码:{2}", station.StationName, station.Data.RFIDNo, station.Data.subLineList[1].barcode);
|
|
|
// bFlag = true;
|
|
|
// }
|
|
|
//}
|
|
|
//else if (station.stationID == "10")
|
|
|
//{
|
|
|
// //重投到当前工位
|
|
|
// ICSharpCode.Core.LoggingService.Debug(station.StationCode + "收到PLC传递的托盘号:" + station.Data.RFIDNo);
|
|
|
// bFlag = IsReStartWork(station);
|
|
|
//}
|
|
|
return bFlag;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
public bool WritePLC_Result(StationInfo station)
|
|
|
{
|
|
|
bool bIsReStartWork = false;
|
|
|
string stationID = "";
|
|
|
string ISdis = "";
|
|
|
try
|
|
|
{
|
|
|
if (station.stationID == "4")
|
|
|
{
|
|
|
//根据条码查询原来的组件绑定到新版上
|
|
|
string Abarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
|
|
|
InsertBarcodeRelationShip(Abarcode, station.Data.subLineList[2].barcode, "", 2);
|
|
|
if (station.Data.QGCT)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug("前盖重投...");
|
|
|
stationID = "5";
|
|
|
ISdis = "2";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug("曲轴组件重投...");
|
|
|
stationID = "8";
|
|
|
ISdis = "3";
|
|
|
}
|
|
|
//更新工位信息并放行
|
|
|
UpdateTray(stationID, station.Data.RFIDNo);
|
|
|
|
|
|
//更新T_SY_TraceState表工位状态
|
|
|
bool bflag = UpdateTraceReStartStation(ISdis, "4", stationID, "",Abarcode);
|
|
|
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return bIsReStartWork;
|
|
|
}
|
|
|
else if (station.stationID == "5")
|
|
|
{
|
|
|
string Abarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
|
|
|
//更新工位信息并放行
|
|
|
UpdateTray(station.stationID, station.Data.RFIDNo);
|
|
|
//更新当前工位
|
|
|
UpdateTraceReStartStation(station.stationID, Abarcode);
|
|
|
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return bIsReStartWork;
|
|
|
}
|
|
|
else if (station.stationID == "6")
|
|
|
{
|
|
|
string Abarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
|
|
|
//更新工位信息并放行
|
|
|
UpdateTray(station.stationID, station.Data.RFIDNo);
|
|
|
//更新当前工位
|
|
|
UpdateTraceReStartStation(station.stationID, Abarcode);
|
|
|
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
else if (station.stationID == "7")
|
|
|
{
|
|
|
string Abarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
|
|
|
//更新工位信息并放行
|
|
|
UpdateTray(station.stationID, station.Data.RFIDNo);
|
|
|
//更新当前工位
|
|
|
UpdateTraceReStartStation(station.stationID, Abarcode);
|
|
|
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
return bIsReStartWork;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return bIsReStartWork;
|
|
|
}
|
|
|
}
|
|
|
public bool HandleData(StationInfo station)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//暂时不用
|
|
|
//if (!CheckNewData(station, ""))
|
|
|
//{
|
|
|
// ICSharpCode.Core.LoggingService.Debug("工位:" + station.StationCode + "的RFID:" + station.Data.RFIDNo + "数据已上传。条码号:" + station.Data.ProductBarcode + " 任务号:" + station.Data.MaskID.ToString());
|
|
|
// return false;
|
|
|
//}
|
|
|
//保存数据
|
|
|
if (station.stationID == "4")
|
|
|
{
|
|
|
station.Data.ProductBarcode = station.Data.subLineList[2].barcode;
|
|
|
}
|
|
|
//曲轴组件装配
|
|
|
else if (station.stationID == "6")
|
|
|
{
|
|
|
//ok放行
|
|
|
if (station.Data.DP_OpenFlag)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.ErrorFormatted("{0}工位OK物料放行!", station.StationName);
|
|
|
//string semibarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
////收到PLC OK放行信号,系统强制托盘信息为合格
|
|
|
//UpdateTray(station.Data.RFIDNo, semibarcode, "6", 1);
|
|
|
//this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
//return false;
|
|
|
}
|
|
|
//NG放行
|
|
|
if (station.Data.ReWork)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.ErrorFormatted("{0}工位NG物料放行!" , station.StationName);
|
|
|
//标记NG物料放行
|
|
|
string semibarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
//string mainBarcode = GetTrayBarcode(station.Data.RFIDNo);
|
|
|
UpdateTray(station.Data.RFIDNo, semibarcode,"6",3);
|
|
|
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
else if (station.stationID == "7")
|
|
|
{
|
|
|
if (station.Data.ReWork)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.ErrorFormatted("{0}工位NG物料放行!", station.StationName);
|
|
|
//标记NG物料放行
|
|
|
string semibarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
//string mainBarcode = GetTrayBarcode(station.Data.RFIDNo);
|
|
|
UpdateTray(station.Data.RFIDNo, semibarcode, "7", 3);
|
|
|
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
else if (station.stationID == "9")
|
|
|
{
|
|
|
station.Data.ProductBarcode = station.Data.subLineList[1].barcode;
|
|
|
//查询是否重投
|
|
|
ICSharpCode.Core.LoggingService.DebugFormatted("{0}收到PLC传递的托盘号:{1},条码:{2}", station.StationCode, station.Data.RFIDNo, station.Data.subLineList[1].barcode);
|
|
|
//string IsReWork = GetReStartInfo("ScanBarcode", station.Data.subLineList[1].barcode, station.TableName, "ScanBarcode");
|
|
|
if (station.Data.Restart)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.DebugFormatted("{0}查询{1}托盘的产品为重投,条码:{2}", station.StationName, station.Data.RFIDNo, station.Data.subLineList[1].barcode);
|
|
|
|
|
|
string Abarcode = GetTraySemiBarcode(station.Data.RFIDNo);
|
|
|
//判断是否存在物料关系,如果存在则更新,反之插入数据
|
|
|
|
|
|
|
|
|
InsertBarcodeRelationShip(Abarcode, station.Data.subLineList[1].barcode, "", 1);
|
|
|
|
|
|
//更新工位信息并放行
|
|
|
UpdateTray(station.stationID, station.Data.RFIDNo);
|
|
|
|
|
|
//更新T_SY_TraceState表工位状态
|
|
|
bool bflag = UpdateTraceReStartStation("4","9", "10", station.Data.subLineList[1].barcode, Abarcode);
|
|
|
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
//肯定是新板新组件
|
|
|
//根据条码查询原来的组件绑定到新版上
|
|
|
}
|
|
|
base.SaveStationData(station,StationType.NormarlStation);
|
|
|
FinishSavePLCWork(station);
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Info(e.ToString());
|
|
|
//这里要加一个OK放行
|
|
|
FinishSavePLCWork(station);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|