From a66828ce4fde703a3e6d9bc9c7b30d41b9d96249 Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 24 Apr 2024 16:23:11 +0800 Subject: [PATCH] =?UTF-8?q?change-=E7=95=8C=E9=9D=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/MainWindowViewModel.cs | 145 +++++++++--------- Aucma.Core.CodeBinding/appsettings.json | 4 +- .../ViewModels/StatisticsPageViewModel.cs | 6 +- Aucma.Core.Palletiz/Views/IndexPageView.xaml | 105 ++++++------- Aucma.Core.Palletiz/appsettings.json | 10 +- .../ViewModels/StatisticsPageViewModel.cs | 6 +- .../Views/IndexPageView.xaml | 6 +- .../ViewModels/MainWindowViewModel.cs | 29 +++- Aucma.Core.ProductOffLine/appsettings.json | 4 +- .../ViewModels/MainWindowViewModel.cs | 26 +++- Aucma.Core.ProductOffLineCX1/appsettings.json | 8 +- 11 files changed, 183 insertions(+), 166 deletions(-) diff --git a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs index 15271326..50452852 100644 --- a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs @@ -67,74 +67,71 @@ namespace Aucma.Core.CodeBinding.ViewModels TouchSocketService.RefreshStateEvent += RefreshScanner; GunBusiness.InstanceSerialPort3(); - updatePlcState(); - // InitHikRobot(); + init(); + } - private void updatePlcState() + + #region 初始化班组刷新定时任务 + public void init() { - Task.Run(() => - { - Thread.Sleep(4000); - var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); - if (obj.plc.IsConnected) - { - PlcState(true); - } - else - { - PlcState(false); - } - }); + // 设备状态刷新定时器 + System.Timers.Timer timer = new System.Timers.Timer(1000 * 5); + timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshStatus); + timer.AutoReset = true; + timer.Enabled = true; + timer.Start(); } + #endregion + #region 开启海康扫码器 - public void InitHikRobot() - { - try - { - Task.Run(() => - { - Thread.Sleep(2000); + //public void InitHikRobot() + //{ + // try + // { + // Task.Run(() => + // { + // Thread.Sleep(2000); - Business.MvCodeHelper.Shell(); + // Business.MvCodeHelper.Shell(); - }); - - Task.Run(() => - { - Thread.Sleep(4000); - try - { - var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); - if (obj != null) - { - PlcState(true); - } - else - { - PlcState(false); - } - - }catch (Exception ex) - { - PlcState(false); - } + // }); + + // Task.Run(() => + // { + // Thread.Sleep(4000); + // try + // { + // var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); + // if (obj != null) + // { + // PlcState(true); + // } + // else + // { + // PlcState(false); + // } + + // }catch (Exception ex) + // { + // PlcState(false); + // } - Business.MvCodeHelper.Liner(); - }); - - } - catch (Exception ex) - { - log.Error("InitHikRobot()开启海康扫码器和扫码枪方法异常" + ex.Message.ToString()); - //MvCodeHelper.CloseAllDevice(); - //InitHikRobot(); - } - } + // Business.MvCodeHelper.Liner(); + // }); + + // } + // catch (Exception ex) + // { + // log.Error("InitHikRobot()开启海康扫码器和扫码枪方法异常" + ex.Message.ToString()); + // //MvCodeHelper.CloseAllDevice(); + // //InitHikRobot(); + // } + //} #endregion @@ -156,31 +153,29 @@ namespace Aucma.Core.CodeBinding.ViewModels /// /// 设备状态刷新 /// - public Task RefreshStatus(bool mesState,bool plcState,bool scanner1,bool scanner2) + public void RefreshStatus(object sender, System.Timers.ElapsedEventArgs e) { - MesDbState(mesState); - PlcState(plcState); - // Scanner1State(scanner1); - // Scanner2State(scanner2); - return Task.CompletedTask; + + MesDbState(true); + RefreshPlc(); } - /// - /// 扫码器状态刷新 - /// - /// - /// - public void RefreshScanner() + + // 刷新plc状态 + public void RefreshPlc() { - string ip1 = Appsettings.app("Middleware", "Scanner1", "Ip"); - string ip2 = Appsettings.app("Middleware", "Scanner2", "Ip"); - // bool flag1 = MvCodeHelper.ConnectionStatus(ip1); - // bool flag2 = MvCodeHelper.ConnectionStatus(ip2); - Scanner1State(true); - Scanner2State(true); + var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); + if (obj.plc.IsConnected) + { + PlcState(true); + } + else + { + PlcState(false); + } } #endregion - + #region 更换界面 diff --git a/Aucma.Core.CodeBinding/appsettings.json b/Aucma.Core.CodeBinding/appsettings.json index 4c8a31fe..4b950bdf 100644 --- a/Aucma.Core.CodeBinding/appsettings.json +++ b/Aucma.Core.CodeBinding/appsettings.json @@ -223,8 +223,8 @@ "EquipName": "条码绑定Plc", "PlcType": "Melsec", "Enabled": true, - //"IP": "127.0.0.1", - // "Port": 6000 + // "IP": "127.0.0.1", + // "Port": 6000 "IP": "10.10.92.70", "Port": 2014 }, diff --git a/Aucma.Core.Palletiz/ViewModels/StatisticsPageViewModel.cs b/Aucma.Core.Palletiz/ViewModels/StatisticsPageViewModel.cs index 1e746e43..6e5cc58c 100644 --- a/Aucma.Core.Palletiz/ViewModels/StatisticsPageViewModel.cs +++ b/Aucma.Core.Palletiz/ViewModels/StatisticsPageViewModel.cs @@ -51,11 +51,7 @@ namespace Aucma.Core.Palletiz.ViewModels /// public void AddData(RecordInStore record) { - App.Current.Dispatcher.Invoke(() => - { - MaterialDataGrid.Add(record); - CountInstoreEvent?.Invoke(MaterialDataGrid.Count); - }); + LoadData(); } #region 加载DataGrid数据 diff --git a/Aucma.Core.Palletiz/Views/IndexPageView.xaml b/Aucma.Core.Palletiz/Views/IndexPageView.xaml index e9c6a4b2..e950f088 100644 --- a/Aucma.Core.Palletiz/Views/IndexPageView.xaml +++ b/Aucma.Core.Palletiz/Views/IndexPageView.xaml @@ -80,7 +80,7 @@ - + @@ -122,14 +122,23 @@ - + - + + + + +