alielie
2025-11-21 3a471ae651b228231bebb3a2d438baa1d4ac0261
Plugin.DOControl/DOControl.xaml.cs
@@ -5,6 +5,7 @@
using HMI.UI;
using HMI.UI.Util;
using log4net;
using OPCConnection;
using Panuon.WPF.UI;
using Plugin.DOControl.Entity;
using System;
@@ -26,8 +27,8 @@
        /// <summary>
        /// 实例化服务器接口函数
        /// </summary>
        //private OpcInterface.OpcInterface lTSCADAApi = new OpcInterface.OpcInterface();
        private PipeClient pipeClient = new PipeClient("DAService");
        private SCADAApi lTSCADAApi = new OPCClient();
        //private PipeClient pipeClient = new PipeClient("DAService");
        private ObservableCollection<string> groups;
        public ObservableCollection<string> Groups
@@ -99,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; }
@@ -376,24 +383,24 @@
        /// <param name="value">值</param>
        private void SetPlcValue(string key, string value)
        {
            //if (!lTSCADAApi.DoFctWriteSingle(key, value, out string errMsg))
            //{
            //    ToastHelper.Error(this, errMsg);
            //}
            if (!lTSCADAApi.DoFctWriteSingle(key, value, out string errMsg))
            {
                ToastHelper.Error(this, errMsg);
            }
            pipeClient.SendMessage("asdsadasda", out _);
            //lTSCADAApi.SendMessage("asdsadasda", out _);
        }
        private string GetPlcValue(string key)
        {
            //if (lTSCADAApi.DoFctReadSingle(key, out string Val, out string errMsg))
            //{
            //    return Val;
            //}
            //else
            //{
            //    return null;
            //}
            if (lTSCADAApi.DoFctReadSingle(key, out string Val, out string errMsg))
            {
                return Val;
            }
            else
            {
                return null;
            }
            return null;
        }
@@ -450,25 +457,25 @@
            LoadData();
            if (SystemSetting.Instance.PlcEnabled)
            {
                //if (lTSCADAApi.Connect2("127.0.0.1", 6543, 18888, out string errMsg))
                //{
                //    motorMonitorTimer.Enabled = true;
                //    RefreshControl();
                //}
                //else
                //{
                //    MsgBoxHelper2.Error(errMsg);
                //}
                try
                if (lTSCADAApi.Connect2("127.0.0.1", 6543, 28888, out string errMsg))
                {
                    pipeClient.OnConnected += PipeClient_OnConnected;
                    motorMonitorTimer.Enabled = true;
                    RefreshControl();
                }
                else
                {
                    MsgBoxHelper2.Error(errMsg);
                }
                //try
                //{
                //    pipeClient.OnConnected += PipeClient_OnConnected;
                    pipeClient.Connect();
                }
                catch (Exception ex)
                {
                    MsgBoxHelper.Error(this, ex.Message);
                }
                //    pipeClient.Connect();
                //}
                //catch (Exception ex)
                //{
                //    MsgBoxHelper.Error(this, ex.Message);
                //}
            }
            Loaded -= UserControl_Loaded;
        }