Browse Source

修改扭力点检

wanghan 7 tháng trước cách đây
mục cha
commit
e187462464

+ 1 - 1
TeamAAS-VM/Models/TorqueTest.cs → TeamAAS-VM/Models/Torque/TorqueTest.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace TeamAAS_VP.Models
+namespace TeamAAS_VP.Models.Torque
 {
     /// <summary>
     /// 扭力点检参数

+ 15 - 18
TeamAAS-VM/Services/TorqueService.cs

@@ -56,40 +56,36 @@ namespace TeamAAS_VP.Services
         }
 
 
-        public async void Save_Torque_Log(string fileName, string content)
+        public async Task Save_Torque_Log(string content)
         {
             try
             {
-                if (!File.Exists(TorqueParametrPath))
+                if (File.Exists(TorqueParametrPath))
                 {
                     Directory.CreateDirectory(TorqueParametrPath);
                 }
                 bool Is_Exists = File.Exists(CurrentVariableCSV);
                 if (!Is_Exists)
                 {
-                    Directory.CreateDirectory(CurrentVariableCSV);
+                    using (File.Create(CurrentVariableCSV)) { }
                 }
-
-                using (FileStream fs = new FileStream(CurrentVariableCSV, FileMode.Append, FileAccess.Write))
+                using (StreamWriter sw = new StreamWriter(CurrentVariableCSV, true))
                 {
-                    using (StreamWriter sw = new StreamWriter(fs))
+                    if (!Is_Exists)
+                    {
+                        //初始化文件,写入标题行
+                        sw.WriteLine("Time,扭力仪测量值,电批读取值,当前差值,设置差值,结果");
+                        sw.WriteLine(content);
+                    }
+                    else
                     {
-                        if (!Is_Exists)
-                        {
-                            //初始化文件,写入标题行
-                            sw.WriteLine("Time,...");
-                            sw.WriteLine("Time,...");
-                        }
-                        else
-                        {
-                            sw.WriteLine("Time,...");
-                        }
+                        sw.WriteLine(content);
                     }
                 }
-
             }
             catch (Exception)
             {
+                MessageBox.Show("写入数据失败");
 
             }
         }
@@ -146,6 +142,8 @@ namespace TeamAAS_VP.Services
 
             result.Add(await BackZero_Async(Robot, point));
 
+            await Task.Delay(500);
+
             result.Add(await Task.Run(() =>
             {
                 return (bool)plc.ReadNode(addressConfig.InWork.Address);
@@ -171,7 +169,6 @@ namespace TeamAAS_VP.Services
 
             result.Add(await plc.WriteNodeAsync(addressConfig.Check_ScrewTorque.Address, true));
 
-            //result.Add(await Robot.JogAsync("Z", Z_Distance));
             point.Z = PlcPoint.TorquePoints[2].Z_Position_Stop;
 
             Robot.Go(point);

+ 1 - 1
TeamAAS-VM/TeamAAS-VP.csproj

@@ -540,7 +540,7 @@
     <Compile Include="Models\Torque\PlcPoint_Torque.cs" />
     <Compile Include="Models\PhotoCaptureRecord.cs" />
     <Compile Include="Models\ScrewFeederBatchRecord.cs" />
-    <Compile Include="Models\TorqueTest.cs" />
+    <Compile Include="Models\Torque\TorqueTest.cs" />
     <Compile Include="Models\Torque\Torque_TaskStatus.cs" />
     <Compile Include="Models\Torque\TorqueProduceModel.cs" />
     <Compile Include="Resources\Languages\Lang.Designer.cs">

+ 34 - 22
TeamAAS-VM/ViewModels/Home/TorqueCheckViewModel.cs

@@ -394,7 +394,7 @@ namespace TeamAAS_VP.ViewModels.Home
             SelectedPoint.X_Position = curpos.X;
             SelectedPoint.Y_Position = curpos.Y;
             SelectedPoint.Z_Position_Start = curpos.Z;
-            //SelectedPoint.Z_Position_Stop = curpos.Z - (float)this.Z_Distance;
+
             SelectedPoint.Z_Position_Stop = 0;
 
             AllProductParameter.TorqueValue = this.TorqueValue;
@@ -417,8 +417,14 @@ namespace TeamAAS_VP.ViewModels.Home
             var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
 
             res.TorqueValue = this.TorqueValue;
-
-            FileHelper.WriteJsonFile(res, FilePath.TorqueCheckPath);
+            try
+            {
+                FileHelper.WriteJsonFile(res, FilePath.TorqueCheckPath);
+            }
+            catch (Exception)
+            {
+                MessageBox.Show("修改失败");
+            }
             _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.4 });
         }
 
