增加工位号兼容功能 不依赖固定的 OP10 OP20做硬编码判定 通过App.config作为工位依据
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
<add key="IsWriteLog4" value="1"/>
|
||||
<!--称重类型:Ground=地面称重(两独立工位), Hanging=空中称重/吊称(放油前+放油后)-->
|
||||
<add key="WeighingType" value="Hanging"/>
|
||||
<!--逻辑工位映射:必须与SignalTable_CZ.xlsx的设备类型对应表工位号一致-->
|
||||
<add key="Station1OpName" value="ST04"/>
|
||||
<add key="Station2OpName" value="ST05"/>
|
||||
<!--数据库连接-->
|
||||
<add key="ConnectionString" value="server=.,1333;database=MESBasicDB_WC_CZGKJ;uid=sa;pwd=126.com;Connection Reset=FALSE;Max Pool Size = 1000"/>
|
||||
<!--WebApi-->
|
||||
@@ -24,10 +27,10 @@
|
||||
|
||||
<!--扫码枪:1=启用, 0=禁用-->
|
||||
<add key="IsUseBarcode" value="0"/>
|
||||
<!--OP10扫码枪COM口,如COM3-->
|
||||
<add key="OP10BarCOM" value="COM2"/>
|
||||
<!--OP20扫码枪COM口,如COM4-->
|
||||
<add key="OP20BarCOM" value="COM3"/>
|
||||
<!--工位1扫码枪COM口,如COM3-->
|
||||
<add key="Station1BarCOM" value="COM2"/>
|
||||
<!--工位2扫码枪COM口,如COM4-->
|
||||
<add key="Station2BarCOM" value="COM3"/>
|
||||
<!--扫码枪波特率-->
|
||||
<add key="BarcodeBaudRate" value="9600"/>
|
||||
|
||||
|
||||
@@ -57,18 +57,28 @@ namespace MesWork
|
||||
/// </summary>
|
||||
public static string WeighingType = AppSettings["WeighingType"] ?? "Hanging";
|
||||
|
||||
/// <summary>
|
||||
/// 工位1现场工位号,Hanging模式下代表放油前工位
|
||||
/// </summary>
|
||||
public static string Station1OpName = AppSettings["Station1OpName"] ?? "";
|
||||
|
||||
/// <summary>
|
||||
/// 工位2现场工位号,Hanging模式下代表放油后工位
|
||||
/// </summary>
|
||||
public static string Station2OpName = AppSettings["Station2OpName"] ?? "";
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用扫码枪:1=启用, 0=禁用
|
||||
/// </summary>
|
||||
public static int IsUseBarcode = int.TryParse(AppSettings["IsUseBarcode"], out var _iub) ? _iub : 0;
|
||||
/// <summary>
|
||||
/// OP10扫码枪COM口(如COM3),空则不启用
|
||||
/// 工位1扫码枪COM口(如COM3),空则不启用
|
||||
/// </summary>
|
||||
public static string OP10BarCOM = AppSettings["OP10BarCOM"] ?? "";
|
||||
public static string Station1BarCOM = AppSettings["Station1BarCOM"] ?? "";
|
||||
/// <summary>
|
||||
/// OP20扫码枪COM口(如COM4),空则不启用
|
||||
/// 工位2扫码枪COM口(如COM4),空则不启用
|
||||
/// </summary>
|
||||
public static string OP20BarCOM = AppSettings["OP20BarCOM"] ?? "";
|
||||
public static string Station2BarCOM = AppSettings["Station2BarCOM"] ?? "";
|
||||
/// <summary>
|
||||
/// 扫码枪波特率
|
||||
/// </summary>
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace MesWork
|
||||
public static class BarcodeManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 扫码枪实例字典,key = opName(OP10/OP20)
|
||||
/// 扫码枪实例字典,key = opName
|
||||
/// </summary>
|
||||
public static Dictionary<string, BarcodeScanner> Scanners { get; } = new Dictionary<string, BarcodeScanner>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
@@ -33,27 +33,24 @@ namespace MesWork
|
||||
|
||||
int baudRate = MesWorkForm.BarcodeBaudRate;
|
||||
|
||||
// OP10
|
||||
string op10Com = MesWorkForm.OP10BarCOM?.Trim();
|
||||
if (!string.IsNullOrEmpty(op10Com))
|
||||
{
|
||||
var scanner = new BarcodeScanner("OP10", baudRate);
|
||||
scanner.BarcodeReceived += HandleBarcodeReceived;
|
||||
scanner.Log += HandleLog;
|
||||
Scanners["OP10"] = scanner;
|
||||
scanner.Connect(op10Com);
|
||||
InitScanner(MesWorkForm.Station1OpName, MesWorkForm.Station1BarCOM, baudRate);
|
||||
InitScanner(MesWorkForm.Station2OpName, MesWorkForm.Station2BarCOM, baudRate);
|
||||
}
|
||||
|
||||
// OP20
|
||||
string op20Com = MesWorkForm.OP20BarCOM?.Trim();
|
||||
if (!string.IsNullOrEmpty(op20Com))
|
||||
private static void InitScanner(string opName, string comPort, int baudRate)
|
||||
{
|
||||
var scanner = new BarcodeScanner("OP20", baudRate);
|
||||
opName = opName?.Trim();
|
||||
comPort = comPort?.Trim();
|
||||
if (string.IsNullOrEmpty(opName) || string.IsNullOrEmpty(comPort))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var scanner = new BarcodeScanner(opName, baudRate);
|
||||
scanner.BarcodeReceived += HandleBarcodeReceived;
|
||||
scanner.Log += HandleLog;
|
||||
Scanners["OP20"] = scanner;
|
||||
scanner.Connect(op20Com);
|
||||
}
|
||||
Scanners[opName] = scanner;
|
||||
scanner.Connect(comPort);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -137,14 +137,20 @@ namespace MesWork
|
||||
/// <summary>
|
||||
/// 获取称重类型:地面/放油前/放油后
|
||||
/// Ground模式:统一返回"地面"
|
||||
/// Hanging模式:OP10=放油前,OP20=放油后
|
||||
/// Hanging模式:工位1=放油前,工位2=放油后
|
||||
/// </summary>
|
||||
private string GetWeighingType(string opName)
|
||||
{
|
||||
if (WeighingType == "Ground")
|
||||
return "地面";
|
||||
// Hanging模式
|
||||
return opName == "OP10" ? "放油前" : "放油后";
|
||||
|
||||
if (string.Equals(opName, Station1OpName, StringComparison.OrdinalIgnoreCase))
|
||||
return "放油前";
|
||||
|
||||
if (string.Equals(opName, Station2OpName, StringComparison.OrdinalIgnoreCase))
|
||||
return "放油后";
|
||||
|
||||
throw new InvalidOperationException($"工位号[{opName}]未匹配到App.config中的Station1OpName/Station2OpName,请检查工位配置");
|
||||
}
|
||||
|
||||
|
||||
@@ -422,7 +428,7 @@ namespace MesWork
|
||||
}
|
||||
else
|
||||
{
|
||||
// 找不到放油前记录(可能直接进OP20):创建一条放油后记录并标记完成
|
||||
// 找不到放油前记录(可能直接进放油后工位):创建一条放油后记录并标记完成
|
||||
curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "空中放油后", engineNo, "", "", "",
|
||||
0, weight, 0, 0, 0, 0, 0, 0, 0, 2, waterContent,
|
||||
opName, Curr_UserName, isComplete: 1); // 异常兜底记录,质量直接判不合格
|
||||
@@ -458,7 +464,7 @@ namespace MesWork
|
||||
/// 扫码枪扫码完成后的业务处理
|
||||
/// 将码值写入PLC地址102500,触发完成信号100016=1,1秒后复位
|
||||
/// </summary>
|
||||
/// <param name="opName">工位号(OP10/OP20),由COM口绑定决定</param>
|
||||
/// <param name="opName">工位号,由COM口绑定决定</param>
|
||||
/// <param name="barcode">扫到的条码值</param>
|
||||
public void Barcode_HandleScan(string opName, string barcode)
|
||||
{
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace MesWork
|
||||
StationDisplayNames[opName] = $"{opName}-{dataSource}";
|
||||
stIdx++;
|
||||
}
|
||||
ValidateStationConfig();
|
||||
|
||||
LoadOPCData(dt_Tag_Mes, dt_Device, IsDemoMesServer, IsWriteMonitorLog, true, false, out string error);
|
||||
if (error.Length > 0)
|
||||
@@ -76,6 +77,35 @@ namespace MesWork
|
||||
B_DB_Opera.SaveLog_Request(Curr_Station, Log_Type.ZK_Login, "", Log_FromAndTo.ZK, Log_FromAndTo.ZK, $"称重系统启动成功!WebPort:[{MesWorkForm.WebApi_Port}]", out long AID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验App.config中的逻辑工位必须能匹配Excel启用工位,避免工位号配错后继续运行。
|
||||
/// </summary>
|
||||
private static void ValidateStationConfig()
|
||||
{
|
||||
string station1 = Station1OpName?.Trim();
|
||||
string station2 = Station2OpName?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(station1) || string.IsNullOrWhiteSpace(station2))
|
||||
{
|
||||
MessageBox.Show("App.config未配置Station1OpName或Station2OpName,程序不能启动。");
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
||||
if (string.Equals(station1, station2, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
MessageBox.Show($"App.config中Station1OpName和Station2OpName不能相同,当前均为[{station1}],程序不能启动。");
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
||||
bool hasStation1 = StationOpNames.Exists(x => string.Equals(x, station1, StringComparison.OrdinalIgnoreCase));
|
||||
bool hasStation2 = StationOpNames.Exists(x => string.Equals(x, station2, StringComparison.OrdinalIgnoreCase));
|
||||
if (!hasStation1 || !hasStation2)
|
||||
{
|
||||
string excelStations = string.Join("、", StationOpNames);
|
||||
MessageBox.Show($"App.config工位配置与SignalTable_CZ.xlsx不一致,程序不能启动。\r\nStation1OpName={station1}\r\nStation2OpName={station2}\r\nExcel启用工位={excelStations}");
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace MesWork.Pages
|
||||
/// </summary>
|
||||
public partial class UC_SystemSettings : UserControl
|
||||
{
|
||||
// OP10 控件
|
||||
// 工位1控件
|
||||
private ComboBox cmb_Com1;
|
||||
private Button btn_Connect1, btn_Disconnect1, btn_ManualSend1;
|
||||
private Label lbl_Status1, lbl_ScanTime1;
|
||||
private TextBox txt_Barcode1;
|
||||
|
||||
// OP20 控件
|
||||
// 工位2控件
|
||||
private ComboBox cmb_Com2;
|
||||
private Button btn_Connect2, btn_Disconnect2, btn_ManualSend2;
|
||||
private Label lbl_Status2, lbl_ScanTime2;
|
||||
@@ -26,19 +26,26 @@ namespace MesWork.Pages
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
string station1 = MesWorkForm.Station1OpName;
|
||||
string station2 = MesWorkForm.Station2OpName;
|
||||
grp_Station1.Text = $" 工位1({station1}) ";
|
||||
grp_Station2.Text = $" 工位2({station2}) ";
|
||||
grp_Scanner1.Text = $" {station1} 扫码枪 ";
|
||||
grp_Scanner2.Text = $" {station2} 扫码枪 ";
|
||||
|
||||
if (BarcodeManager.IsEnabled)
|
||||
{
|
||||
BuildScannerPanel(grp_Scanner1, "OP10", ref cmb_Com1, ref lbl_Status1, ref txt_Barcode1, ref lbl_ScanTime1,
|
||||
BuildScannerPanel(grp_Scanner1, station1, ref cmb_Com1, ref lbl_Status1, ref txt_Barcode1, ref lbl_ScanTime1,
|
||||
ref btn_Connect1, ref btn_Disconnect1, ref btn_ManualSend1);
|
||||
BuildScannerPanel(grp_Scanner2, "OP20", ref cmb_Com2, ref lbl_Status2, ref txt_Barcode2, ref lbl_ScanTime2,
|
||||
BuildScannerPanel(grp_Scanner2, station2, ref cmb_Com2, ref lbl_Status2, ref txt_Barcode2, ref lbl_ScanTime2,
|
||||
ref btn_Connect2, ref btn_Disconnect2, ref btn_ManualSend2);
|
||||
timer_Refresh.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
BuildScannerPanel(grp_Scanner1, "OP10", ref cmb_Com1, ref lbl_Status1, ref txt_Barcode1, ref lbl_ScanTime1,
|
||||
BuildScannerPanel(grp_Scanner1, station1, ref cmb_Com1, ref lbl_Status1, ref txt_Barcode1, ref lbl_ScanTime1,
|
||||
ref btn_Connect1, ref btn_Disconnect1, ref btn_ManualSend1);
|
||||
BuildScannerPanel(grp_Scanner2, "OP20", ref cmb_Com2, ref lbl_Status2, ref txt_Barcode2, ref lbl_ScanTime2,
|
||||
BuildScannerPanel(grp_Scanner2, station2, ref cmb_Com2, ref lbl_Status2, ref txt_Barcode2, ref lbl_ScanTime2,
|
||||
ref btn_Connect2, ref btn_Disconnect2, ref btn_ManualSend2);
|
||||
grp_Scanner1.Enabled = false;
|
||||
grp_Scanner2.Enabled = false;
|
||||
@@ -182,12 +189,12 @@ namespace MesWork.Pages
|
||||
|
||||
private async void btn_WeightClear1_Click(object sender, EventArgs e)
|
||||
{
|
||||
await DoWeightClearAsync("OP10", btn_WeightClear1);
|
||||
await DoWeightClearAsync(MesWorkForm.Station1OpName, btn_WeightClear1);
|
||||
}
|
||||
|
||||
private async void btn_WeightClear2_Click(object sender, EventArgs e)
|
||||
{
|
||||
await DoWeightClearAsync("OP20", btn_WeightClear2);
|
||||
await DoWeightClearAsync(MesWorkForm.Station2OpName, btn_WeightClear2);
|
||||
}
|
||||
|
||||
private async Task DoWeightClearAsync(string opName, Button btn)
|
||||
@@ -230,8 +237,8 @@ namespace MesWork.Pages
|
||||
|
||||
private void timer_Refresh_Tick(object sender, EventArgs e)
|
||||
{
|
||||
RefreshScannerStatus("OP10", lbl_Status1, txt_Barcode1, lbl_ScanTime1);
|
||||
RefreshScannerStatus("OP20", lbl_Status2, txt_Barcode2, lbl_ScanTime2);
|
||||
RefreshScannerStatus(MesWorkForm.Station1OpName, lbl_Status1, txt_Barcode1, lbl_ScanTime1);
|
||||
RefreshScannerStatus(MesWorkForm.Station2OpName, lbl_Status2, txt_Barcode2, lbl_ScanTime2);
|
||||
}
|
||||
|
||||
private void RefreshScannerStatus(string opName, Label lblStatus, TextBox txtBar, Label lblTime)
|
||||
|
||||
Reference in New Issue
Block a user