TorqueCheckViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. using MathNet.Numerics;
  2. using NPOI.OpenXml4Net.OPC.Internal;
  3. using NPOI.SS.Formula.Functions;
  4. using Org.BouncyCastle.Bcpg.Sig;
  5. using OxyPlot;
  6. using Prism.Commands;
  7. using Prism.Events;
  8. using Prism.Ioc;
  9. using Prism.Mvvm;
  10. using Prism.Services.Dialogs;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Collections.ObjectModel;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. using System.Windows;
  20. using TeamAAS_VP.Controls;
  21. using TeamAAS_VP.Core;
  22. using TeamAAS_VP.Core.PLCs;
  23. using TeamAAS_VP.Core.ScrewDriver;
  24. using TeamAAS_VP.Data;
  25. using TeamAAS_VP.Enums;
  26. using TeamAAS_VP.Events;
  27. using TeamAAS_VP.Interfaces;
  28. using TeamAAS_VP.Models;
  29. using TeamAAS_VP.Models.PLC;
  30. using TeamAAS_VP.Models.Torque;
  31. using TeamAAS_VP.Resources.Languages;
  32. using TeamAAS_VP.Services;
  33. using FileHelper = TeamAAS_VP.Core.FileHelper;
  34. namespace TeamAAS_VP.ViewModels.Home
  35. {
  36. public class TorqueCheckViewModel : BindableBase, IDialogAware
  37. {
  38. // 点检扭矩参数存放日志地址
  39. public static readonly string CheckTorqueConfigurationPath = "..//Log//ScrewFeedersConfiguration.cfg";
  40. IEventAggregator _eventAggregator;
  41. IConfigService _configService;
  42. IContainerProvider _container;
  43. IRobotService _robotService;
  44. IPlcService _plcService;
  45. TorqueService _torqueService;
  46. float Value { get; set; } = 0;
  47. #region 属性
  48. private Management _management;
  49. public Management management
  50. {
  51. get { return _management; }
  52. set { SetProperty(ref _management, value); }
  53. }
  54. private bool CanExecute
  55. {
  56. get
  57. {
  58. // 命令可执行仅当机器人可执行且已选择点位
  59. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  60. {
  61. return true;
  62. }
  63. return false;
  64. }
  65. }
  66. private IRobot _Robot;
  67. public IRobot Robot
  68. {
  69. get { return _Robot; }
  70. set { SetProperty(ref _Robot, value); }
  71. }
  72. private double _Distance = 1;
  73. public double Distance
  74. {
  75. get { return _Distance; }
  76. set
  77. {
  78. SetProperty(ref _Distance, value);
  79. try
  80. {
  81. if (Robot == null)
  82. {
  83. return;
  84. }
  85. _configService.UpdateRobotStepDistance(Robot.Id, value);
  86. }
  87. catch (Exception)
  88. {
  89. }
  90. }
  91. }
  92. private float _Z_Distance;
  93. public float Z_Distance
  94. {
  95. get { return _Z_Distance; }
  96. set { SetProperty(ref _Z_Distance, value); }
  97. }
  98. private float _torqueValue;
  99. public float TorqueValue
  100. {
  101. get { return _torqueValue; }
  102. set { SetProperty(ref _torqueValue, value); }
  103. }
  104. private string _TValue;
  105. public string TValue
  106. {
  107. get { return _TValue; }
  108. set
  109. {
  110. SetProperty(ref _TValue, value);
  111. }
  112. }
  113. private string _PValue;
  114. public string PValue
  115. {
  116. get { return _PValue; }
  117. set
  118. {
  119. SetProperty(ref _PValue, value);
  120. }
  121. }
  122. private string _SubValue;
  123. public string SubValue
  124. {
  125. get { return _SubValue; }
  126. set { SetProperty(ref _SubValue, value); }
  127. }
  128. private string _Result;
  129. public string Result
  130. {
  131. get { return _Result; }
  132. set { SetProperty(ref _Result, value); }
  133. }
  134. private string _FontColor;
  135. public string FontColor
  136. {
  137. get { return _FontColor; }
  138. set { SetProperty(ref _FontColor, value); }
  139. }
  140. private int _SelectedIndex;
  141. public int SelectedIndex
  142. {
  143. get { return _SelectedIndex; }
  144. set { SetProperty(ref _SelectedIndex, value); }
  145. }
  146. private ObservableCollection<PlcPoint_Torque> _Points = new ObservableCollection<PlcPoint_Torque>();
  147. /// <summary>
  148. /// 点位集合
  149. /// </summary>
  150. public ObservableCollection<PlcPoint_Torque> Points
  151. {
  152. get { return _Points; }
  153. set { SetProperty(ref _Points, value); }
  154. }
  155. private TorqueProduceModel _AllProductParameter = new TorqueProduceModel();
  156. /// <summary>
  157. /// 所有产品的参数信息
  158. /// </summary>
  159. public TorqueProduceModel AllProductParameter
  160. {
  161. get { return _AllProductParameter; }
  162. set { SetProperty(ref _AllProductParameter, value); }
  163. }
  164. private PlcPoint_Torque _selectedPointInDataGrid;
  165. public PlcPoint_Torque SelectedPointInDataGrid
  166. {
  167. get { return _selectedPointInDataGrid; }
  168. set
  169. {
  170. SetProperty(ref _selectedPointInDataGrid, value);
  171. // 可以同步到 SelectPoint 属性
  172. SelectedPoint = value;
  173. AllProductParameter.TorquePoints = _Points;
  174. }
  175. }
  176. private PlcPoint_Torque _SelectedPoint;
  177. public PlcPoint_Torque SelectedPoint
  178. {
  179. get { return _SelectedPoint; }
  180. set { SetProperty(ref _SelectedPoint, value); }
  181. }
  182. #endregion
  183. #region 命令
  184. private DelegateCommand _CancelCommand;
  185. public DelegateCommand CancelCommand =>
  186. _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  187. private DelegateCommand _LoadedCommand;
  188. public DelegateCommand LoadedCommand =>
  189. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  190. private DelegateCommand _ConfirmCommand;
  191. public DelegateCommand ConfirmCommand =>
  192. _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
  193. private DelegateCommand<string> _MotorCommand;
  194. public DelegateCommand<string> MotorCommand =>
  195. _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  196. private DelegateCommand<object> _JogCommand;
  197. public DelegateCommand<object> JogCommand =>
  198. _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  199. private DelegateCommand _TechPointCommand;
  200. public DelegateCommand TechPointCommand =>
  201. _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand));
  202. private DelegateCommand _MovePointCommand;
  203. public DelegateCommand MovePointCommand =>
  204. _MovePointCommand ?? (_MovePointCommand = new DelegateCommand(ExecuteMovePointCommand));
  205. private DelegateCommand _ModifyCommand;
  206. public DelegateCommand ModifyCommand =>
  207. _ModifyCommand ?? (_ModifyCommand = new DelegateCommand(ExecuteModifyCommand));
  208. private DelegateCommand _WorkCommand;
  209. public DelegateCommand WorkCommand =>
  210. _WorkCommand ?? (_WorkCommand = new DelegateCommand(ExecuteWorkCommand));
  211. private DelegateCommand _SavePointsCommand;
  212. public DelegateCommand SavePointsCommand =>
  213. _SavePointsCommand ?? (_SavePointsCommand = new DelegateCommand(ExecuteSavePointsCommand));
  214. #endregion
  215. #region 方法
  216. public TorqueCheckViewModel(IEventAggregator ea, IConfigService configService, TorqueService torqueService,
  217. IContainerProvider container, IRobotService robotService, IPlcService plcService)
  218. {
  219. _eventAggregator = ea;
  220. _configService = configService;
  221. _container = container;
  222. _robotService = robotService;
  223. _plcService = plcService;
  224. _torqueService = torqueService;
  225. management = _container.Resolve<Management>();
  226. }
  227. bool CanExecuteDeletePointCommand()
  228. {
  229. return SelectedPointInDataGrid != null;
  230. }
  231. void ExecuteCancelCommand()
  232. {
  233. IDialogParameters parameters = new DialogParameters();
  234. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
  235. }
  236. void ExecuteConfirmCommand()
  237. {
  238. IDialogParameters parameters = new DialogParameters();
  239. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
  240. }
  241. /// <summary>
  242. /// 电机
  243. /// </summary>
  244. /// <param name="obj"></param>
  245. private async void ExecuteMotorCommand(string obj)
  246. {
  247. if (Robot == null || !Robot.IsConnected) return;
  248. try
  249. {
  250. await Robot.MotorAsync(Convert.ToBoolean(obj));
  251. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  252. }
  253. catch (Exception ex)
  254. {
  255. LogHelper.WriteLogError("机器人点击操作时出错!", ex);
  256. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  257. }
  258. }
  259. /// <summary>
  260. /// 点动
  261. /// </summary>
  262. /// <param name="obj"></param>
  263. private async void ExecuteJogCommand(object obj)
  264. {
  265. if (Robot == null || !Robot.IsConnected) return;
  266. try
  267. {
  268. var items = ((string)obj).Split(':');
  269. //如果移动距离大于10mm,则提示用户确认
  270. double distance = double.Parse(items[1]);
  271. if (Math.Abs(distance) >= 10)
  272. {
  273. if (MessageBox.Show($"确认要点动距离 {distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  274. {
  275. return;
  276. }
  277. }
  278. Robot.Timeout = 6000000;
  279. switch (items[0])
  280. {
  281. case "X+":
  282. await Robot.JogAsync("X", distance);
  283. break;
  284. case "X-":
  285. await Robot.JogAsync("X", -distance);
  286. break;
  287. case "Y+":
  288. await Robot.JogAsync("Y", distance);
  289. break;
  290. case "Y-":
  291. await Robot.JogAsync("Y", -distance);
  292. break;
  293. case "Z+":
  294. await Robot.JogAsync("Z", distance);
  295. break;
  296. case "Z-":
  297. await Robot.JogAsync("Z", -distance);
  298. break;
  299. case "U+":
  300. await Robot.JogAsync("U", distance);
  301. break;
  302. case "U-":
  303. await Robot.JogAsync("U", -distance);
  304. break;
  305. case "V+":
  306. await Robot.JogAsync("V", distance);
  307. break;
  308. case "V-":
  309. await Robot.JogAsync("V", -distance);
  310. break;
  311. case "W+":
  312. await Robot.JogAsync("W", distance);
  313. break;
  314. case "W-":
  315. await Robot.JogAsync("W", -distance);
  316. break;
  317. default:
  318. break;
  319. }
  320. Robot.Timeout = 5000;
  321. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  322. }
  323. catch (Exception ex)
  324. {
  325. LogHelper.WriteLogError("机器人点位-机器人点动时出错", ex);
  326. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  327. }
  328. }
  329. /// <summary>
  330. /// 示教点位
  331. /// </summary>
  332. async void ExecuteTechPointCommand()
  333. {
  334. //弹窗用户是否确认要示教该点位
  335. if (MessageBox.Show($"确认要示教点位吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  336. {
  337. return;
  338. }
  339. if (SelectedPoint == null)
  340. {
  341. MessageBox.Show("请选择示教点位");
  342. return;
  343. }
  344. var curpos = await Robot.GetRobotPosAsync();
  345. SelectedPoint.X_Position = curpos.X;
  346. SelectedPoint.Y_Position = curpos.Y;
  347. SelectedPoint.Z_Position_Start = curpos.Z;
  348. SelectedPoint.Z_Position_Stop = 0;
  349. AllProductParameter.TorqueValue = this.TorqueValue;
  350. AllProductParameter.TorquePoints = Points;
  351. FileHelper.WriteJsonFile(AllProductParameter, FilePath.TorqueCheckPath);
  352. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  353. }
  354. /// <summary>
  355. /// 修改
  356. /// </summary>
  357. async void ExecuteModifyCommand()
  358. {
  359. if (MessageBox.Show($"确认要修改扭力阈值吗?", "修改", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  360. {
  361. return;
  362. }
  363. var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
  364. res.TorqueValue = this.TorqueValue;
  365. try
  366. {
  367. FileHelper.WriteJsonFile(res, FilePath.TorqueCheckPath);
  368. }
  369. catch (Exception)
  370. {
  371. MessageBox.Show("修改失败");
  372. }
  373. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.4 });
  374. }
  375. async void ExecuteWorkCommand()
  376. {
  377. if (!File.Exists(FilePath.TorqueCheckPath))
  378. {
  379. MessageBox.Show("还未示教,请先示教");
  380. return;
  381. }
  382. if (Robot == null || !Robot.IsConnected)
  383. {
  384. return;
  385. }
  386. if (MessageBox.Show($"确认要进行点检吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  387. {
  388. return;
  389. }
  390. try
  391. {
  392. if (await MoveRobot())
  393. {
  394. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 0.4 });
  395. }
  396. else
  397. {
  398. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.失败, Duration = 0.4 });
  399. }
  400. }
  401. catch (Exception ex)
  402. {
  403. LogHelper.WriteLogError("执行点检时出错!", ex);
  404. }
  405. }
  406. /// <summary>
  407. /// 点检扭矩总体流程
  408. /// </summary>
  409. /// <returns></returns>
  410. public async Task<bool> MoveRobot()
  411. {
  412. TorqueProduceModel Plc_Point = new TorqueProduceModel();
  413. PlcAddressConfig addressConfig = _configService.GetPlcAddresses();
  414. OpcUaClientPLC plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
  415. try
  416. {
  417. Plc_Point = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
  418. if (Plc_Point == null || addressConfig == null || plc == null)
  419. {
  420. return false;
  421. }
  422. //切换手动模式
  423. if (await plc.WriteNodeAsync<bool>(addressConfig.OP_AutoManual.Address, false))
  424. {
  425. //回设置的零点
  426. if (await _torqueService.Safety_Position_Async(Robot, plc, addressConfig, Plc_Point))
  427. {
  428. //执行抛螺丝动作
  429. if (await _torqueService.Throw_Screw_Async(Robot, plc, addressConfig, Plc_Point))
  430. {
  431. //执行取螺丝动作
  432. if (await _torqueService.Pick_Screw_Async(Robot, plc, addressConfig, Plc_Point))
  433. {
  434. //执行锁螺丝点位操作
  435. if (await _torqueService.Screw_Torque_Async(Robot, plc, addressConfig, Plc_Point))
  436. {
  437. //获取电批结果并显示曲线
  438. if (await WatchAsync(plc, addressConfig))
  439. {
  440. await DisplayResult();
  441. return true;
  442. }
  443. MessageBox.Show("未获取到电批结果"); return false;
  444. }
  445. MessageBox.Show("执行锁螺丝点位操作失败"); return false;
  446. }
  447. MessageBox.Show("执行取螺丝动作失败"); return false;
  448. }
  449. MessageBox.Show("执行抛螺丝动作失败"); return false;
  450. }
  451. MessageBox.Show("执行回安全点失败"); return false;
  452. }
  453. MessageBox.Show("点检失败"); return false;
  454. }
  455. catch (Exception ex)
  456. {
  457. LogHelper.WriteLogError("执行点检移动时出错!", ex);
  458. return false;
  459. }
  460. finally
  461. {
  462. await _torqueService.Safety_Position_Async(Robot, plc, addressConfig, Plc_Point);
  463. }
  464. }
  465. public async Task DisplayResult()
  466. {
  467. try
  468. {
  469. await Task.Delay(100);
  470. TValue = management.SignalValue;
  471. double tvalue = double.Parse(TValue.Split(' ')[0]);
  472. double pvalue = Value;
  473. PValue = $"{Math.Round(pvalue, 3)} kgf.cm";
  474. SubValue = $"{Math.Round(Math.Abs(tvalue - pvalue), 3)} kgf.cm";
  475. double sub = Math.Abs(tvalue - pvalue);
  476. var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
  477. if (res != null)
  478. {
  479. if (sub <= res.TorqueValue)
  480. {
  481. FontColor = "Green";
  482. Result = "OK";
  483. }
  484. else
  485. {
  486. FontColor = "Red";
  487. Result = "NG";
  488. }
  489. }
  490. else
  491. {
  492. if (sub <= TorqueValue)
  493. {
  494. FontColor = "Green";
  495. Result = "OK";
  496. }
  497. else
  498. {
  499. FontColor = "Red";
  500. Result = "NG";
  501. }
  502. }
  503. await _torqueService.Save_Torque_Log($"{DateTime.Now},{TValue},{PValue},{Math.Round(sub, 4)},{TorqueValue},{Result}");
  504. SendTaskMessage("点检扭矩成功", MessageLevel.Info);
  505. }
  506. catch (Exception ex)
  507. {
  508. LogHelper.WriteLogError("执行点检显示时出错!", ex);
  509. }
  510. }
  511. public async Task<bool> WatchAsync(OpcUaClientPLC plc, PlcAddressConfig addressConfig)
  512. {
  513. object oking = null;
  514. object nging = null;
  515. int count = 0;
  516. while (count++ < 20)
  517. {
  518. await Task.Delay(100);
  519. oking = plc.ReadNode(addressConfig.Screw_OK.Address);
  520. nging = plc.ReadNode(addressConfig.Screw_NG.Address);
  521. if (oking != null && nging != null)
  522. {
  523. bool okin = (bool)oking; bool ngin = (bool)nging;
  524. //电批OKNG
  525. if (okin || ngin)
  526. {
  527. //获取电批结果
  528. bool isSucced = management.ScrewDriver.GetData();
  529. LockResult lockResult = new LockResult();
  530. lockResult.LockTurns = (float)management.ScrewDriver.Truns;
  531. lockResult.LockTorque = (float)management.ScrewDriver.TorqueValue;
  532. lockResult.WaveDatas = management.ScrewDriver.WaveDatas;
  533. App.Current.Dispatcher.Invoke(() =>
  534. {
  535. _eventAggregator.GetEvent<LockFinishNotification>().Publish(lockResult);
  536. });
  537. //await _systemDatabaseService.RecordLockResultAsync(lockResult);
  538. await plc.WriteNodeAsync(addressConfig.In_WorkDone.Address, (Int16)0);
  539. Value = lockResult.LockTorque;
  540. await plc.WriteNodeAsync(addressConfig.Check_ScrewTorque.Address, false);
  541. return true;
  542. }
  543. }
  544. }
  545. return false;
  546. }
  547. #endregion
  548. public string Title { get; set; } = "扭力点检";
  549. public event Action<IDialogResult> RequestClose;
  550. public bool CanCloseDialog()
  551. {
  552. return true;
  553. }
  554. public void OnDialogClosed()
  555. {
  556. }
  557. public void OnDialogOpened(IDialogParameters parameters)
  558. {
  559. try
  560. {
  561. var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
  562. if (res == null)
  563. {
  564. MessageBox.Show("还未示教,请先示教");
  565. InitialTorquePoints();
  566. }
  567. }
  568. catch (Exception)
  569. {
  570. MessageBox.Show("还未示教,请先示教");
  571. InitialTorquePoints();
  572. }
  573. if (Robot == null)
  574. {
  575. Robot = _robotService.GetRobotByNumber(1);
  576. }
  577. if (Robot != null && Robot.IsConnected)
  578. {
  579. this.Distance = _configService.GetRobotStepDistance(Robot.Id);
  580. Robot.EnterDebugMode = true;
  581. }
  582. else if (Robot != null)
  583. {
  584. Robot.EnterDebugMode = true;
  585. }
  586. }
  587. private void InitialTorquePoints()
  588. {
  589. TorqueProduceModel torques = new TorqueProduceModel()
  590. {
  591. TorquePoints = new ObservableCollection<PlcPoint_Torque>()
  592. {
  593. new PlcPoint_Torque(){Label="抛料点位"},
  594. new PlcPoint_Torque(){Label="取料点位"},
  595. new PlcPoint_Torque(){Label="锁螺丝点位"},
  596. new PlcPoint_Torque(){Label="安全点位"},
  597. }
  598. };
  599. FileHelper.WriteJsonFile(torques, FilePath.TorqueCheckPath);
  600. }
  601. private void ExecuteLoadedCommand()
  602. {
  603. var res = FileHelper.ReadJsonFile<TorqueProduceModel>(FilePath.TorqueCheckPath);
  604. this.Points = res.TorquePoints;
  605. this.TorqueValue = res.TorqueValue;
  606. }
  607. private void SendTaskMessage(string msg, MessageLevel level)
  608. {
  609. App.Current.Dispatcher.Invoke(() =>
  610. {
  611. _eventAggregator.GetEvent<TaskMessageNotification>().Publish(new Models.MessageStruct() { Message = msg, level = level });
  612. });
  613. }
  614. private void ExecuteSavePointsCommand()
  615. {
  616. AllProductParameter.TorqueValue = this.TorqueValue;
  617. AllProductParameter.TorquePoints = Points;
  618. FileHelper.WriteJsonFile(AllProductParameter, FilePath.TorqueCheckPath);
  619. MessageBox.Show("参数保存成功");
  620. }
  621. private async void ExecuteMovePointCommand()
  622. {
  623. if (MessageBox.Show($"确认要进行单独移动至点位吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  624. {
  625. return;
  626. }
  627. PlcAddressConfig addressConfig = _configService.GetPlcAddresses();
  628. OpcUaClientPLC plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
  629. await _torqueService.Signal_Move_Async(Robot, plc, addressConfig, SelectedPoint);
  630. }
  631. }
  632. }