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.

944 lines
41 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 MaterialTraceability.Common;
using MaterialTraceability.Entity.DAO;
using MaterialTraceability.Entity.DTO;
using MaterialTraceability.Entity.Enum;
using MaterialTraceability.Entity.UpLoad;
using MaterialTraceability.SqlSugar;
using MaterialTraceability.SqlSugar.ServiceImpl;
using MaterialTraceability.WebService;
using MaterialTraceability.WebService.GetParametricValueServiceService;
using MaterialTraceability.WebService.MachineIntegrationServiceService;
using MaterialTraceability.WebService.MiBatchCompleteSfcAndAdujustQtyServiceService;
using MaterialTraceability.WebService.MiFirstOperationForsfcServiceService;
using MaterialTraceability.WebService.MiSFCQueryQtyServiceService;
using MaterialTraceability.WebService.Param;
using MaterialTraceability.WebService.ProcessLotServiceWSService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MaterialTraceability.Business.Impl
{
public class JRSignalReadBusiness : ISignalReadFunction
{
/// <summary>
/// INIFile配置文件
/// </summary>
private INIFile inifile = new INIFile(System.Environment.CurrentDirectory + "/MesConfig/App.InI");
private AppConfigDto appConfig = AppConfigDto.Instance;
/// <summary>
/// 日志刷新
/// </summary>
/// <param name="type">日志内容</param>
/// <param name="massage"></param>
public delegate void LogRefresh(LogType logType, string massage);
public static event LogRefresh LogRefreshEvent;
/// <summary>
/// 视图层数据刷新
/// </summary>
/// <param name="viewModelDto"></param>
public delegate void ViewModelRefresh(ViewModelDto viewModelDto);
public static event ViewModelRefresh ViewModelRefreshEvent;
/// <summary>
/// PLC信号事件
/// </summary>
/// <param name="status"></param>
/// <param name="position"></param>
public delegate void SignalReadInvoke(int status, int position);
/// <summary>
/// RFID读写器业务
/// </summary>
private EquipBusiness equipBusiness = new EquipBusiness();
/// <summary>
/// Mes WebService接口
/// </summary>
private IMesWebServices MesWebServices = new MesWebServicesImpl();
//卷轴信息
private IBaseServices<ProShaftInfo> shaftInfoServices = new BaseServices<ProShaftInfo>();
//收卷记录
private IBaseServices<ProDownRecord> downRecordServices = new BaseServices<ProDownRecord>();
//上料记录
private IBaseServices<ProUpRecord> upRecordServices = new BaseServices<ProUpRecord>();
private IBaseServices<SysClient> sysClientServices = new BaseServices<SysClient>();
private MesAlarmInfo mesAlarmInfo = new MesAlarmInfo();
private PlcBusiness plcBusiness = new PlcBusiness();
private UpLoadBusiness upLoadBusiness = UpLoadBusiness.Instance;
/// <summary>
/// 写入RFID
/// </summary>
/// <param name="position"></param>
/// <param name="epc"></param>
public void WriteRFIDtoPLC(int position, String epc)
{
try
{
switch (position)
{
case 1:
PlcBusiness.writeStrPlc(appConfig.JrAddress.RFID, epc);
break;
case 2:
PlcBusiness.writeStrPlc(appConfig.JrAddress.RFID, epc);
break;
case 3:
PlcBusiness.writeStrPlc(appConfig.JrAddress.RFID, epc);
break;
case 4:
PlcBusiness.writeStrPlc(appConfig.JrAddress.RFID, epc);
break;
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 写入SFC
/// </summary>
/// <param name="position"></param>
/// <param name="sfc"></param>
public void WriteSFCtoPLC(int position, String sfc)
{
try
{
switch (position)
{
case 1:
PlcBusiness.writeStrPlc(appConfig.JrAddress.SFC, sfc);
break;
case 2:
PlcBusiness.writeStrPlc(appConfig.JrAddress.SFC, sfc);
break;
case 3:
PlcBusiness.writeStrPlc(appConfig.JrAddress.SFC, sfc);
break;
case 4:
PlcBusiness.writeStrPlc(appConfig.JrAddress.SFC, sfc);
break;
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 写入EA
/// </summary>
/// <param name="position"></param>
/// <param name="sfc"></param>
public void WriteEAtoPLC(int position, int ea)
{
try
{
switch (position)
{
case 1:
plcBusiness.writeInt16Plc(appConfig.JrAddress.EA, ea);
break;
case 2:
plcBusiness.writeInt16Plc(appConfig.JrAddress.EA, ea);
break;
case 3:
plcBusiness.writeInt16Plc(appConfig.JrAddress.EA, ea);
break;
case 4:
plcBusiness.writeInt16Plc(appConfig.JrAddress.EA, ea);
break;
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 写入膜卷等级
/// </summary>
/// <param name="position"></param>
/// <param name="sfc"></param>
public void WriteLeveltoPLC(int position, int level)
{
try
{
switch (position)
{
case 1:
// plcBusiness.writePlc(appConfig.JrAddress.阳极左卷轴膜卷等级, level);
plcBusiness.writeInt16Plc(appConfig.JrAddress., level);
break;
case 2:
plcBusiness.writeInt16Plc(appConfig.JrAddress., level);
break;
case 3:
plcBusiness.writeInt16Plc(appConfig.JrAddress., level);
break;
case 4:
plcBusiness.writeInt16Plc(appConfig.JrAddress., level);
break;
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 写入读取、过账MES完成信号
/// </summary>
/// <param name="position"></param>
/// <param name="flag"></param>
public void WriteOKtoPLC(int position, int flag)
{
try
{
switch (position)
{
case 1:
plcBusiness.writePlc(appConfig.JrAddress., flag);
break;
case 2:
plcBusiness.writePlc(appConfig.JrAddress., flag);
break;
case 3:
plcBusiness.writePlc(appConfig.JrAddress., flag);
break;
case 4:
plcBusiness.writePlc(appConfig.JrAddress., flag);
break;
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 写入报警信息:2002-RFID读取失败2102-MES交互失败
/// </summary>
/// <param name="position"></param>
/// <param name="flag"></param>
public void WriteWarningtoPLC(int position, int flag)
{
try
{
if (position == 1)
{
plcBusiness.writePlc(appConfig.JrAddress., flag);
}
else if (position == 2)
{
plcBusiness.writePlc(appConfig.JrAddress., flag);
}
else if (position == 3)
{
plcBusiness.writePlc(appConfig.JrAddress., flag);
}
else if (position == 4)
{
plcBusiness.writePlc(appConfig.JrAddress., flag);
}
}
catch (Exception ex)
{
}
}
/// <summary>
///判断当前是哪个轴
/// </summary>
/// <returns></returns>
private string Which(int position)
{
string logStr = "";
if (position == 1) logStr = LanguageHelper.ShowMessage("阳极放卷A轴");
if (position == 2) logStr = LanguageHelper.ShowMessage("阳极放卷B轴");
if (position == 3) logStr = LanguageHelper.ShowMessage("阴极放卷A轴");
if (position == 4) logStr = LanguageHelper.ShowMessage("阴极放卷B轴");
return logStr;
}
///
/// <summary>
/// //卷绕开始过账信号
/// </summary>
/// <param name="position"></param>
public void UpBegin(int position)
{
try
{
Expression<Func<ProUpRecord, bool>> exp = s1 => s1.PositionId == position;
Expression<Func<ProUpRecord, object>> order = (x) => x.RecordTime;
ProUpRecord upRecord = upRecordServices.QueryFirst(exp, order, false).Result;
if (upRecord != null && string.IsNullOrEmpty(upRecord.Sfc))
{
MesBegin(position, upRecord.Rfid, true);
}
}
catch (Exception ex)
{
LogHelper.Error(ex.Message);
}
}
//end add
/// <summary>
/// 放卷涨紧
/// </summary>
/// <param name="position"></param>
public void UpMaterialBegin(int position)
{
try
{
string logStr = Which(position);
LogRefreshEvent?.Invoke(LogType.PlcLog, logStr+ LanguageHelper.ShowMessage("涨紧信号触发成功"));
LogHelper.Info(String.Format("{0}涨紧信号触发成功", logStr));
//读取卷筒RFID物料信息
ProEquip proEquip = equipBusiness.Equiplist.Where(x => x.positionId == position).FirstOrDefault();
if (proEquip == null)
{
LogRefreshEvent?.Invoke(LogType.AlarmLog, logStr+ LanguageHelper.ShowMessage("获取RFID设备信息异常"));
WriteWarningtoPLC(position, 2002);
return;
}
string epc = equipBusiness.ReadEPCByAntana(proEquip.equipId);
//测试数据
// epc = "JYHB01010125";
epc = epc.Replace("\0", "").Trim();
Thread.Sleep(10000);
//if (epc == "" || epc == null)
//{
// Random random = new Random();
// epc = "CATT1RDA" + random.Next(000000, 999999).ToString();
//}
if (StringExtension.IsBlank(epc))
{
WriteWarningtoPLC(position, 2002);
LogHelper.Info($"{logStr}RFID条码信息读取失败下发PLC报警");
LogRefreshEvent?.Invoke(LogType.AlarmLog, logStr+LanguageHelper.ShowMessage("RFID条码信息读取失败"));
ViewModelRefreshEvent?.Invoke(new ViewModelDto()
{
rfidInfo = new RfidInfoDto()
{
rfid = "",
sfc = "",
ea = "",
position = position,
},
plcStatus = true,
});
return;
}
//SaveReadRecord(proEquip, epc);
LogHelper.Info($"{logStr}RFID条码信息读取成功{epc}");
LogRefreshEvent?.Invoke(LogType.RfidLog, logStr+LanguageHelper.ShowMessage("RFID条码信息读取成功,RFID为")+ epc);
//判断RFID标签是否重复
//LogHelper.Info("判断RFID标签是否重复");
#region 暂不启用
//if (BusinessHelper.UpRfidIsRecur(epc, position).Result)
//{
// LogHelper.Info("放卷位RFID读取到的条码" + epc + "与前一读取相同并且生产未结束,可以继续生产");
// LogRefreshEvent?.Invoke(LogType.RfidLog, "放卷位RFID读取到的条码" + epc + "与前一读取相同并且生产未结束,可以继续生产");
// LogHelper.Info("卷绕放卷流程处理成功D6014写0");
// plcBusiness.writePlc(appConfig.JrAddress.放卷上料1AOK, 0);
// return;
// //判断是否已经生产结束
// if (UpMaterialIsEndProduction(epc).Result)
// {
// plcBusiness.writePlc(appConfig.JrAddress.RFID异常, 1);
// LogRefreshEvent?.Invoke(LogType.AlarmLog, String.Format("当前读取的RFID{0},已经生产结束不允许再次上料", epc));
// LogHelper.Info(String.Format("当前读取的RFID{0},已经生产结束不允许再次上料", epc));
// return;
// }
// else
// {
// Expression<Func<ProUpRecord, bool>> exp = s1 => true;
// Expression<Func<ProUpRecord, object>> order = (x) => x.RecordTime;
// ProUpRecord upRecord = upRecordServices.QueryFirst(exp, order, false).Result;
// if (upRecord != null)
// {
// WriteRFIDtoPLC(position, epc);
// WriteSFCtoPLC(position, upRecord.Sfc);
// //PlcBusiness.writeStrPlc(appConfig.JrAddress.放卷SFC, upRecord.Sfc);
// ViewModelRefreshEvent?.Invoke(new ViewModelDto()
// {
// rfidInfo = new RfidInfoDto()
// {
// rfid = epc,
// sfc = upRecord.Sfc,
// position = position,
// },
// plcStatus = true,
// });
// }
// LogHelper.Info("放卷位RFID读取到的条码" + epc + "与前一读取相同并且生产未结束,可以继续生产");
// LogRefreshEvent?.Invoke(LogType.RfidLog, "放卷位RFID读取到的条码" + epc + "与前一读取相同并且生产未结束,可以继续生产");
// LogHelper.Info("卷绕放卷流程处理成功D6014写0");
// //plcBusiness.writePlc(appConfig.JrAddress.放卷上料OK, 0);
// return;
// }
//}
#endregion 暂不启用
if (position == 1 || position == 2)
{
plcBusiness.writePlc(appConfig.JrAddress., 1);
}
else
{
plcBusiness.writePlc(appConfig.JrAddress., 1);
}
//读取数据刷新
ViewModelRefreshEvent?.Invoke(new ViewModelDto()
{
rfidInfo = new RfidInfoDto()
{
rfid = epc,
//sfc = "",
position = position,
},
plcStatus = true,
});
//存储数据库
Expression<Func<ProUpRecord, bool>> exp = s1 => s1.PositionId == position;
Expression<Func<ProUpRecord, object>> order = (x) => x.RecordTime;
ProUpRecord upRecord = upRecordServices.QueryFirst(exp, order, false).Result;
if (upRecord == null || upRecord.Rfid != epc)
{
//本地保存SFC,上料记录
ProUpRecord upRecord1 = new ProUpRecord()
{
Id = System.Guid.NewGuid().ToString(),
MachineId = appConfig.machineId,
PositionId = position,
Rfid = epc,
IsProduction = 0,
beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
RecordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
upRecordServices.Add(upRecord1);
}
}
catch (Exception ex)
{
LogHelper.Error("放卷涨紧逻辑处理异常", ex);
LogRefreshEvent?.Invoke(LogType.AlarmLog, LanguageHelper.ShowMessage("放卷涨紧逻辑处理异常")+ ex.Message);
}
}
/// <summary>
/// 开始过账信号Mes处理
/// </summary>
/// <param name="position"></param>
/// <param name="epc"></param>
/// <param name="auto"></param>
public async void MesBegin(int position, string epc, bool auto)
{
WriteRFIDtoPLC(position, epc);
string logStr = Which(position);
string sfc = "";
try
{
LogHelper.Info($"{logStr}调用MES首工序获取SFC接口");
LogRefreshEvent?.Invoke(LogType.MesLog, logStr+ LanguageHelper.ShowMessage("调用MES首工序获取SFC接口"));
LogRefreshEvent?.Invoke(LogType.RfidLog, logStr + LanguageHelper.ShowMessage("调用MES首工序获取SFC接口"));
sfc = GetSfcByRfid(epc);
#region 阴阳极上料防呆,position=1,2是阳极轴34是阴极轴
string code = sfc.Substring(5, 1);
if (code == "A") //阳极膜卷号
{
if (position == 3 || position == 4)
{
LogRefreshEvent?.Invoke(LogType.MesLog,LanguageHelper.ShowMessage("请检查阴阳极是否混料,或者RFID绑定关系是否有误"));
LogRefreshEvent?.Invoke(LogType.AlarmLog, LanguageHelper.ShowMessage("请检查阴阳极是否混料,或者RFID绑定关系是否有误"));
WriteWarningtoPLC(position, 2102);
return;
}
}
else if (code == "C") //阴极膜卷号
{
if (position == 1 || position == 2)
{
LogRefreshEvent?.Invoke(LogType.MesLog, LanguageHelper.ShowMessage("请检查阴阳极是否混料,或者RFID绑定关系是否有误"));
LogRefreshEvent?.Invoke(LogType.AlarmLog, LanguageHelper.ShowMessage("请检查阴阳极是否混料,或者RFID绑定关系是否有误"));
WriteWarningtoPLC(position, 2102);
return;
}
}
#endregion 阴阳极上料防呆,position=1,2是阳极轴34是阴极轴
if (StringExtension.IsBlank(sfc))
{
LogRefreshEvent?.Invoke(LogType.MesLog, logStr+ epc + "通过MES未获取到SFC");
LogRefreshEvent?.Invoke(LogType.AlarmLog, logStr + epc + "通过MES未获取SFC");
WriteWarningtoPLC(position, 2102);
return;
}
WriteSFCtoPLC(position, sfc);
//MES接口获取膜卷等级
//double level = GetSfcLevelByMes(epc, sfc);
double level = 2;
if (level == -1)
{
LogRefreshEvent?.Invoke(LogType.MesLog, logStr+epc + LanguageHelper.ShowMessage("通过MES未获取到膜卷等级"));
LogRefreshEvent?.Invoke(LogType.AlarmLog, logStr + epc + LanguageHelper.ShowMessage("通过MES未获取到膜卷等级"));
WriteWarningtoPLC(position, 2102);
return;
}
WriteLeveltoPLC(position, (int)level);
//获取ea
//int ea = GetUpMaterialQty111(position, sfc, logStr);
int ea = 160;
if (ea <= 0)
{
LogRefreshEvent?.Invoke(LogType.MesLog, logStr+ epc + LanguageHelper.ShowMessage("通过MES未获取到EA"));
LogRefreshEvent?.Invoke(LogType.AlarmLog, logStr + epc + LanguageHelper.ShowMessage("通过MES未获取到EA"));
WriteWarningtoPLC(position, 2102);
return;
}
WriteEAtoPLC(position, ea);
#region 卷绕上账接口
if (appConfig.isMesFlag == 1)
{
//调MES首工序获取SFC接口-----卷绕自动上料接口 todo---确定MES接口请求参数以及确定接口是否这个,找PE
MiFirstOperationForsfcServiceServiceParam miFirstOperationForsfcServiceServiceParam = new MiFirstOperationForsfcServiceServiceParam()
{
url = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "url"),
site = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "site"),
sfc = "",
processLot = epc,
operation = appConfig.operation,
operationRevision = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "operationRevision"),
resource = appConfig.resource,
user = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "user"),
activity = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "activity"),
modeProcessSfc = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "modeProcessSfc"),
loginUser = "",
password = "",
};
LogHelper.Info("卷绕自动上料接口请求参数:" + JsonChange.ModeToJson(miFirstOperationForsfcServiceServiceParam));
miFirstOperationForsfcResponse firstOperationForsfcResponse = new miFirstOperationForsfcResponse();
DateTime beginTime = DateTime.Now;
try
{
firstOperationForsfcResponse = MesWebServices.iMiFirstOperationForsfcServiceService(miFirstOperationForsfcServiceServiceParam);
LogHelper.Info("卷绕自动上料接口返回参数:" + JsonChange.ModeToJson(firstOperationForsfcResponse));
//判断返回结果
if (firstOperationForsfcResponse.@return.code > 0)
{
LogHelper.Info("卷绕自动上料接口请求失败:" + firstOperationForsfcResponse.@return.message);
WriteWarningtoPLC(position, 2102);
LogRefreshEvent?.Invoke(LogType.RfidLog, LanguageHelper.ShowMessage("MES自动上料接口调用失败"));
LogRefreshEvent?.Invoke(LogType.MesLog,LanguageHelper.ShowMessage("MES自动上料接口调用失败") + upLoadBusiness.GetMesMessage(firstOperationForsfcResponse.@return.code, firstOperationForsfcResponse.@return.message));
LogRefreshEvent?.Invoke(LogType.AlarmLog,LanguageHelper.ShowMessage("MES自动上料接口调用失败") + upLoadBusiness.GetMesMessage(firstOperationForsfcResponse.@return.code, firstOperationForsfcResponse.@return.message));
//LogRefreshEvent?.Invoke(LogType.PlcLog,LanguageHelper.ShowMessage("自动上料接口调用失败下发PLC报警信号"));
return;
}
// qty = firstOperationForsfcResponse.@return.qty;
LogRefreshEvent?.Invoke(LogType.RfidLog, LanguageHelper.ShowMessage("自动上料接口调用成功")+"SFC"+ sfc + "EA" + ea);
// LogRefreshEvent?.Invoke(LogType.RfidLog, String.Format("卷绕自动上料接口调用成功SFC{0}EA{1}", sfc, qty));
LogHelper.Info(String.Format("自动上料接口调用成功SFC{0}EA{1}", sfc, ea));
// LogHelper.Info(String.Format("卷绕自动上料接口调用成功SFC{0}EA{1}", sfc, qty));
}
catch (Exception ex)
{
LogHelper.Info("自动上料接口调用异常:" + ex.Message);
LogRefreshEvent?.Invoke(LogType.AlarmLog, LanguageHelper.ShowMessage("自动上料接口调用异常:") + ex.Message);
LogRefreshEvent?.Invoke(LogType.MesLog, LanguageHelper.ShowMessage("自动上料接口调用异常:") + ex.Message);
WebServiceLog.saveMiFirstOperationForsfcServiceService(miFirstOperationForsfcServiceServiceParam, null
, beginTime, ex.Message);
WriteWarningtoPLC(position, 2102);
return;
}
}
#endregion 卷绕上账接口
ViewModelRefreshEvent?.Invoke(new ViewModelDto()
{
rfidInfo = new RfidInfoDto()
{
rfid = epc,
sfc = sfc,
position = position,
ea = ea.ToString(),
//grade = level.ToString()
},
plcStatus = true,
});
//实时绑定卷轴与RFID信息
LogHelper.Info(String.Format("绑定放卷轴与RFID:{0};获取卷轴信息", epc));
ProShaftInfo shaftInfo = await this.GetShaftInfoByPosition(position);
if (shaftInfo == null)
{
LogRefreshEvent?.Invoke(LogType.RfidLog,LanguageHelper.ShowMessage("绑定卷轴与RFID获取卷轴信息为空"));
LogRefreshEvent?.Invoke(LogType.AlarmLog,LanguageHelper.ShowMessage("绑定卷轴与RFID获取卷轴信息为空"));
LogHelper.Info("绑定卷轴与RFID获取卷轴信息为空");
return;
}
LogHelper.Info("获取卷轴信息为:" + JsonChange.ModeToJson(shaftInfo));
shaftInfo.bindRfid = epc;
shaftInfo.bindSfc = sfc;
shaftInfo.bindEaValue = ea.ToString();
shaftInfo.bindTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
await shaftInfoServices.Update(shaftInfo);
Expression<Func<ProUpRecord, bool>> exp = s1 => s1.PositionId == position;
Expression<Func<ProUpRecord, object>> order = (x) => x.RecordTime;
ProUpRecord upRecord = upRecordServices.QueryFirst(exp, order, false).Result;
upRecord.Sfc = sfc;
upRecord.eaValue = ea;
upRecord.IsProduction = 1;
await upRecordServices.Update(upRecord);
LogHelper.Info("卷绕放卷流程处理成功D6014写0");
WriteOKtoPLC(position, 1);
}
catch (Exception ex)
{
LogHelper.Error("MES处理异常", ex);
}
}
/// <summary>
/// 放卷结束--暂未使用
/// </summary>
/// <param name="position"></param>
public async void UpMaterialEnd(int position)
{
try
{
LogRefreshEvent?.Invoke(LogType.PlcLog, "卷绕放卷位结束信号触发成功");
LogRefreshEvent?.Invoke(LogType.RfidLog, "卷绕放卷位结束信号触发成功");
LogHelper.Info("卷绕放卷位结束信号触发成功");
ProShaftInfo shaftInfo = await this.GetShaftInfoByPosition(position);
if (shaftInfo == null)
{
LogRefreshEvent?.Invoke(LogType.RfidLog, "放卷结束,获取卷轴绑定的信息为空");
return;
}
Expression<Func<ProUpRecord, bool>> upExp = s1 => true;
upExp = upExp.And(x => x.Sfc == shaftInfo.bindSfc && x.Rfid == shaftInfo.bindRfid && x.IsProduction == 0);
Expression<Func<ProUpRecord, object>> upOrder = (x) => x.RecordTime;
ProUpRecord upRecord = await upRecordServices.QueryFirst(upExp, upOrder, false);
if (upRecord == null)
{
LogRefreshEvent?.Invoke(LogType.AlarmLog, "放卷结束,获取上料信息为空");
return;
}
//清空绑定信息
//shaftInfo.bindSfc = String.Empty;
//shaftInfo.bindRfid = String.Empty;
//shaftInfo.bindEaValue = String.Empty;
//await shaftInfoServices.Update(shaftInfo);
//LogRefreshEvent?.Invoke(LogType.RfidLog, "放卷结束,清除卷轴绑定信息");
LogRefreshEvent?.Invoke(LogType.RfidLog, "获取当前正在生产的收卷轴");
//if (PlcBusiness.readPlc(appConfig.JrAddress.收卷1A状态) == 1) UpdateShaftEndFlag(1);
//if (PlcBusiness.readPlc(appConfig.JrAddress.收卷1B状态) == 1) UpdateShaftEndFlag(2);
//if (PlcBusiness.readPlc(appConfig.JrAddress.收卷2A状态) == 1) UpdateShaftEndFlag(3);
//if (PlcBusiness.readPlc(appConfig.JrAddress.收卷2B状态) == 1) UpdateShaftEndFlag(4);
//更新放卷信息
upRecord.endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
upRecord.IsProduction = 1;
upRecord.isFinish = 1;
await upRecordServices.Update(upRecord);
LogRefreshEvent?.Invoke(LogType.RfidLog, "生成放卷信息");
upLoadBusiness.UpdateUpRecord(upRecord);
}
catch (Exception ex)
{
LogHelper.Error("卷绕放卷位结束逻辑处理异常", ex);
LogRefreshEvent?.Invoke(LogType.AlarmLog, "卷绕放卷位结束逻辑处理异常" + ex.Message);
}
}
/// <summary>
/// 收卷涨紧
/// </summary>
/// <param name="position"></param>
public async void DownMaterialBegin(int position)
{
}
/// <summary>
/// 收卷结束
/// </summary>
/// <param name="position"></param>
public async void DownMaterialEnd(int position)
{
}
/// <summary>
/// 通过RFID获取SFC
/// </summary>
/// <param name="rfidStr"></param>
/// <returns></returns>
private string GetSfcByRfid(string rfidStr)
{
string sfcStr = "";
DateTime beginTime = new DateTime();
ProcessLotServiceWSServiceParam processLotServiceWSServiceParam = new ProcessLotServiceWSServiceParam()
{
url = inifile.IniReadValue("ProcessLotServiceWSServiceParam", "url"),
site = inifile.IniReadValue("ProcessLotServiceWSServiceParam", "site"),
loginUser = inifile.IniReadValue("ProcessLotServiceWSServiceParam", "loginUser"),
password = inifile.IniReadValue("ProcessLotServiceWSServiceParam", "password"),
processlotref = String.Format("ProcessLotBO:2100,{0}", rfidStr)
};
try
{
LogRefreshEvent?.Invoke(LogType.MesLog, "调用MES接口获取RFID绑定的SFC");
LogHelper.Info("MES获取SFC接口请求参数" + JsonChange.ModeToJson(processLotServiceWSServiceParam));
if (appConfig.isMesFlag == 1)
{
readProcessLotResponse readProcessLotResponse = MesWebServices.readProcessLot(processLotServiceWSServiceParam);
LogHelper.Info("MES获取SFC接口返回参数" + JsonChange.ModeToJson(readProcessLotResponse));
if (readProcessLotResponse.Response.processLotMemberList != null)
{
sfcStr = readProcessLotResponse.Response.processLotMemberList[0].memberContext.Substring(11);
LogHelper.Info("RFID条码" + rfidStr + "绑定的SFC条码为" + sfcStr);
LogRefreshEvent?.Invoke(LogType.MesLog, "RFID" + rfidStr + ",SFC" + sfcStr);
}
}
else
{
sfcStr = "LYL3PA02230824" + new Random().Next(0000,9999);
}
}
catch (Exception ex)
{
LogHelper.Info("MES获取SFC接口调用异常" + ex.Message);
LogRefreshEvent?.Invoke(LogType.MesLog, "MES获取SFC接口调用异常" + ex.Message);
LogRefreshEvent?.Invoke(LogType.AlarmLog, "MES获取SFC接口调用异常" + ex.Message);
WebServiceLog.saveReadProcessLot(processLotServiceWSServiceParam, null, beginTime, ex.Message);
}
return sfcStr;
}
/// <summary>
/// 通过MES接口获取膜卷等级
/// </summary>
/// <returns></returns>
private double GetSfcLevelByMes(string epc, string sfc)
{
double SHIPPING_GRADE_EARS = 0;//膜卷等级
try
{
string gradeName = inifile.IniReadValue("JRParametricValueParam", "gradeName");
GetParametricValueRequestData[] t = new GetParametricValueRequestData[] {
new GetParametricValueRequestData { parameter= gradeName }
};
TBDataServiceParam jrServiceParam = new TBDataServiceParam()
{
url = inifile.IniReadValue("JRParametricValueParam", "url"),
site = inifile.IniReadValue("JRParametricValueParam", "site"),
sfc = sfc,
memberlist = t
};
LogHelper.Info("获取膜卷等级接口请求参数:" + JsonChange.ModeToJson(jrServiceParam));
var tbresult = MesWebServices.findTBData(jrServiceParam);
if (tbresult.code != "0")
{
LogHelper.Error($"从mes中获取膜卷等级数据失败");
return 0;
}
LogHelper.Info($"从mes中获取膜卷等级数据{JsonChange.ModeToJson(tbresult)}");
foreach (var item in tbresult.paramValues)
{
if (item.parameter == gradeName) SHIPPING_GRADE_EARS = Convert.ToDouble((item.value));
}
}
catch (Exception ex)
{
LogHelper.Error($"从mes中获取膜卷等级数据异常{ex.Message}");
return -1;
}
return SHIPPING_GRADE_EARS;
}
/// <summary>
/// 获取放卷位EA值
/// </summary>
/// <param name="bindSfc"></param>
/// <param name="logStr"></param>
/// <returns></returns>
private int GetUpMaterialQty111(int position, string bindSfc, string logStr)
{
LogHelper.Info(logStr + "通过MES接口获取放卷物料的EA值");
GetMaterialNumParam getMaterialNumParam = new GetMaterialNumParam()
{
url = inifile.IniReadValue("JRGetMaterialNumParam", "url"),
site = inifile.IniReadValue("JRGetMaterialNumParam", "site"),
sfc = bindSfc
};
LogHelper.Info(logStr + "卷绕MES获取物料EA值接口请求参数" + JsonChange.ModeToJson(getMaterialNumParam));
DateTime beginTime = DateTime.Now;
try
{
if (appConfig.isMesFlag == 1)
{
var warehouseIntegrationInventoryTransferResponse = MesWebServices.JRGetEaInWarehourse(getMaterialNumParam);
LogHelper.Info(logStr + "通过MES获取物料EA值接口返回参数" + JsonChange.ModeToJson(warehouseIntegrationInventoryTransferResponse));
if (warehouseIntegrationInventoryTransferResponse.@return.code > 0)
{
LogHelper.Info(logStr + "通过MES获取物料EA值接口请求失败" + warehouseIntegrationInventoryTransferResponse.@return.message);
LogRefreshEvent?.Invoke(LogType.MesLog, logStr + LanguageHelper.ShowMessage("通过MES接口获取放卷物料的SFC数量失败") + bindSfc + upLoadBusiness.GetMesMessage(warehouseIntegrationInventoryTransferResponse.@return.code, warehouseIntegrationInventoryTransferResponse.@return.message));
LogRefreshEvent?.Invoke(LogType.AlarmLog, logStr + LanguageHelper.ShowMessage("通过MES接口获取放卷物料的SFC数量失败") + bindSfc + upLoadBusiness.GetMesMessage(warehouseIntegrationInventoryTransferResponse.@return.code, warehouseIntegrationInventoryTransferResponse.@return.message));
return 0;
}
return (int)warehouseIntegrationInventoryTransferResponse.@return.qty;
}
else
{
return 0;
}
}
catch (Exception ex)
{
LogHelper.Info(String.Format(logStr + "通过MES获取SFC数量接口异常:{1}", ex.Message));
// WebServiceLog.saveMiSFCQueryQtyServiceService(getMaterialNumParam, null, beginTime, ex.Message);
LogRefreshEvent?.Invoke(LogType.AlarmLog, logStr + LanguageHelper.ShowMessage("调用MES获取SFC接口异常") + ex.Message);
LogRefreshEvent?.Invoke(LogType.MesLog, logStr + LanguageHelper.ShowMessage("调用MES获取SFC接口异常") + ex.Message);
return 0;
}
}
/// <summary>
/// 根据设备位置获取卷轴信息
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public async Task<ProShaftInfo> GetShaftInfoByPosition(int position)
{
try
{
string str = appConfig.processId;
Expression<Func<ProShaftInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.positionId == position.ToString() && x.processId == str);
List<ProShaftInfo> result = await shaftInfoServices.Query(exp);
if (result != null || result.Count > 0)
{
ProShaftInfo shaftInfo = result.FirstOrDefault();
return shaftInfo;
}
return null;
}
catch (Exception ex)
{
LogRefreshEvent?.Invoke(LogType.RfidLog, LanguageHelper.ShowMessage("绑定卷轴与RFID获取卷轴信息为空"));
LogHelper.Info("获取卷轴信息异常:" + ex.Message);
return null;
}
}
/// <summary>
/// 收卷位开始信号
/// </summary>
/// <param name="position"></param>
public void DownBegin(int position)
{
}
/// <summary>
/// 设备启动
/// </summary>
public void MachineStartUp()
{
}
public void ForceDown(int position)
{
}
}
}