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.

347 lines
18 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 NoRFIDStation : Common, IStation
{
/// <summary>
/// 无RFID托盘的工位直接将产品条码号放到数据表中没有系统条码之分这样统计数据只能按最后一次来统计
/// 对于重投次数也不太好统计
/// </summary>
/// <param name="station"></param>
/// <returns></returns>
public bool PrepareWork(StationInfo station)
{
//先判断后台开关是否打开在进行逻辑验证
bool iflag = IsOpen(station.stationID);
if (iflag)
{
//主线产品码未扫描到条码下发PLC报警
//大转盘壳体条码
if (station.stationID == "1" || station.stationID == "9"|| station.stationID == "11" || station.stationID == "12"|| station.stationID == "15" || station.stationID == "16")
{
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.DebugFormatted("{0}收到PLC条码:{1}", station.StationCode, station.Data.subLineList[1].barcode);
}
}
else if (station.stationID == "8")
{
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;
}
else
{
ICSharpCode.Core.LoggingService.DebugFormatted("{0}收到PLC条码:{1}", station.StationCode, station.Data.subLineList[2].barcode);
}
}
else if(station.stationID == "17" || station.stationID == "18")
{
if (string.IsNullOrEmpty(station.Data.ProductBarcode) || station.Data.ProductBarcode.Equals("ERROR"))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
return false;
}
else
{
ICSharpCode.Core.LoggingService.DebugFormatted("{0}收到PLC条码:{1}", station.StationCode, station.Data.ProductBarcode);
}
}
else if (station.stationID == "19")
{
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.DebugFormatted("{0}收到PLC条码:{1}", station.StationCode, station.Data.subLineList[1].barcode);
string ZhuYou = GetZhuYouByKTBarCode(station.Data.subLineList[1].barcode);
if (string.IsNullOrEmpty(ZhuYou))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未查询到注油量");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.TakeNG);
return false;
}
ICSharpCode.Core.LoggingService.DebugFormatted("查询{0}裸机重量:{1}", station.Data.subLineList[1].barcode, ZhuYou);
float cc = float.Parse(ZhuYou);
//ICSharpCode.Core.LoggingService.DebugFormatted("查询{0}裸机重量-120后:{1}", station.Data.subLineList[1].barcode, cc);
object[] ZhuYouLiang = floatToObject(cc);
//向PLC写入裸机重量
bool bflag = WritePLCByByte(station, 20, ZhuYouLiang);
if (bflag)
{
ICSharpCode.Core.LoggingService.DebugFormatted("写入{0}裸机重量:{1}", station.Data.subLineList[1].barcode, ZhuYou);
}
}
}
//else if (station.stationID == "8")
//{
// if (string.IsNullOrEmpty(station.Data.ProductBarcode) || station.Data.ProductBarcode.Equals("ERROR"))
// {
// ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
// this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
// return false;
// }
//}
//前盖条码
//else if (station.stationID == "5")
//{
// 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;
// }
//}
//静盘条码
else if (station.stationID == "3")
{
if (string.IsNullOrEmpty(station.Data.subLineList[4].barcode) || station.Data.subLineList[4].barcode.Equals("ERROR"))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
return false;
}
}
//动盘条码
//else if (station.stationID == "12")
//{
// if (!station.Data.DP_OpenFlag)
// {
// if (string.IsNullOrEmpty(station.Data.subLineList[3].barcode) || station.Data.subLineList[3].barcode.Equals("ERROR"))
// {
// ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
// this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
// return false;
// }
// }
//}
//后盖条码
//else if (station.stationID == "15")
//{
// if (string.IsNullOrEmpty(station.Data.subLineList[5].barcode) || station.Data.subLineList[5].barcode.Equals("ERROR"))
// {
// ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
// this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
// return false;
// }
//}
//判断上一工位开关是否打开
string preStationID = GetFirstStationIDByStationID(station.stationID);
if (!string.IsNullOrEmpty(preStationID))
{
bool iPreflag = IsOpen(preStationID);
if (iPreflag)
{
string LastWorkInfo = "";
if (station.stationID == "3")
{
//通过静盘条码查询A码
string Sem = getSemiBarcodeAByDongPanCode(station.Data.subLineList[4].barcode);
//通过A码查询上工位
if (!string.IsNullOrEmpty(Sem))
{
LastWorkInfo = LastWorkProductionInfo(Sem, station.PreTableName, "SemiBarcode");
}
else
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "检测无上工位信息");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.PreNoWork);
return false;
}
}
else
{
if (station.stationID != "8")
{
if (station.stationID == "15")
{
string LastWorkInfo1 = LastWorkProductionInfo(station.Data.subLineList[1].barcode, "T_RP_StationPara_B130_1", "ScanBarcode");
if (string.IsNullOrEmpty(LastWorkInfo1))
{
string LastWorkInfo2 = LastWorkProductionInfo(station.Data.subLineList[1].barcode, "T_RP_StationPara_B130_2", "ScanBarcode");
if (!string.IsNullOrEmpty(LastWorkInfo2))
{
LastWorkInfo = LastWorkInfo2;
}
}
else
{
LastWorkInfo = LastWorkInfo1;
}
}
else if (station.stationID == "13" || station.stationID == "14")
{
//启用绝缘工位互锁后检漏工位判断上工位是否合格业务逻辑
if (station.Data.subLineList[1].barcode == "00000000000000000000")
{
LastWorkInfo = "1";
}
else
{
LastWorkInfo = LastWorkProductionInfo(station.Data.subLineList[1].barcode, station.PreTableName, "ScanBarcode");
}
}
else
{
if (station.stationID == "17"|| station.stationID == "18")
{
LastWorkInfo = LastWorkProductionInfo(station.Data.ProductBarcode, station.PreTableName, "ScanBarcode");
}
else
{
LastWorkInfo = LastWorkProductionInfo(station.Data.subLineList[1].barcode, station.PreTableName, "ScanBarcode");
}
}
}
}
//没有上工位信息
if (string.IsNullOrEmpty(LastWorkInfo))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "检测无上工位信息");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.PreNoWork);
return false;
}
else
{
//NG物料拿取
if (LastWorkInfo != "1")
{
if (LastWorkInfo == "0")
{
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.OK);
return false;
}
else
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "检测上工位信息不合格,NG物料拿取");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.TakeNG);
return false;
}
}
}
}
}
//这里加一个物料是否匹配=======//还要加判断,当前工位是否需要判断
//ICSharpCode.Core.LoggingService.Debug("》》》》》》开始写入PLC反馈信号");
}
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.OK);
//ICSharpCode.Core.LoggingService.Debug("》》》》》》写入PLC反馈信号完成");
return true;
}
public bool HandleData(StationInfo station)
{
try
{
SqlHelper sh = new SqlHelper();
DbHandler db = new DbHandler();
if (station.stationID == "3")
{
station.Data.ProductBarcode = station.Data.subLineList[4].barcode;
}
else if (station.stationID == "11" || station.stationID == "12" || station.stationID == "13" || station.stationID == "14" || station.stationID == "15" || station.stationID == "16" || station.stationID == "19" || station.stationID == "20")
{
station.Data.ProductBarcode = station.Data.subLineList[1].barcode;
}
else if (station.stationID == "8")
{
station.Data.ProductBarcode = station.Data.subLineList[2].barcode;
}
//判断动静盘工位
//if (station.stationID == "12")
//{
// if (!station.Data.DP_OpenFlag)
// {
// //保存绑定动静盘
// //判断是否含有动静盘条码
// string DPBarCode = station.Data.subLineList[3].barcode;
// string JPBarCode = station.Data.subLineList[4].barcode;
// string ProductBarCode = station.Data.ProductBarcode;
// db.InsertDJRelationShip(DPBarCode, JPBarCode);
// }
//}
foreach (subLine s in station.Data.subLineList)
{
if (!string.IsNullOrEmpty(s.barcode))
{
ICSharpCode.Core.LoggingService.Debug(station.StationName + ",支线工位:" + station.StationCode + " ,物料条码:" + s.barcode);
}
}
//插入新数据
string InsertSql = sh.DataInsertSql2(station);
db.ExecSql(InsertSql);
//更新工位
if (station.stationID != "8")
{
string ABarCode = getSemiBarcodeAByDongPanCode(station.Data.ProductBarcode);
//根据组件码查询A码
if (!string.IsNullOrEmpty(ABarCode))
{
if (station.stationID == "20")
{
/*UPDATE dbo.T_SY_TraceState SET FinishFlag = 1,EndTime = GETDATE(),CurrentStationID = '33',state = 1,NameplateInfo = @serialNum,MarkRecord = @bigCode WHERE SemiBarcode_A = @semibarcode*/
//结束工位
UpdateCompleteStationInfo(ABarCode);
ICSharpCode.Core.LoggingService.DebugFormatted("{0}工位,{1}条码工位数据更新成功。", station.stationID, station.Data.ProductBarcode);
}
else
{
//根据A码查询M码
//获取系统M码
string Mainbarcode = GetMainBarcode(ABarCode);
if (!string.IsNullOrEmpty(Mainbarcode))
{
UpdateTraceStation(station.stationID, Mainbarcode);
ICSharpCode.Core.LoggingService.DebugFormatted("{0}工位,{1}条码工位数据更新成功。", station.stationID, station.Data.ProductBarcode);
}
}
}
}
ICSharpCode.Core.LoggingService.Debug("工位:" + station.StationCode + " 保存数据成功。托盘号:" + station.Data.RFIDNo);
}
catch (Exception e)
{
ICSharpCode.Core.LoggingService.Info(e.ToString());
return false;
}
finally
{
//这里要加一个OK放行
FinishSavePLCWork(station);
}
return true;
}
}
}