diff --git a/Dll/log4net.dll b/Dll/log4net.dll new file mode 100644 index 0000000..ffc57e1 Binary files /dev/null and b/Dll/log4net.dll differ diff --git a/NDSD-Screwdriver/MainForm.cs b/NDSD-Screwdriver/MainForm.cs index a4d9cdd..9d8d31a 100644 --- a/NDSD-Screwdriver/MainForm.cs +++ b/NDSD-Screwdriver/MainForm.cs @@ -1,5 +1,7 @@ using DNSD_DB; using NDSD_Screwdriver.Entity; +using NDSD_Screwdriver.Tool; + using NDSD_TouchSocket; using System; using System.Collections.Generic; @@ -9,6 +11,7 @@ using System.Drawing; using System.Drawing.Text; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -55,6 +58,11 @@ namespace NDSD_Screwdriver "5555222233334444" }; + + SerialPortFactory serialPort; + + private CancellationTokenSource cancellationTokenSource; + public MainForm() { InitializeComponent(); @@ -64,7 +72,24 @@ namespace NDSD_Screwdriver MessageBox.Show("服务端打开失败!"); } + serialPort=new SerialPortFactory(); + + StartLongRunningTask(); } + + private void StartLongRunningTask() + { + cancellationTokenSource = new CancellationTokenSource(); + Task.Run(() => + { + while (!cancellationTokenSource.Token.IsCancellationRequested) + { + // 这里是你的长期运行逻辑 + Thread.Sleep(1000); // 模拟一些长时间的工作 + } + }, cancellationTokenSource.Token); + } + /// /// 打开DO测试 @@ -73,6 +98,9 @@ namespace NDSD_Screwdriver /// private void DOTest_Click(object sender, EventArgs e) { + + string str= serialPort.Read(); + ScrewdriverTest screwdriverTest = new ScrewdriverTest(server, DOperate); screwdriverTest.Show(); } diff --git a/NDSD-Screwdriver/NDSD_Screwdriver.csproj b/NDSD-Screwdriver/NDSD_Screwdriver.csproj index e8f126b..9954e5d 100644 --- a/NDSD-Screwdriver/NDSD_Screwdriver.csproj +++ b/NDSD-Screwdriver/NDSD_Screwdriver.csproj @@ -39,6 +39,9 @@ ..\packages\Chloe.SQLite.5.26.0\lib\net46\Chloe.SQLite.dll + + ..\Dll\log4net.dll + diff --git a/NDSD-Screwdriver/Tool/SerialPortFactory.cs b/NDSD-Screwdriver/Tool/SerialPortFactory.cs index 7064f51..ac93982 100644 --- a/NDSD-Screwdriver/Tool/SerialPortFactory.cs +++ b/NDSD-Screwdriver/Tool/SerialPortFactory.cs @@ -20,13 +20,16 @@ namespace NDSD_Screwdriver.Tool public string Read() { + + + + if (!serialPortModbus.IsOpen) { serialPortModbus.Open(); - var b= reader.Connect(serialPortModbus, 2000, 0); } - - + + var b = reader.Connect(serialPortModbus, 2000, 0); string str2 = ""; ushort[] array6 = reader.ReadTagMemory(ref str2, 28, 4);