异常情况兜底不中断信号流程
This commit is contained in:
@@ -152,6 +152,18 @@ namespace MesWork
|
||||
|
||||
return !string.IsNullOrWhiteSpace(productNo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 业务资料异常时只记录兜底日志,PLC交互仍尽量继续,避免现场流程被MES辅助数据卡住。
|
||||
/// </summary>
|
||||
private void LogWeighingFallback(string opName, string productNo, string flowName, string reason, long AID)
|
||||
{
|
||||
string safeProductNo = string.IsNullOrWhiteSpace(productNo) ? "未知产品" : productNo;
|
||||
string msg = $"【{opName}】兜底放行:产品={safeProductNo},流程={flowName},原因={reason}";
|
||||
B_DB_Opera.SaveLog_Response(msg, AID);
|
||||
WeighingPage?.AppendLog($"[{opName}] {msg}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理请求工作信号 (tagTypeCodeID=44)
|
||||
/// 流程:读取工件信息 → 查询参数 → 写过站记录 → 按类型处理称重记录 → 回写允许工作
|
||||
@@ -166,7 +178,8 @@ namespace MesWork
|
||||
string modelNo = PLC_R.GetString_CleanGarbled(ReadPLC(11, opName)); // 机型号
|
||||
string orderNo = PLC_R.GetString_CleanGarbled(ReadPLC(39, opName)); // 工单号
|
||||
string palletNo = PLC_R.GetString_CleanGarbled(ReadPLC(80, opName)); // 托盘号
|
||||
// 解析代码串格式: 0/DHN2.5Q0219-36/D426E016767 或 DHH02K0014-400/B726E00584555
|
||||
string rawCodeBlock = engineNo;
|
||||
// 解析代码串格式: 0/DHN2.5Q0219-36/D426E016767 或 DHH02K0014-400/B726E00584555
|
||||
if (TryConvertCodeBlockData(engineNo, out string parsedOrderNo, out string parsedProductNo))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(parsedOrderNo))
|
||||
@@ -175,19 +188,21 @@ namespace MesWork
|
||||
}
|
||||
engineNo = parsedProductNo;
|
||||
|
||||
int stIdx = WeighingPage?.GetStationIndex(opName) ?? 1;
|
||||
if (!B_DB_Opera.QueryWorkpieceByOrderNo(orderNo, out string matchedModelNo, out decimal addOilQty, out decimal extractOilQty, out decimal density,
|
||||
out decimal residualOilUpperLimit, out decimal residualOilLowerLimit)) // 根据订货号 查询基本参数
|
||||
{
|
||||
WritePLC_IF(112, opName, 3); // 报警代码=3,机型错误
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】工件管理中未找到订货号[{orderNo}]的匹配规则,发动机={engineNo}", AID);
|
||||
WeighingPage?.AppendLog($"[{opName}] 订货号[{orderNo}]未匹配到工件参数");
|
||||
return;
|
||||
}
|
||||
modelNo = matchedModelNo;
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】读取工件:发动机={engineNo},机型={modelNo},订货号={orderNo},托盘={palletNo}", AID);
|
||||
WeighingPage?.UpdateStationInfo(stIdx, engineNo, modelNo, orderNo);
|
||||
WeighingPage?.AppendLog($"[{opName}] 读取工件:{engineNo},机型={modelNo}");
|
||||
int stIdx = WeighingPage?.GetStationIndex(opName) ?? 1;
|
||||
if (!B_DB_Opera.QueryWorkpieceByOrderNo(orderNo, out string matchedModelNo, out decimal addOilQty, out decimal extractOilQty, out decimal density,
|
||||
out decimal residualOilUpperLimit, out decimal residualOilLowerLimit)) // 根据订货号 查询基本参数
|
||||
{
|
||||
WritePLC_IF(112, opName, 3); // 报警代码=3,机型错误
|
||||
LogWeighingFallback(opName, engineNo, "请求工作", $"订货号[{orderNo}]未匹配到工件参数,使用PLC机型[{modelNo}]继续允许工作", AID);
|
||||
// 兜底机制:参数资料缺失不再卡PLC,请求保存时若无法正常更新记录会生成异常完成记录。
|
||||
WritePLC_IF(66, opName, true);
|
||||
CurveCollector_Start(opName, engineNo, modelNo);
|
||||
return;
|
||||
}
|
||||
modelNo = matchedModelNo;
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】读取工件:发动机={engineNo},机型={modelNo},订货号={orderNo},托盘={palletNo}", AID);
|
||||
WeighingPage?.UpdateStationInfo(stIdx, engineNo, modelNo, orderNo);
|
||||
WeighingPage?.AppendLog($"[{opName}] 读取工件:{engineNo},机型={modelNo}");
|
||||
WeighingPage?.UpdateOilInfo(stIdx, addOilQty, extractOilQty, density, 0, 0);
|
||||
string weighType = GetWeighingType(opName); // 地面/放油前/放油后
|
||||
string stationName = weighType; // 工位名称直接用称重类型名
|
||||
@@ -199,9 +214,7 @@ namespace MesWork
|
||||
if (!B_DB_Opera.QueryWeighingBeforeOil(engineNo, out _, out decimal preWeight, out _, out _, out _))
|
||||
{
|
||||
WritePLC_IF(112, opName, 3);
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】未找到发动机[{engineNo}]的空中称重记录", AID);
|
||||
WeighingPage?.AppendLog($"[{opName}] 未找到[{engineNo}]放油前记录,进站失败");
|
||||
return;
|
||||
LogWeighingFallback(opName, engineNo, "请求工作-放油后", "未找到放油前记录,继续允许工作,保存时按异常放油后记录处理", AID);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -223,8 +236,11 @@ namespace MesWork
|
||||
else
|
||||
{
|
||||
WritePLC_IF(112, opName, 1); // 报警代码=1,获取数据失败
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】码块数据转换失败:原始码值=[{engineNo}]", AID);
|
||||
WeighingPage?.AppendLog($"[{opName}] 码块数据转换失败:{engineNo}");
|
||||
engineNo = string.IsNullOrWhiteSpace(rawCodeBlock) ? $"未知产品_{opName}_{DateTime.Now:yyyyMMddHHmmss}" : rawCodeBlock.Trim();
|
||||
LogWeighingFallback(opName, engineNo, "请求工作", $"码块数据转换失败,原始码值=[{rawCodeBlock}],仍允许工作", AID);
|
||||
// 兜底机制:产品解析失败时仍给允许工作,后续保存阶段会按异常产品记录并判不合格。
|
||||
WritePLC_IF(66, opName, true);
|
||||
CurveCollector_Start(opName, engineNo, modelNo);
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
@@ -251,27 +267,34 @@ namespace MesWork
|
||||
{
|
||||
engineNo = parsedProductNo;
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(engineNo))
|
||||
{
|
||||
engineNo = $"未知产品_{opName}_{DateTime.Now:yyyyMMddHHmmss}";
|
||||
LogWeighingFallback(opName, engineNo, "请求保存", "保存时产品编号为空,使用临时产品号继续保存", AID);
|
||||
}
|
||||
|
||||
if (CurveCollector_TryGetStableWeight(opName, out decimal curveWeight, out int curvePointCount, out string curveMsg))
|
||||
{
|
||||
weight = curveWeight; // 曲线采样点已按工具标定公式处理,稳定重量不再二次标定
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】标定曲线重量={curveWeight:F3}kg,PLC锁定重量={plcWeight:F3}kg,点数={curvePointCount}", AID);
|
||||
}
|
||||
else
|
||||
{
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】曲线重量不可用,使用PLC锁定重量={plcWeight:F3}kg,原因={curveMsg}", AID);
|
||||
decimal rawWeight = plcWeight;
|
||||
if (!WeightCalibrationHelper.Apply(opName, rawWeight, out decimal calibratedWeight, out string calibrationFormula, out string calibrationMsg))
|
||||
{
|
||||
throw new Exception($"工具标定公式处理失败:{calibrationMsg}");
|
||||
}
|
||||
weight = calibratedWeight;
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】PLC锁定重量标定:原始重量={rawWeight:F3}kg,公式={calibrationFormula},标定后={weight:F3}kg", AID);
|
||||
WeighingPage?.AppendLog($"[{opName}] PLC锁定重量标定:原始={rawWeight:F3}kg,公式={calibrationFormula},结果={weight:F3}kg");
|
||||
}
|
||||
|
||||
long curveWeighingRecordId = 0;
|
||||
B_DB_Opera.UpdateStationComplete(engineNo, opName, weight); // 过站记录保存最终采用重量
|
||||
if (CurveCollector_TryGetStableWeight(opName, out decimal curveWeight, out int curvePointCount, out string curveMsg))
|
||||
{
|
||||
weight = curveWeight; // 曲线采样点已按工具标定公式处理,稳定重量不再二次标定
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】标定曲线重量={curveWeight:F3}kg,PLC锁定重量={plcWeight:F3}kg,点数={curvePointCount}", AID);
|
||||
}
|
||||
else
|
||||
{
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】曲线重量不可用,使用PLC锁定重量={plcWeight:F3}kg,原因={curveMsg}", AID);
|
||||
decimal rawWeight = plcWeight;
|
||||
if (!WeightCalibrationHelper.Apply(opName, rawWeight, out decimal calibratedWeight, out string calibrationFormula, out string calibrationMsg))
|
||||
{
|
||||
LogWeighingFallback(opName, engineNo, "请求保存", $"工具标定公式处理失败:{calibrationMsg},使用PLC原始重量继续保存", AID);
|
||||
calibrationFormula = "未标定兜底";
|
||||
calibratedWeight = rawWeight;
|
||||
}
|
||||
weight = calibratedWeight;
|
||||
B_DB_Opera.SaveLog_Response($"【{opName}】PLC锁定重量标定:原始重量={rawWeight:F3}kg,公式={calibrationFormula},标定后={weight:F3}kg", AID);
|
||||
WeighingPage?.AppendLog($"[{opName}] PLC锁定重量标定:原始={rawWeight:F3}kg,公式={calibrationFormula},结果={weight:F3}kg");
|
||||
}
|
||||
|
||||
long curveWeighingRecordId = 0;
|
||||
B_DB_Opera.UpdateStationComplete(engineNo, opName, weight); // 过站记录保存最终采用重量
|
||||
string weighType = GetWeighingType(opName);
|
||||
decimal oilReleaseQty = 0;
|
||||
decimal residualOilQty = 0;
|
||||
@@ -280,29 +303,53 @@ namespace MesWork
|
||||
if (weighType == "地面")
|
||||
{
|
||||
// 地面:查最新记录 → 放油量=重量/密度 → 标记完成
|
||||
B_DB_Opera.QueryLatestRecord(opName, engineNo,
|
||||
out long recordId, out _, out decimal addOil, out decimal extractOil, out decimal dens);
|
||||
curveWeighingRecordId = recordId; // 曲线记录最终关联这条称重记录
|
||||
oilReleaseQty = dens > 0 ? weight / dens : 0; // 地面:油桶重量/密度=放油量
|
||||
residualOilQty = addOil - extractOil - oilReleaseQty; // 残油=加油-抽油-放油
|
||||
B_DB_Opera.UpdateWeighingComplete(recordId, "地面", opName,
|
||||
weight, oilReleaseQty, residualOilQty, waterContent, out finalQualityFlag, out qualityMsg);
|
||||
B_DB_Opera.SaveLog_Response(
|
||||
$"【{opName}】地面保存完成:发动机={engineNo},重量={weight}kg,放油量={oilReleaseQty:F4}L,残油量={residualOilQty:F4}L,合格标志={finalQualityFlag},{qualityMsg}", AID);
|
||||
WeighingPage?.UpdateOilResult(WeighingPage?.GetStationIndex(opName) ?? 1, oilReleaseQty, residualOilQty);
|
||||
WeighingPage?.AppendLog($"[{opName}] 保存完成:{engineNo},重量={weight:F2}kg,放油量={oilReleaseQty:F4}L");
|
||||
if (B_DB_Opera.QueryLatestRecord(opName, engineNo,
|
||||
out long recordId, out _, out decimal addOil, out decimal extractOil, out decimal dens))
|
||||
{
|
||||
curveWeighingRecordId = recordId; // 曲线记录最终关联这条称重记录
|
||||
oilReleaseQty = dens > 0 ? weight / dens : 0; // 地面:油桶重量/密度=放油量
|
||||
residualOilQty = addOil - extractOil - oilReleaseQty; // 残油=加油-抽油-放油
|
||||
B_DB_Opera.UpdateWeighingComplete(recordId, "地面", opName,
|
||||
weight, oilReleaseQty, residualOilQty, waterContent, out finalQualityFlag, out qualityMsg);
|
||||
B_DB_Opera.SaveLog_Response(
|
||||
$"【{opName}】地面保存完成:发动机={engineNo},重量={weight}kg,放油量={oilReleaseQty:F4}L,残油量={residualOilQty:F4}L,合格标志={finalQualityFlag},{qualityMsg}", AID);
|
||||
WeighingPage?.UpdateOilResult(WeighingPage?.GetStationIndex(opName) ?? 1, oilReleaseQty, residualOilQty);
|
||||
WeighingPage?.AppendLog($"[{opName}] 保存完成:{engineNo},重量={weight:F2}kg,放油量={oilReleaseQty:F4}L");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 兜底机制:请求工作阶段资料异常可能没有占位记录,保存时补一条异常完成记录,避免PLC等不到保存完成。
|
||||
curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "地面", engineNo, "", "", "",
|
||||
0, weight, 0, 0, 0, 0, 0, 0, 0, 2, waterContent,
|
||||
opName, Curr_UserName, isComplete: 1);
|
||||
finalQualityFlag = 2;
|
||||
qualityMsg = "未找到请求工作占位记录,已按异常地面记录保存";
|
||||
LogWeighingFallback(opName, engineNo, "请求保存-地面", qualityMsg, AID);
|
||||
}
|
||||
}
|
||||
else if (weighType == "放油前")
|
||||
{
|
||||
// 空中放油前:查最新记录 → 仅写入进站重量,不标记完成
|
||||
B_DB_Opera.QueryLatestRecord(opName, engineNo,
|
||||
out long recordId, out _, out _, out _, out _);
|
||||
curveWeighingRecordId = recordId; // 放油前曲线也关联同一条称重记录
|
||||
B_DB_Opera.UpdateWeighingComplete(recordId, "空中放油前", opName,
|
||||
weight, 0, 0, waterContent, out finalQualityFlag, out qualityMsg);
|
||||
B_DB_Opera.SaveLog_Response(
|
||||
$"【{opName}】空中放油前保存完成:发动机={engineNo},进站重量={weight}kg,合格标志={finalQualityFlag},{qualityMsg}", AID);
|
||||
WeighingPage?.AppendLog($"[{opName}] 放油前保存:{engineNo},重量={weight:F2}kg");
|
||||
if (B_DB_Opera.QueryLatestRecord(opName, engineNo,
|
||||
out long recordId, out _, out _, out _, out _))
|
||||
{
|
||||
curveWeighingRecordId = recordId; // 放油前曲线也关联同一条称重记录
|
||||
B_DB_Opera.UpdateWeighingComplete(recordId, "空中放油前", opName,
|
||||
weight, 0, 0, waterContent, out finalQualityFlag, out qualityMsg);
|
||||
B_DB_Opera.SaveLog_Response(
|
||||
$"【{opName}】空中放油前保存完成:发动机={engineNo},进站重量={weight}kg,合格标志={finalQualityFlag},{qualityMsg}", AID);
|
||||
WeighingPage?.AppendLog($"[{opName}] 放油前保存:{engineNo},重量={weight:F2}kg");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 兜底机制:没有占位记录时补异常记录并完成握手,后续放油后仍可按异常链路继续。
|
||||
curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "空中", engineNo, "", "", "",
|
||||
weight, 0, 0, 0, 0, 0, 0, 0, 0, 2, waterContent,
|
||||
opName, Curr_UserName, isComplete: 1);
|
||||
finalQualityFlag = 2;
|
||||
qualityMsg = "未找到请求工作占位记录,已按异常放油前记录保存";
|
||||
LogWeighingFallback(opName, engineNo, "请求保存-放油前", qualityMsg, AID);
|
||||
}
|
||||
}
|
||||
else // 放油后
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user