From 559890c482f5973f06aafdfec9550fee5ba3c7f2 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 09 十一月 2026 17:02:15 +0800
Subject: [PATCH] feat: CAN 模拟器 TCP 化 + 多设备并发调试 + 后台生命周期管理
---
HMI.UnitTest/MainWindow.xaml.cs | 131 ++++++++++++-------------------------------
1 files changed, 38 insertions(+), 93 deletions(-)
diff --git a/HMI.UnitTest/MainWindow.xaml.cs b/HMI.UnitTest/MainWindow.xaml.cs
index 2c18c54..d0fbc30 100644
--- a/HMI.UnitTest/MainWindow.xaml.cs
+++ b/HMI.UnitTest/MainWindow.xaml.cs
@@ -2,17 +2,19 @@
using HMI.Core.Api;
using HMI.Core.Util;
using HMI.Simple.Util;
+using HslCommunication.Core.Pipe;
+using HslCommunication.Profinet.Siemens;
using log4net;
-using ModBusTcp;
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.Threading;
-using System.Threading.Tasks;
using System.Windows;
+using System.Xml.Linq;
namespace UnitTest
{
/// <summary>
@@ -23,29 +25,32 @@
private ILog log = LogManager.GetLogger("UnitTest");
public MainWindow()
{
- ProductModelHelper.GetModelBySNR("cc123", out string model, out string msg);
- LangUtil.Load();
- InitializeComponent();
- //RebuildDb();
+ //ProductModelHelper.GetModelBySNR("cc123", out string model, out string msg);
+ //LangUtil.Load();
+ //InitializeComponent();
+ ////RebuildDb();
+ //border2.Child = new TcpDebugger();
- ModBusTcpController controller = new ModBusTcpController("127.0.0.1", 502);
- if (controller.Start(out msg)) {
- bool res;
- int? target;
+ 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();
- controller.WriteBool("1", true, out msg);
- controller.ReadDOBool("1", out res, out msg);
- Console.WriteLine(res);
- controller.ReadDOInt("1", out target, out msg);
- Console.WriteLine(target);
- controller.WriteInt("1", 1, out msg);
- controller.ReadDOInt("1", out target, out msg);
- Console.WriteLine(target);
- Console.WriteLine(target);
- }
+ 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;
@@ -142,6 +147,13 @@
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++)
@@ -198,7 +210,7 @@
//});
//tsExecution.UpdatePositionStatus(0, "Passed");
- tsExecution.UpdatePositionStatus(0, "Failed");
+ //tsExecution.UpdatePositionStatus(0, "Failed");
//tsExecution.UpdatePositionProcessValue(0, 12);
//tsExecution.PausePosition(0);
//tsExecution.SetPositionBarcode(0, "123456789");
@@ -231,73 +243,6 @@
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)
{
@@ -318,10 +263,10 @@
private void Window_Loaded(object sender, RoutedEventArgs e)
{
- var plugin = new TsExecution();
- HandlePlugin(plugin);
- border.Child = plugin;
- tsExecution = plugin;
+ //var plugin = new TsExecution();
+ //HandlePlugin(plugin);
+ //border.Child = plugin;
+ //tsExecution = plugin;
this.Loaded -= Window_Loaded;
}
}
--
Gitblit v1.9.1