终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

493 рядки
17 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.UserControls.MessageShow;
  3. using BPASmartClient.MorkCL.HelpClass;
  4. using System.Reflection.Metadata;
  5. using System.Windows.Markup;
  6. namespace BPASmartClient.MorkCL.ViewModel
  7. {
  8. public class DebugViewModel : NotifyBase
  9. {
  10. private ushort heatGear;
  11. private ushort agitaFrequency;
  12. public DebugViewModel()
  13. {
  14. WriteAgitaParamCommand = new(async () =>
  15. {
  16. //if (!GetDeviceIsIdle(FryingPanSelect))
  17. //{
  18. // return;
  19. //}
  20. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  21. {
  22. return;
  23. }
  24. ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(FryingPanSelect, "LW1", (ushort)(AgitaFrequency*100)));
  25. await SendWriteRequest("LB10");
  26. ShowNotify($"写入搅拌参数成功。");
  27. });
  28. StartAgitateCommand = new(() =>
  29. {
  30. if (!GetDeviceIsIdle(FryingPanSelect))
  31. {
  32. return;
  33. }
  34. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  35. {
  36. return;
  37. }
  38. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB0", true));
  39. ShowNotify($"写入搅拌启动成功。");
  40. });
  41. StopAgitateCommand = new(() =>
  42. {
  43. //if (!GetDeviceIsIdle(FryingPanSelect))
  44. //{
  45. // return;
  46. //}
  47. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  48. {
  49. return;
  50. }
  51. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB0", false));
  52. ShowNotify($"写入搅拌停止成功。");
  53. });
  54. WriteHeatParamCommand = new(async () =>
  55. {
  56. //if (!GetDeviceIsIdle(FryingPanSelect))
  57. //{
  58. // return;
  59. //}
  60. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  61. {
  62. return;
  63. }
  64. ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(FryingPanSelect, "LW0", HeatGear));
  65. await SendWriteRequest("LB9");
  66. ShowNotify($"写入加热参数成功。");
  67. });
  68. StartHeatCommand = new(() =>
  69. {
  70. if (!GetDeviceIsIdle(FryingPanSelect))
  71. {
  72. return;
  73. }
  74. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  75. {
  76. return;
  77. }
  78. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB3", true));
  79. ShowNotify($"写入加热启动成功。");
  80. });
  81. StopHeatCommand = new(() =>
  82. {
  83. //if (!GetDeviceIsIdle(FryingPanSelect))
  84. //{
  85. // return;
  86. //}
  87. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  88. {
  89. return;
  90. }
  91. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB3", false));
  92. ShowNotify($"写入加热停止成功。");
  93. });
  94. ChannelCuttingCommand = new(async () =>
  95. {
  96. //var channelIndex = ChannelSelect;
  97. //var weight = Convert.ToUInt16(Weight);
  98. //byte[] LWOffset = new byte[3] { 3, 4, 5 };
  99. //byte[] LBOffset = new byte[3] { 6, 7, 8 };
  100. //ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(FryingPanSelect, $"LW{LWOffset[channelIndex]}", weight));
  101. //await SendWriteRequest($"LB{LBOffset[channelIndex]}");
  102. if (!GetDeviceIsIdle(FryingPanSelect))
  103. {
  104. return;
  105. }
  106. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  107. {
  108. return;
  109. }
  110. object[] para = new object[3];
  111. para[0]= FryingPanSelect;
  112. para[1] = ChannelSelect+1;
  113. para[2] = Convert.ToUInt16(Weight);
  114. await Task.Run(() => ActionManage.GetInstance.Send("DeviceCuttingControl", para));
  115. ShowNotify($"写入通道下料控制成功。");
  116. });
  117. GoFryLocCommand = new(async () =>
  118. {
  119. if (!GetDeviceIsIdle(FryingPanSelect))
  120. {
  121. return;
  122. }
  123. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  124. {
  125. return;
  126. }
  127. var loc = StirFryLocSelect + 17;
  128. await SendWriteRequest($"LB{loc}");
  129. ShowNotify($"写入去炒制位成功。");
  130. });
  131. GoHomeCommand = new(async () =>
  132. {
  133. if (!GetDeviceIsIdle(FryingPanSelect))
  134. {
  135. return;
  136. }
  137. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  138. {
  139. return;
  140. }
  141. await SendWriteRequest("LB12");
  142. ShowNotify($"写入回原点成功。");
  143. });
  144. GoSeasoningFeddLocCommand = new(async () =>
  145. {
  146. if (!GetDeviceIsIdle(FryingPanSelect))
  147. {
  148. return;
  149. }
  150. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  151. {
  152. return;
  153. }
  154. await SendWriteRequest("LB16");
  155. ShowNotify($"写入去调料投料位成功。");
  156. });
  157. OutDiningStartCommand = new(async () =>
  158. {
  159. if (!GetDeviceIsIdle(FryingPanSelect))
  160. {
  161. return;
  162. }
  163. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  164. {
  165. return;
  166. }
  167. await SendWriteRequest("LB13");
  168. ShowNotify($"写入出餐启动成功。");
  169. });
  170. FryPanCleanCommand = new(async () =>
  171. {
  172. if (!GetDeviceIsIdle(FryingPanSelect))
  173. {
  174. return;
  175. }
  176. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  177. {
  178. return;
  179. }
  180. await SendWriteRequest("LB14");
  181. ShowNotify($"写入炒锅清洗成功。");
  182. });
  183. SetAutoModeCommand = new(() =>
  184. {
  185. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB20", true));
  186. ShowNotify($"设置设备自动模式成功。");
  187. });
  188. SetManualModeCommand = new(() =>
  189. {
  190. if (!GetDeviceIsIdle(FryingPanSelect))
  191. {
  192. return;
  193. }
  194. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB20", false));
  195. ShowNotify($"设置设备手动模式成功。");
  196. });
  197. InitalDeviceCommand = new(async () =>
  198. {
  199. if (!GetDeviceIsIdle(FryingPanSelect))
  200. {
  201. return;
  202. }
  203. //复位所有变量。
  204. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  205. {
  206. return;
  207. }
  208. ResetFryPanVariable(FryingPanSelect);
  209. await SendWriteRequest("LB21");
  210. ShowNotify($"设置设备初始化成功。");
  211. });
  212. StopDeviceCommand = new(async () =>
  213. {
  214. //if (!GetDeviceIsIdle(FryingPanSelect))
  215. //{
  216. // return;
  217. //}
  218. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  219. {
  220. return;
  221. }
  222. await SendWriteRequest("LB22");
  223. ShowNotify($"设置设备停止成功。");
  224. });
  225. //炒锅那边复位变量没有使用。
  226. GoCleanLocCommand = new(async () =>
  227. {
  228. if (!GetDeviceIsIdle(FryingPanSelect))
  229. {
  230. return;
  231. }
  232. if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
  233. {
  234. return;
  235. }
  236. await SendWriteRequest("LB23");
  237. ShowNotify($"设置设备去洗锅位成功。");
  238. });
  239. CancelFryPanTaskCommand = new((string device) =>
  240. {
  241. ActionManage.GetInstance.Send("CancelFryPanTask", device);
  242. ShowNotify($"[{device}#]取消当前任务成功");
  243. });
  244. ClearFryPanTaskCommand_1 = new(() =>
  245. {
  246. });
  247. ClearFryPanTaskCommand_2 = new(() =>
  248. {
  249. });
  250. InitRobotVarCommand = new(() =>
  251. {
  252. Task.Run(() =>
  253. {
  254. ActionManage.GetInstance.Send("InitRobotAllVar");
  255. });
  256. });
  257. RobotGoCleanLocCommand = new(() =>
  258. {
  259. if (!MessageNotify.GetInstance.ShowDialog("确认是否将机械手移动到清洗位?"))
  260. {
  261. return;
  262. }
  263. ActionManage.GetInstance.Send("RobotGoCleanLoc");
  264. });
  265. }
  266. #region 私有方法
  267. private async Task SendWriteRequest(string address)
  268. {
  269. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, address, false));
  270. await Task.Delay(400);
  271. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, address, true));
  272. await Task.Delay(400);
  273. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, address, false));
  274. }
  275. private void ShowNotify(string info)
  276. {
  277. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", info);
  278. }
  279. private bool GetDeviceIsIdle(EDeviceType device)
  280. {
  281. if (ActionManage.GetInstance.SendResult("GetDeviceIsIdle", FryingPanSelect) is bool frypanisIdle)
  282. {
  283. if (frypanisIdle)
  284. {
  285. return true;
  286. }
  287. else
  288. {
  289. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", "当前炒锅正在炒菜,稍后再试。");
  290. }
  291. }
  292. return false;
  293. }
  294. /// <summary>
  295. /// 复位指定炒锅的所有变量。
  296. /// </summary>
  297. /// <param name="deviceType"></param>
  298. private void ResetFryPanVariable(EDeviceType deviceType)
  299. {
  300. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB0", false));
  301. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB3", false));
  302. for (int i = 6; i <= 19; i++)
  303. {
  304. ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB" + i, false));
  305. }
  306. for (int i = 0; i <= 5; i++)
  307. {
  308. ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(deviceType, "LW" + i, 0));
  309. }
  310. }
  311. #endregion 私有方法
  312. #region 属性
  313. private EDeviceType fryingPanSelect = EDeviceType.炒锅1;
  314. /// <summary>炒锅选择。</summary>
  315. public EDeviceType FryingPanSelect
  316. {
  317. get { return fryingPanSelect; }
  318. set { fryingPanSelect = value; OnPropertyChanged(); }
  319. }
  320. /// <summary>搅拌频率</summary>
  321. public ushort AgitaFrequency
  322. {
  323. get => agitaFrequency; set
  324. {
  325. if (value >= 50)
  326. agitaFrequency = 50;
  327. else if (value <= 1)
  328. agitaFrequency = 1;
  329. else
  330. agitaFrequency = value;
  331. OnPropertyChanged();
  332. }
  333. }
  334. /// <summary>加热档位</summary>
  335. public ushort HeatGear
  336. {
  337. get => heatGear; set
  338. {
  339. if (value >= 8)
  340. heatGear = 8;
  341. else if (value <= 1)
  342. heatGear = 1;
  343. else
  344. heatGear = value;
  345. OnPropertyChanged();
  346. }
  347. }
  348. private float weight;
  349. /// <summary>下料重量</summary>
  350. public float Weight
  351. {
  352. get { return weight; }
  353. set { weight = value; }
  354. }
  355. private int channelSelect;
  356. /// <summary>下料通道选择。</summary>
  357. public int ChannelSelect
  358. {
  359. get { return channelSelect; }
  360. set { channelSelect = value; OnPropertyChanged(); }
  361. }
  362. private int stirFryLocSelect;
  363. /// <summary>炒制位选择。</summary>
  364. public int StirFryLocSelect
  365. {
  366. get { return stirFryLocSelect; }
  367. set { stirFryLocSelect = value; OnPropertyChanged(); }
  368. }
  369. public ObservableCollection<EDeviceType> DeviceTypes { get; set; } = new ObservableCollection<EDeviceType>() { EDeviceType.炒锅1, EDeviceType.炒锅2 };
  370. #endregion 属性
  371. #region 命令
  372. /// <summary>写入搅拌参数。</summary>
  373. public BPARelayCommand WriteAgitaParamCommand { get; set; }
  374. /// <summary>开始搅拌。</summary>
  375. public BPARelayCommand StartAgitateCommand { get; set; }
  376. /// <summary>停止搅拌。</summary>
  377. public BPARelayCommand StopAgitateCommand { get; set; }
  378. /// <summary>写入加热参数。</summary>
  379. public BPARelayCommand WriteHeatParamCommand { get; set; }
  380. /// <summary>开始加热。</summary>
  381. public BPARelayCommand StartHeatCommand { get; set; }
  382. /// <summary>停止加热。</summary>
  383. public BPARelayCommand StopHeatCommand { get; set; }
  384. /// <summary>通道下料启动。</summary>
  385. public BPARelayCommand ChannelCuttingCommand { get; set; }
  386. /// <summary>去炒制位。</summary>
  387. public BPARelayCommand GoFryLocCommand { get; set; }
  388. /// <summary>回原点/投料位置。</summary>
  389. public BPARelayCommand GoHomeCommand { get; set; }
  390. /// <summary>去调料投料位。</summary>
  391. public BPARelayCommand GoSeasoningFeddLocCommand { get; set; }
  392. /// <summary>出餐启动。</summary>
  393. public BPARelayCommand OutDiningStartCommand { get; set; }
  394. /// <summary>炒锅清洗。</summary>
  395. public BPARelayCommand FryPanCleanCommand { get; set; }
  396. /// <summary>
  397. /// 设为自动模式。
  398. /// </summary>
  399. public BPARelayCommand SetAutoModeCommand { get; set; }
  400. /// <summary>
  401. /// 设为手动模式。
  402. /// </summary>
  403. public BPARelayCommand SetManualModeCommand { get; set; }
  404. /// <summary>
  405. /// 初始化设备。
  406. /// </summary>
  407. public BPARelayCommand InitalDeviceCommand { get; set; }
  408. /// <summary>
  409. /// 设备停止。
  410. /// </summary>
  411. public BPARelayCommand StopDeviceCommand { get; set; }
  412. /// <summary>
  413. /// 设备去洗锅位置。
  414. /// </summary>
  415. public BPARelayCommand GoCleanLocCommand { get; set; }
  416. /// <summary>
  417. /// 取消指定炒锅当前任务。
  418. /// </summary>
  419. public BPARelayCommand<string> CancelFryPanTaskCommand { get; set; }
  420. /// <summary>
  421. /// 清空1#炒锅所有任务。
  422. /// </summary>
  423. public BPARelayCommand ClearFryPanTaskCommand_1 { get; set; }
  424. /// <summary>
  425. /// 清空2#炒锅所有任务。
  426. /// </summary>
  427. public BPARelayCommand ClearFryPanTaskCommand_2 { get; set; }
  428. /// <summary>
  429. /// 复位机器人所有由上位机下发的变量。
  430. /// </summary>
  431. public BPARelayCommand InitRobotVarCommand { get; set; }
  432. public BPARelayCommand RobotGoCleanLocCommand { get; set; }
  433. #endregion 命令
  434. }
  435. }