From 99df058a665ea04065a23e729ec79a2f23f79881 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期二, 20 五月 2025 16:59:43 +0800
Subject: [PATCH] 优化

---
 Plugin.TestResult/Scanner.xaml.cs |   37 +++++++++++++++++++++++++------------
 1 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/Plugin.TestResult/Scanner.xaml.cs b/Plugin.TestResult/Scanner.xaml.cs
index 72c0bd4..f545677 100644
--- a/Plugin.TestResult/Scanner.xaml.cs
+++ b/Plugin.TestResult/Scanner.xaml.cs
@@ -1,6 +1,8 @@
 锘縰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;
@@ -60,26 +62,36 @@
         {
             string comStr = "";
             if (serialPort != null) return;
-            if (this.Tag == "Zone1")
+
+            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
@@ -193,6 +205,7 @@
             try
             {
                 serialPort.Close();
+                serialPort = null;
             }
             catch (Exception ex)
             {

--
Gitblit v1.9.1