@@ -441,8 +447,12 @@ namespace TeamAAS_VP.ViewModels.Home
             {
                 if (await MoveRobot())
                 {
-                    
-                }                    
+                    _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.4 });
+                }
+                else
+                {
+                    _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.失败, Duration = 0.4 });
+                }
             }
             catch (Exception ex)
             {
@@ -456,11 +466,12 @@ namespace TeamAAS_VP.ViewModels.Home
         /// <returns></returns>
         public async Task<bool> MoveRobot()
         {
-            var Plc_Point = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
+            TorqueProduceModel Plc_Point = new TorqueProduceModel();
             PlcAddressConfig addressConfig = _configService.GetPlcAddresses();
             OpcUaClientPLC plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
             try
             {
+                Plc_Point = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
                 if (Plc_Point == null || addressConfig == null || plc == null)
                 {
                     return false;
@@ -496,7 +507,7 @@ namespace TeamAAS_VP.ViewModels.Home
                     }
                     MessageBox.Show("执行回安全点失败"); return false;
                 }
-                MessageBox.Show("点检失败");return false;
+                MessageBox.Show("点检失败"); return false;
             }
             catch (Exception ex)
             {
@@ -513,7 +524,7 @@ namespace TeamAAS_VP.ViewModels.Home
         {
             try
             {
-                Thread.Sleep(100);
+                await Task.Delay(100);
                 TValue = management.SignalValue;
                 double tvalue = double.Parse(TValue.Split(' ')[0]);
                 double pvalue = Value;
@@ -521,7 +532,7 @@ namespace TeamAAS_VP.ViewModels.Home
                 SubValue = $"{Math.Round(Math.Abs(tvalue - pvalue), 3)} kgf.cm";
                 double sub = Math.Abs(tvalue - pvalue);
 
-                var res = FileHelper.ReadJsonFile<TorqueTest>(FilePath.TorqueCheckPath);
+                var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
                 if (res != null)
                 {
                     if (sub <= res.TorqueValue)
@@ -548,6 +559,8 @@ namespace TeamAAS_VP.ViewModels.Home
                         Result = "NG";
                     }
                 }
+                await _torqueService.Save_Torque_Log($"{DateTime.Now},{TValue},{PValue},{Math.Round(sub, 4)},{TorqueValue},{Result}");
+                SendTaskMessage("点检扭矩成功", MessageLevel.Info);
             }
             catch (Exception ex)
             {
@@ -555,19 +568,15 @@ namespace TeamAAS_VP.ViewModels.Home
             }
         }
 
-        public void Save_Torque_Parameter()
-        { 
-        }
-
         public async Task<bool> WatchAsync(OpcUaClientPLC plc, PlcAddressConfig addressConfig)
         {
-            Thread.Sleep(100);
             object oking = null;
             object nging = null;
             int count = 0;
 
-            while (count++ < 10)
+            while (count++ < 20)
             {
+                await Task.Delay(100);
                 oking = plc.ReadNode(addressConfig.Screw_OK.Address);
                 nging = plc.ReadNode(addressConfig.Screw_NG.Address);
 
@@ -618,12 +627,8 @@ namespace TeamAAS_VP.ViewModels.Home
         {
             try
             {
-                var res = FileHelper.ReadJsonFile<TorqueTest>(FilePath.TorqueCheckPath);
-                if (res != null)
-                {
-                    res.TorqueValue = TorqueValue;
-                }
-                else
+                var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
+                if (res == null)
                 {
                     MessageBox.Show("还未示教,请先示教");
                 }
@@ -632,7 +637,6 @@ namespace TeamAAS_VP.ViewModels.Home
             {
                 MessageBox.Show("还未示教,请先示教");
             }
-
             if (Robot == null)
             {
                 Robot = _robotService.GetRobotByNumber(1);
@@ -704,6 +708,14 @@ namespace TeamAAS_VP.ViewModels.Home
         }
         #endregion
 
+        private void SendTaskMessage(string msg, MessageLevel level)
+        {
+            App.Current.Dispatcher.Invoke(() =>
+            {
+                _eventAggregator.GetEvent<TaskMessageNotification>().Publish(new Models.MessageStruct() { Message = msg, level = level });
+            });
+        }
+
         private void ExecuteSavePointsCommand()
         {
             AllProductParameter.TorqueValue = this.TorqueValue;

+ 2 - 3
TeamAAS-VM/Views/Home/TorqueCheck.xaml

@@ -543,18 +543,17 @@
                 </Grid>
 
                 <Button Content="{lex:Loc 执行}"
-                        Grid.RowSpan="2"
                         VerticalContentAlignment="Center"
                         materialDesign:ButtonAssist.CornerRadius="10"
                         Style="{StaticResource MaterialDesignRaisedDarkButton}"
                         Command="{Binding WorkCommand}"
                         Margin="15,5"
-                        Grid.Row="3" />
+                        Grid.Row="4" />
 
                 <TextBlock Text="{Binding Result}"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
-                           Grid.Row="4"
+                           Grid.Row="3"
                            FontSize="30"
                            Foreground="{Binding FontColor}" />