|
|
using Mesnac.Compressor.Data;
|
|
|
using Mesnac.Compressor.Entity;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
|
|
|
namespace Mesnac.Compressor.Station
|
|
|
{
|
|
|
public class LastStation : NormarlStation, IStation
|
|
|
{
|
|
|
|
|
|
public bool PrepareWork(StationInfo station)
|
|
|
{
|
|
|
//判断当前工位MES开关是否打开
|
|
|
bool iflag = IsOpen(station.stationID);
|
|
|
if (iflag)
|
|
|
{
|
|
|
WorkTray tray = new WorkTray();
|
|
|
//如果托盘是空的,直接放行,这里可能有个问题,PLC已经判断不是空托盘了,如果是空托盘肯定是系统数据有问题
|
|
|
if (this.TrayIsNull(station, out tray))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "检测到托盘未绑定");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.OK);
|
|
|
return true;
|
|
|
}
|
|
|
//判断当前工位是否已经合格
|
|
|
//if (this.CurrentStationInfo(station, tray.RfidNum))
|
|
|
//{
|
|
|
// ICSharpCode.Core.LoggingService.Debug(station.StationCode + "检测当前工位已合格");
|
|
|
// this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NG);
|
|
|
// return false;
|
|
|
//}
|
|
|
|
|
|
bool ReSatrtWork = IsReStartWork(station);
|
|
|
//如果是重投并且到了重做工位(此处并不是重投口,而是对应拆解台选择的重做工位)
|
|
|
if (ReSatrtWork)
|
|
|
{
|
|
|
//已经重投到了本工位,可以工作
|
|
|
//获取重投的工位号
|
|
|
string CurrentStationID = GetCurrentStationByRFID(tray.RfidNum);
|
|
|
if (int.Parse(station.stationID) < int.Parse(CurrentStationID))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "检测到未到重做工位");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
return false;
|
|
|
}
|
|
|
else if (int.Parse(station.stationID) == int.Parse(CurrentStationID))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "检测到已到重做工位");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.OK);
|
|
|
return false;
|
|
|
}
|
|
|
else if (int.Parse(station.stationID) > int.Parse(CurrentStationID))
|
|
|
{
|
|
|
//这里需要判断一下上工位开关是否打开
|
|
|
string preStationID = GetFirstStationIDByStationID(station.stationID);
|
|
|
bool iPreflag = IsOpen(preStationID);
|
|
|
if (iPreflag)
|
|
|
{
|
|
|
if (!this.PreStationInfo(station, tray.RfidNum))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "检测无上工位信息");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.PreNoWork);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//这里需要判断一下上工位开关是否打开
|
|
|
string preStationID = GetFirstStationIDByStationID(station.stationID);
|
|
|
if (!string.IsNullOrEmpty(preStationID))
|
|
|
{
|
|
|
bool iPreflag = IsOpen(preStationID);
|
|
|
if (iPreflag)
|
|
|
{
|
|
|
|
|
|
//判断上一工位是否有工作信息
|
|
|
if (!this.PreStationInfo(station, tray.RfidNum))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "检测无上工位信息");
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.PreNoWork);
|
|
|
return false;
|
|
|
}
|
|
|
//如果不是空托盘,判断当前是否合格f
|
|
|
if (tray.OKNG != 1)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "检测上工位信息不合格");
|
|
|
//这里要判断当前工位是否是NG拿取工位=====
|
|
|
if (station.NGTakeStation)
|
|
|
{
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.TakeNG);
|
|
|
//托盘状态清空(这里加了当前工位重做逻辑,不需要清空)
|
|
|
//UpdateTray(tray.RfidNum, tray.RfidNum, "", "", 0);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.FangXing);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.OK);
|
|
|
return true;
|
|
|
}
|
|
|
public new bool HandleData(StationInfo station)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//保存数据
|
|
|
base.SaveStationData(station,StationType.LastStation);
|
|
|
UpdateTrace(station);
|
|
|
|
|
|
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error(e.ToString());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
{
|
|
|
//这里要加一个OK放行
|
|
|
FinishSavePLCWork(station);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public void UpdateTrace(StationInfo station)
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
try
|
|
|
{
|
|
|
DbHandler db = new DbHandler();
|
|
|
db.dbHelper.ClearParameter();
|
|
|
db.dbHelper.CommandType = CommandType.Text;
|
|
|
db.dbHelper.CommandText = "";
|
|
|
|
|
|
string sql = "EXEC SP_Pro_SaveProductionInfo @RFID,@productid";
|
|
|
db.dbHelper.AddParameter("@RFID", station.Data.RFIDNo);
|
|
|
db.dbHelper.AddParameter("@productid", station.Data.machineID);
|
|
|
db.dbHelper.CommandText = sql;
|
|
|
db.dbHelper.ExecuteNonQuery();
|
|
|
ICSharpCode.Core.LoggingService.Debug("结束工位更新条码信息"+ sql+"RFID"+ station.Data.RFIDNo+ "productid"+ station.Data.machineID);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取条码语句错误:" + sb.ToString() + "/r/n" + e.ToString());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|