265 lines
14 KiB
C#
265 lines
14 KiB
C#
using System;
|
||
using System.Data;
|
||
using System.Runtime.Remoting.Metadata.W3cXsd2001;
|
||
using System.Threading;
|
||
using System.Xml.Linq;
|
||
using bizFacade;
|
||
|
||
//using SystemFramework;
|
||
using MesServerWork;
|
||
|
||
namespace MesServerFunctions
|
||
{
|
||
partial class FunctionMES
|
||
{
|
||
object lockBarcode = new object();
|
||
|
||
///第一步,判断条码类型,根据条码类型,执行对应的存储过程
|
||
///第二步,条码类型(将扫描的条码保存到对应的表中)
|
||
///第三步,扫描完成之后给出允许工作信号
|
||
/// 处理页面扫描条码
|
||
/// </summary>
|
||
/// <param name="OpName"></param>
|
||
/// <param name="barcode"></param>
|
||
public void Barcode(object e)
|
||
{
|
||
lock(lockBarcode)
|
||
{
|
||
try
|
||
{
|
||
DoWhatPlc.CustomeEvetnArgs msgEvent = (DoWhatPlc.CustomeEvetnArgs)e;
|
||
string OpName = Convert.ToString(msgEvent.OpName);
|
||
string barcode = Convert.ToString(msgEvent.TagValue);
|
||
SendMessageFun.SendInfomation("BarCodeData", barcode, OpName); // 将扫码值发送给前端
|
||
|
||
int EngineTypeID;//机型代码
|
||
string EngineType;//机型
|
||
string EngineID;//工件编号
|
||
|
||
string OrderForm;
|
||
int Recipe1;
|
||
int Recipe2;
|
||
int PartPallet_Code;
|
||
bool IsNotRepeatedNumber = false;
|
||
//1:获得申请上线信息后,扫描条码才处理业务
|
||
bool ispartload;
|
||
//(115)
|
||
int PTO;
|
||
//(118)0=不检测;1=24V,2=12V。检测线上线工位扫描总成条码,根据BOM,查出
|
||
int NgearSwitch;
|
||
//(119)0=不检测;1=24V,2=12V。检测线上线工位扫描总成条码,根据BOM,查出
|
||
int RgearSwitch;
|
||
//(120)0=不检测;1=检测。检测线上线工位扫描总成条码,根据BOM,查出
|
||
int SpeedSensor;
|
||
//(121)例如:5S 400。检测线上线工位扫描总成条码,根据BOM,查出
|
||
string PartTypeMid;
|
||
//(122) 0=不检测;1=24V,2=12V。检测线上线工位扫描总成条码,根据BOM,查出
|
||
int Tcu_V;
|
||
//(123) 加有量检测线上线工位扫描总成条码,根据BOM,查出
|
||
float addOil;
|
||
//(124) 上线法兰凹凸 -- 5s 1 凸 2 凹 6s 4凸 8 凹
|
||
int flange;
|
||
|
||
// 判断是否存在异常导致不允许工作 输出msg到前端
|
||
DataTable OpNameIsWorkDt = BaseDataSystemMES.OpNameIsAllowWork(OpName);
|
||
if (Convert.ToInt32(OpNameIsWorkDt.Rows[0]["提示类型"]) == 3)
|
||
{
|
||
SendMessageFun.SendInfomation("ShowTipBox", OpNameIsWorkDt.Rows[0]["提示文本"].ToString(), OpName);
|
||
return;
|
||
}
|
||
|
||
//判断工件是否到位
|
||
MIS_BASE.Read_WorkStart(OpName, out ispartload);
|
||
if (!ispartload)
|
||
{
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "请检查设备是否到位(DBX500.1=1)");
|
||
return;
|
||
}
|
||
//判断设备是否申请上线
|
||
MIS_BASE.Read_UpdatePalletOK(OpName, out ispartload);
|
||
if (!ispartload)
|
||
{
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "请检查设备是否申请上线(DBX500.3=1)");
|
||
return;
|
||
}
|
||
// 判读条码是变速器序列号条码号还是物料号 小机型*日月年* 流水号(给起始号 + 数量)
|
||
// 选小机型 从北汽福田BOM中选 得先维护BOM
|
||
// 变速器序列号 '1333 050 062*16012023*30000001'
|
||
|
||
//扫描完变速器序列号条码号 true
|
||
bool isGetOver_MES = false;
|
||
//判断上线工位,MES 是否将工件流水号、机型等信息已经写入到PLC了
|
||
//MIS_BASE.Read_EngineTypeGetOver_MES(OpName, out isGetOver_MES);
|
||
MIS_BASE.Read_EngineGetOver_PLC(OpName, out isGetOver_MES);
|
||
//如果工件流水号、机型等信息没有写入PLC,扫描的条码按工件流水号进行验证
|
||
//否则按装配物料进行验证
|
||
if (!isGetOver_MES)
|
||
{
|
||
|
||
if (barcode.Split('*').Length > 2)
|
||
{
|
||
|
||
string partSn = barcode;
|
||
EngineID = barcode;
|
||
|
||
// 判断扫的码是否在当前生产订单中
|
||
DataTable BarCodeDt;
|
||
BarCodeDt = BaseDataSystemMES.GetMainLineNowWorkOrderData(OpName, EngineID);
|
||
if (BarCodeDt.Rows.Count == 0) {
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "当前工位订单可上线条码中不存在此条码,请在当前计划模块中查看!");
|
||
return;
|
||
}
|
||
|
||
BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineID_MES, EngineID);
|
||
SendMessage.ShowMoby(OpName);
|
||
|
||
//2: 判断是否重号
|
||
//IsRepeatedNumber true 不重号;false 重号;
|
||
IsNotRepeatedNumber = BaseDataSystemMES.EngineTypeID_IsNotRepeatedNumber(partSn);
|
||
if (IsNotRepeatedNumber)
|
||
{
|
||
// 从数据库获得机型、机型代码等信息
|
||
BaseDataSystemMES.GetEngineTypeUpLoadOpName(partSn, OpName, out EngineTypeID, out EngineType, out OrderForm, out Recipe1, out Recipe2);
|
||
// 从数据库获得PTO等信息
|
||
BaseDataSystemMES.UpLoadPTO(partSn, out PTO, out NgearSwitch, out RgearSwitch, out SpeedSensor, out PartTypeMid, out Tcu_V,out addOil,out flange,out int Slender, out int Putters);
|
||
//PTO
|
||
MIS_BASE.WritePLC(115, OpName, PTO);
|
||
//空挡开关检测
|
||
MIS_BASE.WritePLC(95, OpName, NgearSwitch);
|
||
//倒挡开关检测
|
||
MIS_BASE.WritePLC(96, OpName, RgearSwitch);
|
||
//里程表检测
|
||
MIS_BASE.WritePLC(97, OpName, SpeedSensor);
|
||
//大机型扩展
|
||
MIS_BASE.WritePLC(98, OpName, PartTypeMid);
|
||
//TCU
|
||
MIS_BASE.WritePLC(122, OpName, Tcu_V);
|
||
// 写入是否存在PKB
|
||
bool isExistPKB = BaseDataSystemMES.Get_IsExistPKB(EngineType);
|
||
MIS_BASE.WritePLC(64, OpName, isExistPKB);
|
||
// 写入是否为后壳体垫块工作
|
||
bool isExistSpecialShell = BaseDataSystemMES.Get_IsExistSpecialShell(EngineType);
|
||
MIS_BASE.WritePLC(35, OpName, isExistSpecialShell);
|
||
|
||
|
||
// 先查询配方号 根据工位号 去moby表查配方号
|
||
// 根据配方号 去配方表查配方数据 写入配方数据
|
||
string tagStartAdr;//= "DB411.10";
|
||
BaseDataSystemMES.PLCRcipeCurrent(OpName, out byte[] bytes, out tagStartAdr);
|
||
DtWebApi.ReadWritePLC.Write_TagValueByTagTypeID("94", OpName, System.Text.Encoding.ASCII.GetString(bytes));
|
||
// 将产品信息写入PLC
|
||
MIS_BASE.Write_EngineTypeID_MES(OpName, EngineTypeID);
|
||
MIS_BASE.Write_EngineType_MES(OpName, EngineType);
|
||
MIS_BASE.Write_EngineID_MES(OpName, EngineID);
|
||
MIS_BASE.Write_OrderForm_MES(OpName, OrderForm);
|
||
|
||
// 写入到数据库的[北汽福田工位状态监控MOBY]表中
|
||
BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineID_MES, EngineID);
|
||
SendMessage.ShowMoby(OpName);
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "总成码扫码完成,请扫描后壳码!");
|
||
|
||
|
||
MIS_BASE.Write_EngineTypeGetOver_MES(OpName, true);
|
||
|
||
//Thread.Sleep(1000);
|
||
//// 临时增加 清除MES的传递机型
|
||
//MIS_BASE.Write_EngineTypeGetOver_MES(OpName, false);
|
||
|
||
}
|
||
else
|
||
{
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "变速器序列号 重号,请确认!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "变速器序列号格式不正确,请确认!");
|
||
}
|
||
}
|
||
else//验证物料
|
||
{
|
||
//物料号
|
||
{
|
||
//读取PLC的传递机型信号
|
||
bool tagValue;
|
||
bool IsSuccess;
|
||
MIS_BASE.Read_EngineGetOver_PLC(OpName, out tagValue);
|
||
if (tagValue)
|
||
{
|
||
// 提前判断一次有没有需要验证的物料 没有要扫码的就往下走允许工作那里
|
||
MIS_BASE.GetEngineTypeFromPLC(OpName, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code, out OrderForm);
|
||
// 在总分线表中添加该关联数据
|
||
BaseDataSystemMES.BusPartLine_Add(EngineID, barcode, OpName, OrderForm, EngineType);
|
||
|
||
BaseDataSystemMES.MesServer_Judge_IsCanWork(OpName, out int IsAllowWork);
|
||
if(IsAllowWork == 1)
|
||
{
|
||
IsSuccess = true;
|
||
}
|
||
else
|
||
{
|
||
//验证物料
|
||
BaseDataSystemMES.PartMaterial_DM_Update(OpName, barcode, out IsSuccess);
|
||
if (!IsSuccess)//????
|
||
{
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "条码无效,请确认");
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
SendMessageFun.SendInfomation("MaterialList", "1", OpName);//通知界面更新零件信息
|
||
}
|
||
//判断物料是否验证完成
|
||
BaseDataSystemMES.MesServer_Judge_IsCanWork(OpName, out int IsAllowWork2);
|
||
IsAllowWork = IsAllowWork2;
|
||
}
|
||
|
||
|
||
|
||
if (IsSuccess)
|
||
{
|
||
if (IsAllowWork == 1)
|
||
{
|
||
//移到允许保存信号中
|
||
//BaseDataSystemMES.Material_Insert(OpName, 1);
|
||
|
||
////更新订单完工数量及物料
|
||
SendMessageFun.SendMessage("245", "111", OpName);
|
||
|
||
// 写入到数据库的[北汽福田工位状态监控MOBY]表中
|
||
SendMessage.ShowMoby(OpName);
|
||
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "扫码完成,请开始工作!");
|
||
|
||
//物料验证完成,通知PLC允许工作,允许工作在保存完成时清空
|
||
MIS_BASE.Write_FixAllow(OpName, true);
|
||
}
|
||
else
|
||
{
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "请扫描物料!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
SendMessageFun.AsyncSendMessage_Notice(OpName, "PLC未传递机型");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
SendMessage.AsyncSendMessage_Notice(OpName, "产品上线后,PLC获得变速器序列号后,再验证物料!");
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (Exception err)
|
||
{
|
||
// 保存出错日志 1.申请上线 2.传递机型 3.允许保存 4.扫码
|
||
MisDataSaveDate.FuntionMesRead.Alarm_SaveFileLog4Error(4, e, "Fun1058", err);
|
||
////ApplicationLog.WriteLog(err, "Function08:Barcode");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|