master
杨威 3 months ago
parent 89bc3a566b
commit cc5c5cfa42

@ -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();
}
}

@ -87,9 +87,18 @@ namespace NDSD_Screwdriver
MessageBox.Show("服务端打开失败!");
FormUtils.LogInsert(LogContext, "服务端打开失败");
}
serialPort = new SerialPortFactory();
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)
{

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

@ -15,7 +15,7 @@ namespace NDSD_Screwdriver.Tool
{
SerialPortClient clientSerialPortClient = new SerialPortClient();
private IWaitingClient<ISerialPortClient, IReceiverResult> 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()));
Loading…
Cancel
Save