PalletManageViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. using MaterialDesignThemes.Wpf;
  2. using Prism.Commands;
  3. using Prism.Events;
  4. using Prism.Ioc;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using Prism.Services.Dialogs;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Web.Hosting;
  13. using TeamAAS_VP.Controls;
  14. using TeamAAS_VP.Enums;
  15. using TeamAAS_VP.Events;
  16. using TeamAAS_VP.Core;
  17. using TeamAAS_VP.Interfaces;
  18. using TeamAAS_VP.Models;
  19. using TeamAAS_VP.Views.Product;
  20. using TeamAAS_VP;
  21. using Microsoft.Win32;
  22. using System.Windows;
  23. using TeamAAS_VP.Resources.Languages;
  24. using TeamAAS_VP.Models.Robot;
  25. using TeamAAS_VP.Services;
  26. using TeamAAS_VP.Core.Robots;
  27. namespace TeamAAS_VP.ViewModels.Product
  28. {
  29. public class PalletManageViewModel : BindableBase, IDialogAware
  30. {
  31. IRegionManager _regionManager;
  32. IEventAggregator _eventAggregator;
  33. IContainerProvider _container;
  34. IDialogService _dialogService;
  35. IRobotService _robotService;
  36. IConfigService _configService;
  37. #region 属性
  38. public string Title => "Pallet";
  39. private ProductModel _SelectProduct;
  40. /// <summary>
  41. /// 选中的产品
  42. /// </summary>
  43. public ProductModel SelectProduct
  44. {
  45. get { return _SelectProduct; }
  46. set { SetProperty(ref _SelectProduct, value); }
  47. }
  48. private RobotPointStore _SelectedRobot;
  49. public RobotPointStore SelectedRobot
  50. {
  51. get { return _SelectedRobot; }
  52. set { SetProperty(ref _SelectedRobot, value); }
  53. }
  54. private ObservableCollection<Pallet> _Pallets;
  55. /// <summary>
  56. /// 托盘集合
  57. /// </summary>
  58. public ObservableCollection<Pallet> Pallets
  59. {
  60. get { return _Pallets; }
  61. set { SetProperty(ref _Pallets, value); }
  62. }
  63. private Pallet _SelectPallet;
  64. /// <summary>
  65. /// 选中的托盘
  66. /// </summary>
  67. public Pallet SelectPallet
  68. {
  69. get { return _SelectPallet; }
  70. set
  71. {
  72. SetProperty(ref _SelectPallet, value);
  73. if (value == null)
  74. return;
  75. Points = new ObservableCollection<RPoint>();
  76. Points.Add(value.P0);
  77. Points.Add(value.P1);
  78. Points.Add(value.P2);
  79. Row = value.Row;
  80. Column = value.Column;
  81. Arrangement = value.Arrangement;
  82. }
  83. }
  84. private RPoint _SelectPoint;
  85. public RPoint SelectPoint
  86. {
  87. get { return _SelectPoint; }
  88. set { SetProperty(ref _SelectPoint, value); }
  89. }
  90. private MotionCommand _SelectMotionCommand;
  91. /// <summary>
  92. /// 选中的运动指令
  93. /// </summary>
  94. public MotionCommand SelectMotionCommand
  95. {
  96. get { return _SelectMotionCommand; }
  97. set { SetProperty(ref _SelectMotionCommand, value); }
  98. }
  99. private int _Row;
  100. public int Row
  101. {
  102. get { return _Row; }
  103. set
  104. {
  105. SetProperty(ref _Row, value);
  106. if (SelectPallet != null)
  107. {
  108. SelectPallet.Row = value;
  109. _eventAggregator.GetEvent<PalletLayoutNotification>().Publish(SelectPallet);
  110. }
  111. }
  112. }
  113. private int _Column;
  114. public int Column
  115. {
  116. get { return _Column; }
  117. set
  118. {
  119. SetProperty(ref _Column, value);
  120. if (SelectPallet != null)
  121. {
  122. SelectPallet.Column = value;
  123. _eventAggregator.GetEvent<PalletLayoutNotification>().Publish(SelectPallet);
  124. }
  125. }
  126. }
  127. private PalletArrangement _Arrangement;
  128. public PalletArrangement Arrangement
  129. {
  130. get
  131. {
  132. return _Arrangement;
  133. }
  134. set
  135. {
  136. SetProperty(ref _Arrangement, value);
  137. if (SelectPallet != null)
  138. {
  139. SelectPallet.Arrangement = value;
  140. _eventAggregator.GetEvent<PalletLayoutNotification>().Publish(SelectPallet);
  141. }
  142. }
  143. }
  144. private ObservableCollection<RPoint> _Points;
  145. public ObservableCollection<RPoint> Points
  146. {
  147. get { return _Points; }
  148. set { SetProperty(ref _Points, value); }
  149. }
  150. public Management management { get; set; }
  151. private IRobot _Robot;
  152. public IRobot Robot
  153. {
  154. get { return _Robot; }
  155. set
  156. {
  157. SetProperty(ref _Robot, value);
  158. }
  159. }
  160. private double _Distance = 1;
  161. public double Distance
  162. {
  163. get { return _Distance; }
  164. set
  165. {
  166. SetProperty(ref _Distance, value);
  167. try
  168. {
  169. if (Robot == null)
  170. {
  171. return;
  172. }
  173. _configService.UpdateRobotStepDistance(Robot.Id, value);
  174. }
  175. catch (Exception)
  176. {
  177. }
  178. }
  179. }
  180. private bool CanRemove
  181. {
  182. get
  183. {
  184. if (SelectPallet != null)
  185. return true;
  186. else return false;
  187. }
  188. }
  189. private ObservableCollection<int> _Tools = new ObservableCollection<int>();
  190. /// <summary>
  191. /// 机器人Tool集合
  192. /// </summary>
  193. public ObservableCollection<int> Tools
  194. {
  195. get { return _Tools; }
  196. set { SetProperty(ref _Tools, value); }
  197. }
  198. private int _SelectTool;
  199. /// <summary>
  200. /// 选中的Tool
  201. /// </summary>
  202. public int SelectTool
  203. {
  204. get { return _SelectTool; }
  205. set
  206. {
  207. SetProperty(ref _SelectTool, value);
  208. if (value >= 0)
  209. {
  210. if (Robot != null && Robot.IsConnected)
  211. {
  212. try
  213. {
  214. Robot.SelectToolAsync(value);
  215. }
  216. catch (Exception)
  217. {
  218. }
  219. }
  220. }
  221. }
  222. }
  223. #endregion
  224. #region 命令
  225. private DelegateCommand _CreateCommand;
  226. public DelegateCommand CreateCommand =>
  227. _CreateCommand ?? (_CreateCommand = new DelegateCommand(ExecuteCreateCommand));
  228. private DelegateCommand _RemoveCommand;
  229. public DelegateCommand RemoveCommand =>
  230. _RemoveCommand ?? (_RemoveCommand = new DelegateCommand(ExecuteRemoveCommand).ObservesCanExecute(() => CanRemove).ObservesProperty(() => SelectPallet));
  231. private DelegateCommand _ProductSelectionChangedCommand;
  232. public DelegateCommand ProductSelectionChangedCommand =>
  233. _ProductSelectionChangedCommand ?? (_ProductSelectionChangedCommand = new DelegateCommand(ExecuteProductSelectionChangedCommand));
  234. private DelegateCommand _ConfirmCommand;
  235. public DelegateCommand ConfirmCommand =>
  236. _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
  237. private DelegateCommand _CancelCommand;
  238. public DelegateCommand CancelCommand =>
  239. _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  240. private DelegateCommand _CopyCommand;
  241. public DelegateCommand CopyCommand =>
  242. _CopyCommand ?? (_CopyCommand = new DelegateCommand(ExecuteCopyCommand));
  243. private DelegateCommand _EditNameCommand;
  244. public DelegateCommand EditNameCommand =>
  245. _EditNameCommand ?? (_EditNameCommand = new DelegateCommand(ExecuteEditNameCommand));
  246. private DelegateCommand<object> _JogCommand;
  247. public DelegateCommand<object> JogCommand =>
  248. _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  249. private DelegateCommand<object> _ExecuteMotion;
  250. public DelegateCommand<object> ExecuteMotion =>
  251. _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  252. private DelegateCommand<RPoint> _TechPointCommand;
  253. public DelegateCommand<RPoint> TechPointCommand =>
  254. _TechPointCommand ?? (_TechPointCommand = new DelegateCommand<RPoint>(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  255. private DelegateCommand _CalculatePalletCommand;
  256. public DelegateCommand CalculatePalletCommand =>
  257. _CalculatePalletCommand ?? (_CalculatePalletCommand = new DelegateCommand(ExecuteCalculatePalletCommand));
  258. private DelegateCommand<string> _MotorCommand;
  259. public DelegateCommand<string> MotorCommand =>
  260. _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  261. private DelegateCommand _ResetCommand;
  262. public DelegateCommand ResetCommand =>
  263. _ResetCommand ?? (_ResetCommand = new DelegateCommand(ExecuteResetCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  264. private DelegateCommand _sFreeCommand;
  265. public DelegateCommand sFreeCommand =>
  266. _sFreeCommand ?? (_sFreeCommand = new DelegateCommand(ExecutesFreeCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  267. private DelegateCommand _SLockCommand;
  268. public DelegateCommand SLockCommand =>
  269. _SLockCommand ?? (_SLockCommand = new DelegateCommand(ExecuteSLockCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  270. private DelegateCommand _SavePalletImage;
  271. public DelegateCommand SavePalletImage =>
  272. _SavePalletImage ?? (_SavePalletImage = new DelegateCommand(ExecuteSavePalletImage));
  273. #endregion
  274. #region 事件
  275. public event Action<IDialogResult> RequestClose;
  276. #endregion
  277. public PalletManageViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  278. IRobotService robotService, IConfigService configService)
  279. {
  280. _regionManager = regionManager;
  281. _eventAggregator = ea;
  282. _container = container;
  283. _dialogService = dialogService;
  284. //订阅权限登录事件
  285. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  286. _robotService = robotService;
  287. _configService = configService;
  288. }
  289. #region 方法
  290. public bool CanCloseDialog()
  291. {
  292. return true;
  293. }
  294. public void OnDialogClosed()
  295. {
  296. }
  297. public void OnDialogOpened(IDialogParameters parameters)
  298. {
  299. SelectProduct=parameters.GetValue<ProductModel>("SelectProduct");
  300. SelectedRobot= parameters.GetValue<RobotPointStore>("SelectedRobot");
  301. Robot = _robotService.GetRobot(SelectedRobot.Id);
  302. if (Robot is FanucRobot)
  303. {
  304. Tools = new ObservableCollection<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  305. SelectTool = Robot.SelectedTool;
  306. }
  307. else
  308. {
  309. Tools = new ObservableCollection<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  310. SelectTool = Robot.SelectedTool;
  311. }
  312. Pallets = SelectedRobot.Pallets;
  313. management = _container.Resolve<Management>();
  314. this.Distance = _configService.GetRobotStepDistance(Robot.Id);
  315. }
  316. /// <summary>
  317. /// 创建托盘
  318. /// </summary>
  319. async void ExecuteCreateCommand()
  320. {
  321. //var view = new AddProduct() { Title = "创建托盘:", Item = "Name" };
  322. var view = new AddPalletView();
  323. //show the dialog
  324. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  325. if (result != null && result is AddPalletView vm && !string.IsNullOrEmpty(vm.PalletName))
  326. {
  327. Pallet pallet = new Pallet()
  328. {
  329. Id = Guid.NewGuid(),
  330. Name = vm.PalletName,
  331. Row = 2,
  332. Column = 2,
  333. P0 = new RPoint() { Number = 0 },
  334. P1 = new RPoint() { Number = 1 },
  335. P2 = new RPoint() { Number = 2 },
  336. Arrangement = PalletArrangement.Z,
  337. };
  338. if (!vm.IsCheckModel1)
  339. {
  340. pallet.Extend = new PalletExtend()
  341. {
  342. Pallet_Row = 2,
  343. Pallet_Column = 2,
  344. Pallet_X_Interval = 0,
  345. Pallet_Y_Interval = 0,
  346. CoordinateModel = vm.CoordinateModel
  347. };
  348. }
  349. Pallets.Add(pallet);
  350. SelectPallet = Pallets[Pallets.Count - 1];
  351. }
  352. //if (result != null && !string.IsNullOrEmpty(result.ToString()))
  353. //{
  354. // Pallets.Add(new Pallet()
  355. // {
  356. // Id = Guid.NewGuid(),
  357. // Name = result.ToString(),
  358. // Row=2,
  359. // Column=2,
  360. // P0 = new RPoint() { Number = 0 },
  361. // P1 = new RPoint() { Number = 1 },
  362. // P2 = new RPoint() { Number = 2 },
  363. // Arrangement=PalletArrangement.Z,
  364. // });
  365. // SelectPallet = Pallets[Pallets.Count - 1];
  366. //}
  367. }
  368. /// <summary>
  369. /// 移除托盘
  370. /// </summary>
  371. void ExecuteRemoveCommand()
  372. {
  373. if (SelectPallet != null)
  374. {
  375. Pallets.Remove(SelectPallet);
  376. }
  377. }
  378. /// <summary>
  379. /// 点击选择托盘时触发方法
  380. /// </summary>
  381. void ExecuteProductSelectionChangedCommand()
  382. {
  383. }
  384. /// <summary>
  385. /// 确定
  386. /// </summary>
  387. void ExecuteConfirmCommand()
  388. {
  389. IDialogParameters parameters = new DialogParameters();
  390. parameters.Add("Pallets", Pallets);
  391. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
  392. }
  393. /// <summary>
  394. /// 取消
  395. /// </summary>
  396. void ExecuteCancelCommand()
  397. {
  398. IDialogParameters parameters = new DialogParameters();
  399. parameters.Add("Pallets", Pallets);
  400. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
  401. }
  402. /// <summary>
  403. /// 保存托盘图片
  404. /// </summary>
  405. void ExecuteSavePalletImage()
  406. {
  407. try
  408. {
  409. if (SelectPallet == null)
  410. {
  411. return;
  412. }
  413. SaveFileDialog dlg = new SaveFileDialog();
  414. dlg.Title = "Save Pallet Layout Image";
  415. dlg.DefaultExt = ".png";
  416. dlg.Filter = "Image (*.png)|*.png";
  417. if (dlg.ShowDialog() ?? false)
  418. {
  419. PalletTool palletTool = new PalletTool(SelectPallet);
  420. palletTool.DrawCoordinatesAndSaveImage(dlg.FileName);
  421. MessageBox.Show("OK");
  422. }
  423. }
  424. catch (Exception ex)
  425. {
  426. MessageBox.Show(ex.ToString());
  427. }
  428. }
  429. /// <summary>
  430. /// 复制
  431. /// </summary>
  432. void ExecuteCopyCommand()
  433. {
  434. }
  435. /// <summary>
  436. /// 修改托盘名称
  437. /// </summary>
  438. void ExecuteEditNameCommand()
  439. {
  440. }
  441. /// <summary>
  442. /// 点动
  443. /// </summary>
  444. /// <param name="obj"></param>
  445. private async void ExecuteJogCommand(object obj)
  446. {
  447. if (Robot == null || !Robot.IsConnected) return;
  448. try
  449. {
  450. Robot.Timeout = 6000000;
  451. var items = ((string)obj).Split(':');
  452. switch (items[0])
  453. {
  454. case "X+":
  455. await Robot.JogAsync("X", double.Parse(items[1]));
  456. break;
  457. case "X-":
  458. await Robot.JogAsync("X", -double.Parse(items[1]));
  459. break;
  460. case "Y+":
  461. await Robot.JogAsync("Y", double.Parse(items[1]));
  462. break;
  463. case "Y-":
  464. await Robot.JogAsync("Y", -double.Parse(items[1]));
  465. break;
  466. case "Z+":
  467. await Robot.JogAsync("Z", double.Parse(items[1]));
  468. break;
  469. case "Z-":
  470. await Robot.JogAsync("Z", -double.Parse(items[1]));
  471. break;
  472. case "U+":
  473. await Robot.JogAsync("U", double.Parse(items[1]));
  474. break;
  475. case "U-":
  476. await Robot.JogAsync("U", -double.Parse(items[1]));
  477. break;
  478. case "V+":
  479. await Robot.JogAsync("V", double.Parse(items[1]));
  480. break;
  481. case "V-":
  482. await Robot.JogAsync("V", -double.Parse(items[1]));
  483. break;
  484. case "W+":
  485. await Robot.JogAsync("W", double.Parse(items[1]));
  486. break;
  487. case "W-":
  488. await Robot.JogAsync("W", -double.Parse(items[1]));
  489. break;
  490. default:
  491. break;
  492. }
  493. Robot.Timeout = 5000;
  494. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  495. }
  496. catch (Exception ex)
  497. {
  498. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  499. LogHelper.WriteLogError("机器人点动时出错", ex);
  500. }
  501. }
  502. /// <summary>
  503. /// 执行运动
  504. /// </summary>
  505. /// <param name="obj"></param>
  506. async void ExecuteExecuteMotion(object parameter)
  507. {
  508. var values = (object[])parameter;
  509. var point = values[0] as RPoint;
  510. MotionCommand motionCmd = (MotionCommand)values[1];
  511. if (Robot == null || !Robot.IsConnected) return;
  512. try
  513. {
  514. Robot.Timeout = 6000000;
  515. switch (motionCmd)
  516. {
  517. case MotionCommand.Go:
  518. await Robot.GoAsync(point);
  519. break;
  520. case MotionCommand.Jump:
  521. await Robot.JumpAsync(point, 0);
  522. break;
  523. case MotionCommand.Move:
  524. await Robot.MoveAsync(point);
  525. break;
  526. }
  527. Robot.Timeout = 5000;
  528. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 1 });
  529. }
  530. catch (Exception ex)
  531. {
  532. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  533. LogHelper.WriteLogError(Lang.机器人运动至目标点时出错, ex);
  534. }
  535. }
  536. /// <summary>
  537. /// 示教点位
  538. /// </summary>
  539. /// <param name="point"></param>
  540. async void ExecuteTechPointCommand(RPoint point)
  541. {
  542. if (Robot == null || !Robot.IsConnected) return;
  543. try
  544. {
  545. var curpos = await Robot.GetRobotPosAsync();
  546. RPoint p0 = Points.FirstOrDefault(x => x.Number == point.Number);
  547. p0.X = curpos.X;
  548. p0.Y = curpos.Y;
  549. p0.Z = curpos.Z;
  550. p0.U = curpos.U;
  551. p0.V = curpos.V;
  552. p0.W = curpos.W;
  553. p0.Hand = curpos.Hand;
  554. p0.Local = curpos.Local;
  555. p0.Tool = curpos.Tool;
  556. p0 = curpos;
  557. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 1 });
  558. }
  559. catch (Exception ex)
  560. {
  561. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  562. LogHelper.WriteLogError(Lang.示教机器人点时出错, ex);
  563. }
  564. }
  565. /// <summary>
  566. /// 计算托盘
  567. /// </summary>
  568. async void ExecuteCalculatePalletCommand()
  569. {
  570. try
  571. {
  572. var view = new CalculatePalletPos();
  573. ((CalculatePalletPosViewModel)view.DataContext).CurrentPallet = ((Pallet)SelectPallet).Clone();
  574. //show the dialog
  575. var result = await DialogHost.Show(view, "PalletCalculateDialog", null, null, null);
  576. if (result != null && result is bool)
  577. {
  578. if (((bool)result))
  579. {
  580. SelectPallet = ((CalculatePalletPosViewModel)view.DataContext).CurrentPallet.Clone();
  581. }
  582. }
  583. }
  584. catch (Exception ex)
  585. {
  586. LogHelper.WriteLogError(Lang.计算托盘时出错, ex);
  587. }
  588. }
  589. /// <summary>
  590. /// 电机
  591. /// </summary>
  592. /// <param name="obj"></param>
  593. private async void ExecuteMotorCommand(string obj)
  594. {
  595. if (Robot == null || !Robot.IsConnected) return;
  596. try
  597. {
  598. await Robot.MotorAsync(Convert.ToBoolean(obj));
  599. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 1 });
  600. }
  601. catch (Exception ex)
  602. {
  603. LogHelper.WriteLogError(Lang.机器人点击操作时出错, ex);
  604. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  605. }
  606. }
  607. /// <summary>
  608. /// 重置
  609. /// </summary>
  610. private async void ExecuteResetCommand()
  611. {
  612. if (Robot == null || !Robot.IsConnected) return;
  613. try
  614. {
  615. await Robot.ResetAsync();
  616. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 1 });
  617. }
  618. catch (Exception ex)
  619. {
  620. LogHelper.WriteLogError(Lang.重置机器人时出错, ex);
  621. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  622. }
  623. }
  624. /// <summary>
  625. /// 锁定刹车
  626. /// </summary>
  627. private async void ExecuteSLockCommand()
  628. {
  629. if (Robot == null || !Robot.IsConnected) return;
  630. try
  631. {
  632. await Robot.SLockAsync();
  633. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 1 });
  634. }
  635. catch (Exception ex)
  636. {
  637. LogHelper.WriteLogError(Lang.机器人锁定刹车时出错, ex);
  638. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  639. }
  640. }
  641. /// <summary>
  642. /// 释放刹车
  643. /// </summary>
  644. private async void ExecutesFreeCommand()
  645. {
  646. if (Robot == null || !Robot.IsConnected) return;
  647. try
  648. {
  649. await Robot.SFreeAsync();
  650. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 1 });
  651. }
  652. catch (Exception ex)
  653. {
  654. LogHelper.WriteLogError(Lang.机器人释放刹车时出错, ex);
  655. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  656. }
  657. }
  658. private bool CanExecute
  659. {
  660. get
  661. {
  662. if (Robot != null)
  663. {
  664. return Robot.CanExecute;
  665. }
  666. else
  667. {
  668. return false;
  669. }
  670. }
  671. }
  672. #endregion
  673. private bool _IsAllowEdit = false;
  674. public bool IsAllowEdit
  675. {
  676. get { return _IsAllowEdit; }
  677. set { SetProperty(ref _IsAllowEdit, value); }
  678. }
  679. private void LoginChange(Models.User user)
  680. {
  681. if (user.userPart == Enums.UserPart.Operator)
  682. {
  683. IsAllowEdit = false;
  684. }
  685. else
  686. {
  687. IsAllowEdit = true;
  688. }
  689. }
  690. }
  691. }