| | |
| | | using HMI.Base; |
| | | using ConnectionUtil; |
| | | using HMI.Base; |
| | | using HMI.Core.Entity; |
| | | using HMI.Core.Manager; |
| | | using HMI.Core.Setting; |
| | | using HMI.Core.Util; |
| | | using HMI.ParameterManage.Entity; |
| | | using HMI.ParameterManage.Util; |
| | | using HMI.UI; |
| | | using HMI.UI.Util; |
| | | using OPCConnection; |
| | | using Plugin.ServoManage.Entity; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | using System.Timers; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | using System.Windows.Threading; |
| | | |
| | | namespace Plugin.ServoManage |
| | | { |
| | |
| | | /// <summary> |
| | | /// 实例化服务器接口函数 |
| | | /// </summary> |
| | | private OpcInterface.OpcInterface lTSCADAApi = new OpcInterface.OpcInterface(); |
| | | private SCADAApi lTSCADAApi = new OPCClient(); |
| | | private bool isActived = false; |
| | | private System.Timers.Timer motorMonitorTimer; |
| | | |
| | | #region ServoData |
| | | private string enable; |
| | | [IsStatus] |
| | | public string Enable |
| | |
| | | Set(ref posCode, value); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | public ServoManage() |
| | | { |
| | | DataContext = this; |
| | | motorMonitorTimer = new System.Timers.Timer(); |
| | | motorMonitorTimer.Elapsed += MotorMonitorTimer_Elapsed; |
| | | motorMonitorTimer.Interval = 100; |
| | | InitializeComponent(); |
| | | } |
| | | |
| | | private void MotorMonitorTimer_Elapsed(object sender, ElapsedEventArgs e) |
| | | { |
| | | this.motorMonitorTimer.Enabled = false; |
| | | try |
| | | { |
| | | RefreshServoStatus(); |
| | | this.motorMonitorTimer.Enabled = true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | this.motorMonitorTimer.Enabled = true; |
| | | return; |
| | | } |
| | | RefreshServoStatus(); |
| | | } |
| | | |
| | | public override void SetBaseFolder(string folder) |
| | |
| | | { |
| | | if (lTSCADAApi.Connect2("127.0.0.1", 6543, 18888, out string errMsg)) |
| | | { |
| | | this.motorMonitorTimer.Interval = 100; |
| | | this.motorMonitorTimer.Start(); |
| | | motorMonitorTimer.Enabled = true; |
| | | isActived = true; |
| | | } |
| | | else |
| | |
| | | MsgBoxHelper2.Error(ex.Message); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | motorMonitorTimer.Enabled = true; |
| | | } |
| | | } |
| | | |
| | | public override void DeActive() |
| | | { |
| | | motorMonitorTimer.Enabled = false; |
| | | base.DeActive(); |
| | | } |
| | | |
| | | private void UserControl_Loaded(object sender, RoutedEventArgs e) |
| | |
| | | case "rfhServoBtn": |
| | | LoadData(); |
| | | break; |
| | | |
| | | case "addProductBtn": |
| | | OpenProductModal(null); |
| | | break; |
| | |
| | | public ObservableCollection<ServoProductData> ReadCommonProducts() |
| | | { |
| | | ObservableCollection<ServoProductData> datas = new ObservableCollection<ServoProductData>(); |
| | | List<ProductData> products = ParameterManager.GetProducts<List<ProductData>>(); |
| | | List<ProductData> products = ProductManager.GetProducts<List<ProductData>>(); |
| | | if (products != null && products.Count > 0) |
| | | { |
| | | foreach (var product in products) |
| | | { |
| | | var parameter = ParameterManager.GetParametersByProductName(product.Name) |
| | | var parameter = ProductManager.GetParametersByProductName(product.Name) |
| | | ?.FirstOrDefault(p => p.Name == "ProgramCode"); |
| | | if (parameter != null) |
| | | { |
| | |
| | | |
| | | private void RefreshServoStatus() |
| | | { |
| | | Dispatcher.Invoke(() => |
| | | this.motorMonitorTimer.Enabled = false; |
| | | try |
| | | { |
| | | if (SelectedServo == null) return; |
| | | PropertyInfo[] properties = this.GetType().GetProperties(); |
| | |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | if (prop.Name == "SelectedProduct") |
| | | Dispatcher.InvokeAsync(new Action(() => |
| | | { |
| | | var data = GetBitValue($"{SelectedServo.Name}_sRecipeCode"); |
| | | SelectedProduct = data; |
| | | } |
| | | else |
| | | { |
| | | var data = GetBitValue($"{SelectedServo.Name}_{prop.Name}"); |
| | | prop.SetValue(this, data); |
| | | } |
| | | if (prop.Name == "SelectedProduct") |
| | | { |
| | | var data = GetBitValue($"{SelectedServo.Name}_sRecipeCode"); |
| | | SelectedProduct = data; |
| | | } |
| | | else |
| | | { |
| | | var data = GetBitValue($"{SelectedServo.Name}_{prop.Name}"); |
| | | prop.SetValue(this, data); |
| | | } |
| | | }), DispatcherPriority.SystemIdle); |
| | | } |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | finally |
| | | { |
| | | this.motorMonitorTimer.Enabled = true; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | Button btn = sender as Button; |
| | | try |
| | | { |
| | | motorMonitorTimer.Enabled = false; |
| | | switch (btn.Tag) |
| | | { |
| | | case "Enable": |
| | |
| | | EnableDoClick(btn.Tag.ToString()); |
| | | break; |
| | | default: |
| | | DoSignClick(btn.Tag?.ToString()); |
| | | //DoSignClick(btn.Tag?.ToString()); |
| | | break; |
| | | } |
| | | } |
| | |
| | | } |
| | | finally |
| | | { |
| | | motorMonitorTimer.Enabled = true; |
| | | } |
| | | } |
| | | |
| | |
| | | SetBitValue($"{SelectedServo?.Name}_{tag}", np.Data?.ToString()); |
| | | } |
| | | } |
| | | |
| | | private void Button_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) |
| | | { |
| | | Button btn = sender as Button; |
| | | var tag = btn.Tag.ToString(); |
| | | try |
| | | { |
| | | motorMonitorTimer.Enabled = false; |
| | | SetBitValue($"{SelectedServo?.Name}_{tag}", "true"); |
| | | } |
| | | finally |
| | | { |
| | | motorMonitorTimer.Enabled = true; |
| | | } |
| | | } |
| | | |
| | | private void Button_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) |
| | | { |
| | | Button btn = sender as Button; |
| | | var tag = btn.Tag.ToString(); |
| | | try |
| | | { |
| | | motorMonitorTimer.Enabled = false; |
| | | SetBitValue($"{SelectedServo?.Name}_{tag}", "false"); |
| | | } |
| | | finally |
| | | { |
| | | motorMonitorTimer.Enabled = true; |
| | | } |
| | | } |
| | | } |
| | | } |