master
杨威 3 months ago
parent 89bc3a566b
commit cc5c5cfa42

@ -1,4 +1,6 @@
namespace NDSD_Screwdriver using System;
namespace NDSD_Screwdriver
{ {
using System.Configuration; using System.Configuration;
public class AppTool public class AppTool
@ -12,5 +14,8 @@
{ {
return ConfigurationManager.AppSettings["db"].ToString(); return ConfigurationManager.AppSettings["db"].ToString();
} }
public static String GetCom=> ConfigurationManager.AppSettings["com"].ToString();
} }
} }

@ -87,8 +87,17 @@ namespace NDSD_Screwdriver
MessageBox.Show("服务端打开失败!"); MessageBox.Show("服务端打开失败!");
FormUtils.LogInsert(LogContext, "服务端打开失败"); 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) private void MainForm_FormClosed(object sender, FormClosedEventArgs e)

@ -123,7 +123,7 @@
<Compile Include="FormUtils.cs" /> <Compile Include="FormUtils.cs" />
<Compile Include="TestDataFactory.cs" /> <Compile Include="TestDataFactory.cs" />
<Compile Include="Tool\MyFixedHeaderRequestInfo.cs" /> <Compile Include="Tool\MyFixedHeaderRequestInfo.cs" />
<Compile Include="Tool\SerialPortFactory.cs" /> <Compile Include="Tool\SerialPortFactory1.cs" />
<EmbeddedResource Include="FrmSetting.resx"> <EmbeddedResource Include="FrmSetting.resx">
<DependentUpon>FrmSetting.cs</DependentUpon> <DependentUpon>FrmSetting.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

@ -15,7 +15,7 @@ namespace NDSD_Screwdriver.Tool
{ {
SerialPortClient clientSerialPortClient = new SerialPortClient(); SerialPortClient clientSerialPortClient = new SerialPortClient();
private IWaitingClient<ISerialPortClient, IReceiverResult> waitClient; private IWaitingClient<ISerialPortClient, IReceiverResult> waitClient;
public SerialPortFactory(string portName="COM13") public SerialPortFactory(string portName)
{ {
clientSerialPortClient.Connecting = (client, e) => EasyTask.CompletedTask;//即将连接到端口 clientSerialPortClient.Connecting = (client, e) => EasyTask.CompletedTask;//即将连接到端口
clientSerialPortClient.Connected = (client, e) => { return EasyTask.CompletedTask; };//成功连接到端口 clientSerialPortClient.Connected = (client, e) => { return EasyTask.CompletedTask; };//成功连接到端口
@ -25,7 +25,7 @@ namespace NDSD_Screwdriver.Tool
BaudRate = 115200, //波特率 BaudRate = 115200, //波特率
DataBits = 8, //数据位 DataBits = 8, //数据位
Parity = System.IO.Ports.Parity.None, //校验位 Parity = System.IO.Ports.Parity.None, //校验位
PortName = "COM13", //COM PortName =portName,
StopBits = System.IO.Ports.StopBits.One //停止位 StopBits = System.IO.Ports.StopBits.One //停止位
}).SetSerialDataHandlingAdapter(() => new MyFixedHeaderCustomDataHandlingAdapter())); }).SetSerialDataHandlingAdapter(() => new MyFixedHeaderCustomDataHandlingAdapter()));
Loading…
Cancel
Save