From c02845ddc3af315248a67decd5e76b7029a126d3 Mon Sep 17 00:00:00 2001 From: 17351662861 Date: Fri, 23 May 2025 08:53:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4scan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ScanControlViewModel.cs | 10 +++++----- .../Util/ScanHelper/ComScanHelper.cs | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/ViewModels/ScanControlViewModel.cs b/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/ViewModels/ScanControlViewModel.cs index 0bbf742..47472ba 100644 --- a/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/ViewModels/ScanControlViewModel.cs +++ b/RIZO_Application/Modules/RIZO_Application.Modules.ModuleName/ViewModels/ScanControlViewModel.cs @@ -111,11 +111,11 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels throw new ObjectDisposedException(nameof(ScanControlViewModel)); - //if (SerialConfigs.Current != null) - //{ - // comName = SerialConfigs.Current.ComName ?? string.Empty; - // baudRate = SerialConfigs.Current.BaudRate ?? 9600; - //} + if (SerialConfigs.Current != null) + { + comName = SerialConfigs.Current.ComName ?? string.Empty; + baudRate = SerialConfigs.Current.BaudRate ?? 9600; + } _eventAggregator.GetEvent().Publish($"串口扫码枪初始化……串口:{comName} 波特率:{baudRate}"); diff --git a/RIZO_Application/RIZO_Application.Infrastructure/Util/ScanHelper/ComScanHelper.cs b/RIZO_Application/RIZO_Application.Infrastructure/Util/ScanHelper/ComScanHelper.cs index 0e1333e..93cf573 100644 --- a/RIZO_Application/RIZO_Application.Infrastructure/Util/ScanHelper/ComScanHelper.cs +++ b/RIZO_Application/RIZO_Application.Infrastructure/Util/ScanHelper/ComScanHelper.cs @@ -63,6 +63,11 @@ namespace RIZO_Helper.Tools _serialPort.DataReceived += OnSerialDataReceived; return true; } + catch (InvalidOperationException ex) + { + Debug.WriteLine($"打开串口 {_serialPort.PortName} 失败: {ex.Message}"); + return false; + } catch (OperationCanceledException) when (_disposeCts.IsCancellationRequested) { return false;