alielie
2025-11-25 006c98e5650b530e5220f279c1e803fefe69d40d
Plugin.CurrentSensorControl/ControlPage.xaml.cs
@@ -5,6 +5,7 @@
using HMI.Core.Util;
using HMI.UI.Util;
using HMI.Util;
using HslCommunication.Profinet.Siemens;
using log4net;
using Microsoft.Win32;
using Plugin.CurrentSensorControl.Entity;
@@ -13,6 +14,7 @@
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Xml.Linq;
namespace Plugin.CurrentSensorControl
{
@@ -28,10 +30,33 @@
        private System.Timers.Timer timer;
        private System.Timers.Timer opcTimer;
        private SCADAApi api;
        public static ILog Logger { get; private set; }
        private volatile bool needRead = false;
        private SiemensS7Net api;
        private bool plcMute = false;
        public bool PlcMute
        {
            get => plcMute;
            set
            {
                try
                {
                    string name = $"PLC_Mute";
                    if (S7Context.WriteData(api, name, value))
                    {
                        plcMute = value;
                        OnPropertyChanged(nameof(PlcMute));
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
        public ControlPage()
        {
@@ -46,6 +71,7 @@
            opcTimer.Interval = 1000;
            S7Context.Init(SystemSetting.Instance.PlcIp, SystemSetting.Instance.PlcPort);
            api = S7Context.Get($"1");
            DataContext = this;
            InitializeComponent();
@@ -73,6 +99,19 @@
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            timer.Enabled = false;
            try
            {
                if (S7Context.GetData(api, "PLC_Mute", out object val))
                {
                    plcMute = (bool)val;
                    OnPropertyChanged("PlcMute");
                }
            }
            catch (Exception ex)
            {
            }
            try
            {
                foreach (var ctl in controls)
@@ -299,7 +338,7 @@
        private void DoDelete(SensorData data)
        {
            if (MsgBoxHelper2.WarnChoose("删除?") == MessageBoxResult.OK)
            if (MsgBoxHelper2.WarnChoose("确定要删除吗?") == MessageBoxResult.OK)
            {
                var index = Datasource.IndexOf(data);
                if (index >= 0)