From fe2aa4880d5c9fd88088ad0ed81ebaca05629f5f Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 17:59:45 +0800
Subject: [PATCH] feat: 集成CAN驱动/模拟器 + 仪器仪表注册/硬件调试模块
---
Plugin.DOControl/DOControl.xaml.cs | 82 ++++++++++++++++++++++++++---------------
1 files changed, 52 insertions(+), 30 deletions(-)
diff --git a/Plugin.DOControl/DOControl.xaml.cs b/Plugin.DOControl/DOControl.xaml.cs
index 4ec40cc..405c4ff 100644
--- a/Plugin.DOControl/DOControl.xaml.cs
+++ b/Plugin.DOControl/DOControl.xaml.cs
@@ -1,9 +1,11 @@
-锘縰sing HMI.Base;
+锘縰sing ConnectionUtil;
+using HMI.Base;
using HMI.Core.Setting;
using HMI.Core.Util;
using HMI.UI;
using HMI.UI.Util;
using log4net;
+using OPCConnection;
using Panuon.WPF.UI;
using Plugin.DOControl.Entity;
using System;
@@ -13,7 +15,6 @@
using System.Linq;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Documents;
using System.Windows.Media;
namespace Plugin.DOControl
@@ -26,7 +27,8 @@
/// <summary>
/// 瀹炰緥鍖栨湇鍔″櫒鎺ュ彛鍑芥暟
/// </summary>
- private OpcInterface.OpcInterface lTSCADAApi = new OpcInterface.OpcInterface();
+ private SCADAApi lTSCADAApi = new OPCClient();
+ //private PipeClient pipeClient = new PipeClient("DAService");
private ObservableCollection<string> groups;
public ObservableCollection<string> Groups
@@ -98,8 +100,14 @@
public override void DoClose(object sender, EventArgs e)
{
- motorMonitorTimer.Enabled = false;
- base.DoClose(sender, e);
+ try
+ {
+
+ motorMonitorTimer.Enabled = false;
+ base.DoClose(sender, e);
+ }
+ catch {
+ }
}
public static string FilePath { get; private set; }
@@ -124,15 +132,14 @@
private void LoadData()
{
+ ObservableCollection<DOControlData> datas = new ObservableCollection<DOControlData>();
try
{
motorMonitorTimer.Enabled = false;
- ObservableCollection<DOControlData> datas = new ObservableCollection<DOControlData>();
if (File.Exists(FilePath))
{
datas = XmlHelper.DeserializeFromXml<ObservableCollection<DOControlData>>(FilePath);
}
- Datasource = datas;
GroupMap = datas.GroupBy(x => x.Group)
.ToDictionary(
group => group.Key,
@@ -157,6 +164,7 @@
{
motorMonitorTimer.Enabled = true;
}
+ Datasource = datas;
}
private void MotorMonitorTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
@@ -174,7 +182,7 @@
string value = GetPlcValue(data.Address);
switch (data.ControlType)
{
- case ControlType.Button:
+ case ControlType.BOOL:
var color = Application.Current.FindResource("VerBar") as Brush;
if (value == data.PressDownValue)
{
@@ -183,12 +191,12 @@
((Button)ui).Background = color;
((Button)ui).Content = value;
break;
- case ControlType.Int16:
- case ControlType.Int32:
- case ControlType.Real:
- case ControlType.LReal:
- case ControlType.String:
- case ControlType.WString:
+ case ControlType.INT:
+ case ControlType.WORD:
+ case ControlType.REAL:
+ case ControlType.LREAL:
+ case ControlType.STRING:
+ case ControlType.WSTRING:
((Button)ui).Content = value;
break;
default:
@@ -235,19 +243,14 @@
FrameworkElement ui = null;
switch (data.ControlType)
{
- case ControlType.Button:
- case ControlType.ClickButton:
+ case ControlType.BOOL:
+ case ControlType.PULSE:
ui = CreateButton(data);
break;
- case ControlType.Int16:
- case ControlType.Int32:
- case ControlType.Real:
- case ControlType.LReal:
- case ControlType.String:
- case ControlType.WString:
- ui = CreateNumberInput(data);
+ case ControlType.TIME:
break;
default:
+ ui = CreateInput(data);
break;
}
if (ui != null)
@@ -294,11 +297,11 @@
MinWidth = 180,
MinHeight = 40
};
- if (data.ControlType == ControlType.Button)
+ if (data.ControlType == ControlType.BOOL)
{
btn.Click += ControlButton_Click;
}
- else if (data.ControlType == ControlType.ClickButton)
+ else if (data.ControlType == ControlType.PULSE)
{
btn.Content = data.Address;
btn.PreviewMouseLeftButtonDown += Btn_MouseLeftButtonDown;
@@ -341,7 +344,7 @@
}
}
- private Button CreateNumberInput(DOControlData data)
+ private Button CreateInput(DOControlData data)
{
Style btnStyle = Application.Current.FindResource("PrimaryButton") as Style;
var tb = new Button
@@ -361,7 +364,7 @@
return tb;
}
- if (data.ControlType == ControlType.String || data.ControlType == ControlType.WString)
+ if (data.ControlType == ControlType.STRING || data.ControlType == ControlType.WSTRING)
{
tb.Click += StringInput_Click;
}
@@ -382,8 +385,10 @@
{
if (!lTSCADAApi.DoFctWriteSingle(key, value, out string errMsg))
{
- throw new Exception(errMsg);
+ ToastHelper.Error(this, errMsg);
}
+
+ //lTSCADAApi.SendMessage("asdsadasda", out _);
}
private string GetPlcValue(string key)
@@ -396,6 +401,7 @@
{
return null;
}
+ return null;
}
private void ControlButton_Click(object sender, RoutedEventArgs args)
@@ -437,7 +443,8 @@
NumberPanel np = new NumberPanel
{
Title = data.Name,
- Owner = Window.GetWindow(this)
+ Owner = Window.GetWindow(this),
+ DotEnabled = data.ControlType == ControlType.REAL || data.ControlType == ControlType.LREAL
};
if (np.Open(tb.Content?.ToString()) == true)
{
@@ -450,7 +457,7 @@
LoadData();
if (SystemSetting.Instance.PlcEnabled)
{
- if (lTSCADAApi.Connect2("127.0.0.1", 6543, 18888, out string errMsg))
+ if (lTSCADAApi.Connect2("127.0.0.1", 6543, 28888, out string errMsg))
{
motorMonitorTimer.Enabled = true;
RefreshControl();
@@ -459,10 +466,25 @@
{
MsgBoxHelper2.Error(errMsg);
}
+ //try
+ //{
+ // pipeClient.OnConnected += PipeClient_OnConnected;
+
+ // pipeClient.Connect();
+ //}
+ //catch (Exception ex)
+ //{
+ // MsgBoxHelper.Error(this, ex.Message);
+ //}
}
Loaded -= UserControl_Loaded;
}
+ private void PipeClient_OnConnected(object sender, EventArgs e)
+ {
+
+ }
+
private void Button_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
--
Gitblit v1.9.1