From 15bbd62b0b24b72c717ae91ab45348a2083ad04e Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 10 十月 2025 08:58:18 +0800
Subject: [PATCH] 优化bug;
---
Plugin.TestResult/Scanner.xaml.cs | 60 +++++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 39 insertions(+), 21 deletions(-)
diff --git a/Plugin.TestResult/Scanner.xaml.cs b/Plugin.TestResult/Scanner.xaml.cs
index 929b47a..f545677 100644
--- a/Plugin.TestResult/Scanner.xaml.cs
+++ b/Plugin.TestResult/Scanner.xaml.cs
@@ -1,5 +1,8 @@
-锘縰sing HMI.UI.Util;
+锘縰sing HMI.Core.Util;
+using HMI.UI.Util;
+using HMI.Util;
using Panuon.WPF.UI;
+using Plugin.TestResult.Model;
using System;
using System.ComponentModel;
using System.IO.Ports;
@@ -59,26 +62,36 @@
{
string comStr = "";
if (serialPort != null) return;
- if (this.title == "涓�鍖烘壂鐮�")
+
+ string section = this.Tag.ToString();
+ ScannerConfig common = ScannerConfig.ReadFromIni(ViewControl.SannerIniFile, "Config");
+
+ string portName = IniFileHelper.ReadIniData(section, "PortName", "", ViewControl.SannerIniFile);
+ if (string.IsNullOrEmpty(portName))
{
- comStr = "COM1";
+ if (section.StartsWith("A"))
+ {
+ portName = "COM1";
+ }
+ else
+ {
+ portName = "COM2";
+ }
}
- else
- {
- comStr = "COM2";
- }
+ common.PortName = portName;
+
// 閰嶇疆涓插彛
serialPort = new SerialPort
{
- PortName = comStr,
- BaudRate = 115200,
+ PortName = common.PortName,
+ BaudRate = common.BaudRate,
Parity = Parity.None,
- DataBits = 8,
- StopBits = StopBits.One,
+ DataBits = common.DataBits,
+ StopBits = common.StopBits,
Handshake = Handshake.None,
- DtrEnable = true,
- RtsEnable = true
+ DtrEnable = common.DtrEnable,
+ RtsEnable = common.RtsEnable
//ReadTimeout = 500,
//WriteTimeout = 500,
//ReciveBufferSize=4096
@@ -93,7 +106,8 @@
}
catch (Exception ex)
{
- MsgBoxHelper.Error(this, $"鍒濆鍖栨壂鐮佹灙澶辫触锛亄ex.StackTrace}");
+ ViewControl.Logger.Error("Init Scan Gun Failed.", ex);
+ MsgBoxHelper.Error(this, $"{this.lang("Tr.InitGunFailed")}: {ex.StackTrace}");
}
}
@@ -123,7 +137,8 @@
}
catch (Exception ex)
{
- MessageBox.Show($"鑾峰彇鎵爜鏋暟鎹け璐ワ紒{ex.StackTrace}");
+ ViewControl.Logger.Error("Get Scan Gun Data Failed.", ex);
+ MessageBox.Show($"{this.lang("Tr.GetGunData")}: {ex.StackTrace}");
}
}
@@ -134,19 +149,20 @@
string position = positionText.Text, snr = snrText.Text;
if (string.IsNullOrEmpty(position) || string.IsNullOrEmpty(snr))
{
- MessageBox.Show("璇疯緭鍏ュ偍浣嶆潯鐮佸拰浜у搧鏉$爜");
+ ToastHelper.Warning(this, this.lang("Tr.PleaseInputSnrs"));
return;
}
try
{
- FinishBarcode.Invoke(this, new BarcodeEventArg(title, position, snr));
+ FinishBarcode.Invoke(this, new BarcodeEventArg(Tag.ToString(), position, snr));
//positionText.Text = "";
//snrText.Text = "";
positionText.Focus();
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message);
+ ViewControl.Logger.Error("Con_Click Failed.", ex);
+ ToastHelper.Warning(this, ex.Message);
}
});
}
@@ -156,17 +172,18 @@
string position = positionText.Text, snr = snrText.Text;
if (string.IsNullOrEmpty(position) || string.IsNullOrEmpty(snr))
{
- MessageBox.Show("璇疯緭鍏ュ偍浣嶆潯鐮佸拰浜у搧鏉$爜");
+ ToastHelper.Warning(this, this.lang("Tr.PleaseInputSnrs"));
return;
}
try
{
- FinishBarcode.Invoke(this, new BarcodeEventArg(title, position, snr));
+ FinishBarcode.Invoke(this, new BarcodeEventArg(Tag.ToString(), position, snr));
this.Close();
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message);
+ ViewControl.Logger.Error("Con_Click Failed.", ex);
+ ToastHelper.Warning(this, ex.Message);
}
}
@@ -188,6 +205,7 @@
try
{
serialPort.Close();
+ serialPort = null;
}
catch (Exception ex)
{
--
Gitblit v1.9.1