工具表定模块 使用科学计数法

This commit is contained in:
XingCheng3
2026-05-12 13:28:37 +08:00
parent 36a4084d3a
commit 08b0d4e5e3
9 changed files with 261 additions and 67 deletions

View File

@@ -233,9 +233,6 @@ namespace MesWork
}
// ====================================================================
// 称重业务数据库方法(调用存储过程,统一 result/msg 返回格式)
// ====================================================================
/// <summary>
/// 根据订货号匹配工件管理规则,查询机型参数(加油量/抽油量/密度/残油量上下限)
@@ -263,6 +260,52 @@ namespace MesWork
return false;
}
/// <summary>
/// 查询指定工位的工具标定配置。
/// </summary>
public static bool QueryToolCalibration(string opName, out string toolName, out string calibrationValue, out string formula, out string description, out string msg)
{
toolName = "";
calibrationValue = "";
formula = "";
description = "";
msg = "";
try
{
using (var conn = new SqlConnection(MesWorkForm.ConnectionString))
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = @"
SELECT TOP 1 [工具名称], [重量标定], [计算公式], [说明]
FROM [工具管理]
WHERE [工位号] = @工位号
ORDER BY [ID]";
cmd.Parameters.Add(new SqlParameter("@工位号", opName ?? ""));
conn.Open();
using (var reader = cmd.ExecuteReader())
{
if (!reader.Read())
{
msg = $"未找到[{opName}]工具标定配置";
return false;
}
toolName = reader["工具名称"]?.ToString() ?? "";
calibrationValue = reader["重量标定"]?.ToString() ?? "";
formula = reader["计算公式"]?.ToString() ?? "";
description = reader["说明"]?.ToString() ?? "";
return true;
}
}
}
catch (Exception err)
{
msg = $"查询[{opName}]工具标定配置失败:{err.Message}";
return false;
}
}
/// <summary>
/// 插入称重记录
/// </summary>

View File

@@ -24,6 +24,7 @@ namespace MesWork
public decimal? StableWeight;
public int? StableStartSeq;
public int? StableEndSeq;
public DateTime LastCalibrationErrorLogTime;
}
private static readonly ConcurrentDictionary<string, CurveCollectorState> _curveCollectors
@@ -76,7 +77,7 @@ namespace MesWork
}
/// <summary>
/// 采集线程200ms读取一次实时重量缓存到内存,保存时一次性写库。
/// 采集线程200ms读取一次实时重量先按工具标定公式计算,再缓存到内存,保存时一次性写库。
/// </summary>
private void CurveCollector_Work(CurveCollectorState state)
{
@@ -84,7 +85,17 @@ namespace MesWork
{
try
{
decimal weight = Convert.ToDecimal(ReadPLC(100220, state.OpName)); // 实时重量点位
decimal rawWeight = Convert.ToDecimal(ReadPLC(100220, state.OpName)); // 实时重量点位
if (!WeightCalibrationHelper.Apply(state.OpName, rawWeight, out decimal weight, out _, out string msg))
{
if ((DateTime.Now - state.LastCalibrationErrorLogTime).TotalSeconds >= 5)
{
state.LastCalibrationErrorLogTime = DateTime.Now;
WeighingPage?.AppendLog($"[{state.OpName}] 曲线采样标定失败:{msg}");
}
Thread.Sleep(CurveCollectorSampleIntervalMs);
continue;
}
lock (state.BufferLock)
{
state.Buffer.Add(new CurveSamplePoint
@@ -139,7 +150,7 @@ namespace MesWork
}
/// <summary>
/// 优先用曲线点计算稳定重量失败时调用方继续使用PLC锁定重量。
/// 优先用已标定曲线点计算稳定重量失败时调用方继续使用PLC锁定重量。
/// </summary>
private bool CurveCollector_TryGetStableWeight(string opName, out decimal weight, out int pointCount, out string msg)
{

View File

@@ -177,7 +177,7 @@ namespace MesWork
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))
out decimal residualOilUpperLimit, out decimal residualOilLowerLimit)) // 根据订货号 查询基本参数
{
WritePLC_IF(112, opName, 3); // 报警代码=3机型错误
B_DB_Opera.SaveLog_Response($"【{opName}】工件管理中未找到订货号[{orderNo}]的匹配规则,发动机={engineNo}", AID);
@@ -252,18 +252,26 @@ namespace MesWork
engineNo = parsedProductNo;
}
if (CurveCollector_TryGetStableWeight(opName, out decimal curveWeight, out int curvePointCount, out string curveMsg))
{
weight = curveWeight; // 优先使用曲线稳定段计算重量
B_DB_Opera.SaveLog_Response($"【{opName}】曲线重量={curveWeight:F3}kgPLC重量={plcWeight:F3}kg差值={(curveWeight - plcWeight):F3}kg点数={curvePointCount}", AID);
}
else
{
B_DB_Opera.SaveLog_Response($"【{opName}】曲线重量不可用使用PLC锁定重量={plcWeight:F3}kg原因={curveMsg}", AID);
}
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}kgPLC锁定重量={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); // 过站记录保存最终采用重量
string weighType = GetWeighingType(opName);
decimal oilReleaseQty = 0;
decimal residualOilQty = 0;