diff --git a/NDSD-Screwdriver/AppTool.cs b/NDSD-Screwdriver/AppTool.cs
index 02d3071..3345b40 100644
--- a/NDSD-Screwdriver/AppTool.cs
+++ b/NDSD-Screwdriver/AppTool.cs
@@ -1,4 +1,6 @@
-namespace NDSD_Screwdriver
+using System;
+
+namespace NDSD_Screwdriver
{
using System.Configuration;
public class AppTool
@@ -12,5 +14,8 @@
{
return ConfigurationManager.AppSettings["db"].ToString();
}
+
+ public static String GetCom=> ConfigurationManager.AppSettings["com"].ToString();
+
}
}
\ No newline at end of file
diff --git a/NDSD-Screwdriver/MainForm.cs b/NDSD-Screwdriver/MainForm.cs
index a9b474c..bf60452 100644
--- a/NDSD-Screwdriver/MainForm.cs
+++ b/NDSD-Screwdriver/MainForm.cs
@@ -87,8 +87,17 @@ namespace NDSD_Screwdriver
MessageBox.Show("服务端打开失败!");
FormUtils.LogInsert(LogContext, "服务端打开失败");
}
- serialPort = new SerialPortFactory();
- StartLongRunningTask();
+
+ try
+ {
+ serialPort = new SerialPortFactory(AppTool.GetCom);
+ StartLongRunningTask();
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message);
+ FormUtils.LogInsert(LogContext, e.Message);
+ }
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
diff --git a/NDSD-Screwdriver/NDSD_Screwdriver.csproj b/NDSD-Screwdriver/NDSD_Screwdriver.csproj
index 7b06ded..fa75ce9 100644
--- a/NDSD-Screwdriver/NDSD_Screwdriver.csproj
+++ b/NDSD-Screwdriver/NDSD_Screwdriver.csproj
@@ -123,7 +123,7 @@
-
+
FrmSetting.cs
diff --git a/NDSD-Screwdriver/Tool/SerialPortFactory.cs b/NDSD-Screwdriver/Tool/SerialPortFactory1.cs
similarity index 95%
rename from NDSD-Screwdriver/Tool/SerialPortFactory.cs
rename to NDSD-Screwdriver/Tool/SerialPortFactory1.cs
index 29503c7..bd97c8b 100644
--- a/NDSD-Screwdriver/Tool/SerialPortFactory.cs
+++ b/NDSD-Screwdriver/Tool/SerialPortFactory1.cs
@@ -15,7 +15,7 @@ namespace NDSD_Screwdriver.Tool
{
SerialPortClient clientSerialPortClient = new SerialPortClient();
private IWaitingClient waitClient;
- public SerialPortFactory(string portName="COM13")
+ public SerialPortFactory(string portName)
{
clientSerialPortClient.Connecting = (client, e) => EasyTask.CompletedTask;//即将连接到端口
clientSerialPortClient.Connected = (client, e) => { return EasyTask.CompletedTask; };//成功连接到端口
@@ -25,7 +25,7 @@ namespace NDSD_Screwdriver.Tool
BaudRate = 115200, //波特率
DataBits = 8, //数据位
Parity = System.IO.Ports.Parity.None, //校验位
- PortName = "COM13", //COM
+ PortName =portName,
StopBits = System.IO.Ports.StopBits.One //停止位
}).SetSerialDataHandlingAdapter(() => new MyFixedHeaderCustomDataHandlingAdapter()));