| | |
| | | using HMI.Base; |
| | | using 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; |
| | |
| | | using System.Linq; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | using System.Windows.Documents; |
| | | using System.Windows.Media; |
| | | |
| | | namespace Plugin.DOControl |
| | |
| | | /// <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 |
| | |
| | | |
| | | 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; } |
| | |
| | | |
| | | 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, |
| | |
| | | { |
| | | motorMonitorTimer.Enabled = true; |
| | | } |
| | | Datasource = datas; |
| | | } |
| | | |
| | | private void MotorMonitorTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) |
| | |
| | | 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) |
| | | { |
| | |
| | | ((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: |
| | |
| | | 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) |
| | |
| | | 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; |
| | |
| | | } |
| | | } |
| | | |
| | | private Button CreateNumberInput(DOControlData data) |
| | | private Button CreateInput(DOControlData data) |
| | | { |
| | | Style btnStyle = Application.Current.FindResource("PrimaryButton") as Style; |
| | | var tb = new Button |
| | |
| | | return tb; |
| | | } |
| | | |
| | | if (data.ControlType == ControlType.String || data.ControlType == ControlType.WString) |
| | | if (data.ControlType == ControlType.STRING || data.ControlType == ControlType.WSTRING) |
| | | { |
| | | tb.Click += StringInput_Click; |
| | | } |
| | |
| | | { |
| | | 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) |
| | |
| | | { |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private void ControlButton_Click(object sender, RoutedEventArgs args) |
| | |
| | | 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) |
| | | { |
| | |
| | | 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(); |
| | |
| | | { |
| | | 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; |