From 2e889843b4c171f2d6ad8e0d53084040703d11f6 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 09 十一月 2026 13:18:21 +0800
Subject: [PATCH] docs: CAN 总线级应答器 + 硬件调试页多标签多会话 设计规格

---
 HMI.UnitTest/MainWindow.xaml.cs |  291 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 215 insertions(+), 76 deletions(-)

diff --git a/HMI.UnitTest/MainWindow.xaml.cs b/HMI.UnitTest/MainWindow.xaml.cs
index cda9a3a..d0fbc30 100644
--- a/HMI.UnitTest/MainWindow.xaml.cs
+++ b/HMI.UnitTest/MainWindow.xaml.cs
@@ -1,30 +1,230 @@
 锘縰sing ConnectionUtil;
 using HMI.Core.Api;
 using HMI.Core.Util;
+using HMI.Simple.Util;
+using HslCommunication.Core.Pipe;
+using HslCommunication.Profinet.Siemens;
+using log4net;
+using Panuon.WPF.UI;
+using PLCHelper;
+using Plugin.DataBoard;
 using Plugin.TestResult_WPF;
+using Plugin.TsExecution;
+using Plugin.UICollection;
 using System;
+using System.IO;
 using System.Windows;
-
+using System.Xml.Linq;
 namespace UnitTest
 {
     /// <summary>
     /// MainWindow.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
-    public partial class MainWindow : Window
+    public partial class MainWindow : WindowX
     {
+        private ILog log = LogManager.GetLogger("UnitTest");
         public MainWindow()
         {
-            LangUtil.Load();
-            InitializeComponent();
+            //ProductModelHelper.GetModelBySNR("cc123", out string model, out string msg);
+            //LangUtil.Load();
+            //InitializeComponent();
+            ////RebuildDb();
+            //border2.Child = new TcpDebugger();
+
+            var client = new SiemensS7Net(SiemensPLCS.S1500);
+            PipeTcpNet pipeTcpNet = new PipeTcpNet("127.0.0.1", 102);
+            pipeTcpNet.ConnectTimeOut = 200;
+            pipeTcpNet.ReceiveTimeOut = 200;
+            client.CommunicationPipe = pipeTcpNet;
+            client.ConnectServer();
+
+            var ss = new IntReader(client, "DB10.DBW100", 0);
+            ss.DataChanged += Ss_DataChanged;
+            ss.Run();
+
+
+
+
             //page.Children.Add(new UserControl1());
+        }
+
+        private void Ss_DataChanged(object sender, DataChangedArg<int> e)
+        {
+            MessageBox.Show($"{e.oldValue} => {e.newValue}");
         }
 
         TcpClientWrapper tcpClient;
 
         PipeClient2 client;
 
+        public string Conv(object obj)
+        {
+            if (obj == null || obj is DBNull)
+            {
+                return "NULL";
+            }
+            if (obj is DateTime dt)
+            {
+                return $"'{dt.ToString("yyyy-MM-dd HH:mm:ss")}'";
+            }
+            return $"'{obj.ToString()}'";
+        }
+
+
+        public void RebuildDb()
+        {
+            string folder = "C:\\Workspace\\VisualStudio\\WPFProject\\WPFProject\\bin\\x64\\Debug\\Config\\DataBoard";
+            var startDate = DateTime.Parse("2025-10-01");
+            var endDate = startDate.AddDays(1);
+            SqliteHelper sourceHelper = new SqliteHelper("C:\\Workspace\\VisualStudio\\WPFProject\\WPFProject\\bin\\x64\\Debug\\Config\\DataBoard\\DataLog.db");
+
+            while (endDate < DateTime.Parse("2025-10-12"))
+            {
+                string targetFile = Path.Combine(folder, $"Data_{startDate.ToString("yyyyMMdd")}.db");
+                SqliteHelper targetHelper = null;
+                if (!File.Exists(targetFile))
+                {
+                    SqliteHelper.CreateDatabase(targetFile);
+                    targetHelper = new SqliteHelper(targetFile);
+                    targetHelper.ExecuteSql(@"CREATE TABLE IF NOT EXISTS serialData (
+                    id INTEGER PRIMARY KEY AUTOINCREMENT,
+                    sn TEXT NOT NULL,
+                    model TEXT,
+                    station TEXT NOT NULL,
+                    step TEXT NOT NULL,
+                    position TEXT,
+                    limitDown TEXT,
+                    limitUp TEXT,
+                    unit TEXT,
+                    offset TEXT,
+                    value TEXT,
+                    status TEXT,
+                    finalStatus TEXT,
+                    consumeTime TEXT, 
+                    totalConsumeTime TEXT, 
+                    time DATETIME NOT NULL);");
+                    targetHelper.ExecuteSql(@"CREATE TABLE IF NOT EXISTS testResult (
+                    id INTEGER PRIMARY KEY AUTOINCREMENT,
+                    sn TEXT NOT NULL,
+                    model TEXT,
+                    station TEXT NOT NULL,
+                    position TEXT,
+                    status TEXT,
+                    result TEXT NOT NULL, 
+                    time DATETIME NOT NULL);");
+
+                    string sql = $@"SELECT sn,model,station,step,position,limitDown,limitUp,unit,offset,value,status,
+finalStatus,consumeTime,totalConsumeTime,time
+FROM serialData WHERE time>='{startDate.ToString("yyyy-MM-dd")}' AND time < '{endDate.ToString("yyyy-MM-dd")}';";
+
+                    var dt = sourceHelper.GetDataTable(sql);
+                    foreach (System.Data.DataRow dr in dt.Rows)
+                    {
+                        targetHelper.ExecuteSql($@"INSERT INTO serialData 
+(sn,model,station,step,position,limitDown,limitUp,unit,offset,value,status,finalStatus,consumeTime,totalConsumeTime,time) VALUES
+({Conv(dr["sn"])}, {Conv(dr["model"])}, {Conv(dr["station"])}, {Conv(dr["step"])}, {Conv(dr["position"])}, {Conv(dr["limitDown"])}, {Conv(dr["limitUP"])},
+{Conv(dr["unit"])}, {Conv(dr["offset"])}, {Conv(dr["value"])}, {Conv(dr["status"])}, {Conv(dr["finalStatus"])}, {Conv(dr["consumeTime"])}, 
+{Conv(dr["totalConsumeTime"])}, {Conv(dr["time"])})");
+                    }
+                    sql = $@"SELECT sn,model,station,position,status,result,time FROM testResult WHERE time>='{startDate.ToString("yyyy-MM-dd")}' 
+AND time < '{endDate.ToString("yyyy-MM-dd")}';";
+
+                    dt = sourceHelper.GetDataTable(sql);
+                    foreach (System.Data.DataRow dr in dt.Rows)
+                    {
+                        targetHelper.ExecuteSql($@"INSERT INTO testResult 
+(sn,model,station,position,status,result,time) VALUES
+({Conv(dr["sn"])}, {Conv(dr["model"])}, {Conv(dr["station"])}, {Conv(dr["position"])}, {Conv(dr["status"])}, {Conv(dr["result"])}, {Conv(dr["time"])})");
+                    }
+
+                    targetHelper.Dispose();
+                    startDate = startDate.AddDays(1);
+                    endDate = endDate.AddDays(1);
+                }
+            }
+            sourceHelper.Dispose();
+        }
+
         private void Button_Click(object sender, RoutedEventArgs e)
         {
+            //var win = new ManualDebug()
+            //{
+            //    seqPath = "C:\\Users\\chrry\\Desktop\\鎵嬪姩璋冭瘯绀轰緥.seq"
+            //};
+
+            //win.Show();
+
+            //Task.Run(() =>
+            //{
+            //    for (int j = 0; j < 1000; j++)
+            //    {
+            //        string status = (j % 2 == 0) ? "Passed" : "Failed";
+            //        string d = (j % 2 == 0) ? "9" : "9999999999999999999999999999999999999999999999999999999999999999995";
+            //        tsExecution.AddTestData(0, $"ConnectivityCANRec,2,3,4,{d},6,{status}");
+            //        Thread.Sleep(5);
+            //    }
+            //});
+
+            //Task.Run(() =>
+            //{
+            //    for (int j = 0; j < 1000; j++)
+            //    {
+            //        string status = (j % 2 == 0) ? "Passed" : "Failed";
+            //        string d = (j % 2 == 0) ? "9" : "9999999999999999999999999999999999999999999999999999999999999999995";
+            //        tsExecution.AddTestData(1, $"ConnectivityCANRec,2,3,4,{d},6,{status}");
+            //        Thread.Sleep(5);
+            //    }
+            //});
+
+            //Task.Run(() =>
+            //{
+            //    for (int j = 0; j < 1000; j++)
+            //    {
+            //        string status = (j % 2 == 0) ? "Passed" : "Failed";
+            //        string d = (j % 2 == 0) ? "9" : "9999999999999999999999999999999999999999999999999999999999999999995";
+            //        tsExecution.AddTestData(2, $"ConnectivityCANRec,2,3,4,{d},6,{status}");
+            //        Thread.Sleep(5);
+            //    }
+            //});
+
+            //Task.Run(() =>
+            //{
+            //    for (int j = 0; j < 1000; j++)
+            //    {
+            //        string status = (j % 2 == 0) ? "Passed" : "Failed";
+            //        string d = (j % 2 == 0) ? "9" : "9999999999999999999999999999999999999999999999999999999999999999995";
+            //        tsExecution.AddTestData(3, $"ConnectivityCANRec,2,3,4,{d},6,{status}");
+            //        Thread.Sleep(5);
+            //    }
+            //});
+
+            //Task.Run(() =>
+            //{
+            //    for (int j = 0; j < 1000; j++)
+            //    {
+            //        string status = (j % 2 == 0) ? "Passed" : "Failed";
+            //        string d = (j % 2 == 0) ? "9" : "9999999999999999999999999999999999999999999999999999999999999999995";
+            //        tsExecution.AddTestData(1, $"ConnectivityCANRec,2,3,4,{d},6,{status}");
+            //        Thread.Sleep(5);
+            //    }
+            //});
+
+            //tsExecution.UpdatePositionStatus(0, "Passed");
+            //tsExecution.UpdatePositionStatus(0, "Failed");
+            //tsExecution.UpdatePositionProcessValue(0, 12);
+            //tsExecution.PausePosition(0);
+            //tsExecution.SetPositionBarcode(0, "123456789");
+            //tsExecution.SavePositionCSV(0);
+
+
+            //tsExecution.UpdatePositionStatus(1, "Failed");
+            //tsExecution.UpdatePositionStatus(2, "Ready");
+            //tsExecution.UpdatePositionStatus(3, "Testing");
+            //tsExecution.UpdatePositionProcessValue(1, 50);
+            //tsExecution.UpdatePositionProcessValue(2, 100);
+            //tsExecution.UpdatePositionProcessValue(3, 99);
+
+
             //client = new PipeClient2("DAService");
             ////client.OnData += Client_OnData1;
             //client.Connect();
@@ -32,7 +232,7 @@
             //tcpClient = new TcpClientWrapper("127.0.0.1", 5555);
             //tcpClient.Connect();
 
-            viewControl.View.GetDataTable(0).GetSingleCell(0).SetStatus("testing");
+            //viewControl.View.GetDataTable(0).GetSingleCell(0).SetStatus("testing");
 
             //new Thread(new ThreadStart(PipeServerMessage)).Start();
             //new Thread(new ThreadStart(PipeClientMessage)).Start();
@@ -43,79 +243,13 @@
             Console.WriteLine($"{e.Data}");
         }
 
-        private void Client_OnData(object sender, PipeDataEventArgs e)
-        {
-            Dispatcher.Invoke(() =>
-            {
-                console.Text += e.Data;
-            });
-        }
-
-        private void Button_Click2(object sender, RoutedEventArgs e)
-        {
-            var allStart = DateTime.Now;
-            for (int i = 0; i < 100; i++)
-            {
-                var start = DateTime.Now;
-                if (client.SendMessage("ping", out string res))
-                {
-                    var interval = (DateTime.Now - start).TotalMilliseconds;
-                    Console.WriteLine($"{interval}: {res}");
-                }
-            }
-            Console.WriteLine($"Total: {(DateTime.Now - allStart).TotalMilliseconds}");
-        }
-
-        private void Button_Click3(object sender, RoutedEventArgs e)
-        {
-            try
-            {
-                var allStart = DateTime.Now;
-                for (int i = 0; i < 500; i++)
-                {
-                    var start = DateTime.Now;
-                    string data = input.Text;
-                    string str = $"{{\"command\":5,\"value\":{data},\"id\":\"DITag0\"}}\r\n";
-                    string res = tcpClient.SendMessage(str);
-                    var interval = (DateTime.Now - start).TotalMilliseconds;
-                    Console.WriteLine($"{interval}: {res}");
-                }
-                Console.WriteLine($"Total: {(DateTime.Now - allStart).TotalMilliseconds}");
-            }
-            catch (Exception ex)
-            {
-
-            }
-        }
-
-        private void Button_Click4(object sender, RoutedEventArgs e)
-        {
-            try
-            {
-                var allStart = DateTime.Now;
-                for (int i = 0; i < 500; i++)
-                {
-                    var start = DateTime.Now;
-                    string data = input.Text;
-                    string str = $"{{\"command\":5,\"value\":{data},\"id\":\"DITag0\"}}";
-                    client.SendMessage(str, out string res);
-                    var interval = (DateTime.Now - start).TotalMilliseconds;
-                    Console.WriteLine($"{interval}: {res}");
-                }
-                Console.WriteLine($"Total: {(DateTime.Now - allStart).TotalMilliseconds}");
-
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine(ex.StackTrace);
-            }
-        }
 
         private void HandlePlugin(object obj)
         {
             if (obj is IPlugin plugin)
             {
-                plugin.SetBaseFolder(PathHelper.AppFolder);
+                plugin.SetBaseFolder("C:\\Workspace\\VisualStudio\\WPFProject\\WPFProject\\bin\\x64\\Debug\\Config\\TsExecution");
+                plugin.SetLogger(log);
                 plugin.InitFinish();
             }
 
@@ -123,11 +257,16 @@
 
         private ViewControl viewControl;
 
+        private TsExecution tsExecution;
+
+        private DataBoard dataBoard;
+
         private void Window_Loaded(object sender, RoutedEventArgs e)
         {
-            viewControl = new ViewControl();
-            HandlePlugin(viewControl);
-            border.Child = viewControl;
+            //var plugin = new TsExecution();
+            //HandlePlugin(plugin);
+            //border.Child = plugin;
+            //tsExecution = plugin;
             this.Loaded -= Window_Loaded;
         }
     }

--
Gitblit v1.9.1