LiquidManualWindowViewModel.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. using System;
  2. using Prism.Mvvm;
  3. using Prism.Commands;
  4. using Panuon.UI.Silver;
  5. using SHJX.Service.Model.Enums;
  6. using SHJX.Service.Common.Constants;
  7. using SHJX.Service.Control.Interface;
  8. namespace SHJX.Service.Shell.ViewModels.Manual
  9. {
  10. public class LiquidManualWindowViewModel : BindableBase
  11. {
  12. #region Field
  13. private readonly IManualService _service;
  14. #endregion
  15. #region Properties
  16. #region In Wait
  17. private bool _sodium1OxalateInLiquidWait;
  18. public bool Sodium1OxalateInLiquidWait
  19. {
  20. get => _sodium1OxalateInLiquidWait;
  21. set => SetProperty(ref _sodium1OxalateInLiquidWait, value);
  22. }
  23. private bool _sodium2OxalateInLiquidWait;
  24. public bool Sodium2OxalateInLiquidWait
  25. {
  26. get => _sodium2OxalateInLiquidWait;
  27. set => SetProperty(ref _sodium2OxalateInLiquidWait, value);
  28. }
  29. //private bool _addLiquidPotassiumPermanganateInLiquidWait;
  30. //public bool AddLiquidPotassiumPermanganateInLiquidWait
  31. //{
  32. // get => _addLiquidPotassiumPermanganateInLiquidWait;
  33. // set => SetProperty(ref _addLiquidPotassiumPermanganateInLiquidWait, value);
  34. //}
  35. private bool _titration1PotassiumPermanganateInLiquidWait;
  36. public bool Titration1PotassiumPermanganateInLiquidWait
  37. {
  38. get => _titration1PotassiumPermanganateInLiquidWait;
  39. set => SetProperty(ref _titration1PotassiumPermanganateInLiquidWait, value);
  40. }
  41. private bool _titration2PotassiumPermanganateInLiquidWait;
  42. public bool Titration2PotassiumPermanganateInLiquidWait
  43. {
  44. get => _titration2PotassiumPermanganateInLiquidWait;
  45. set => SetProperty(ref _titration2PotassiumPermanganateInLiquidWait, value);
  46. }
  47. #endregion
  48. #region Out Wait
  49. private bool _sodium1OxalateOutLiquidWait;
  50. public bool Sodium1OxalateOutLiquidWait
  51. {
  52. get => _sodium1OxalateOutLiquidWait;
  53. set => SetProperty(ref _sodium1OxalateOutLiquidWait, value);
  54. }
  55. private bool _sodium2OxalateOutLiquidWait;
  56. public bool Sodium2OxalateOutLiquidWait
  57. {
  58. get => _sodium2OxalateOutLiquidWait;
  59. set => SetProperty(ref _sodium2OxalateOutLiquidWait, value);
  60. }
  61. //private bool _addLiquidPotassiumPermanganateOutLiquidWait;
  62. //public bool AddLiquidPotassiumPermanganateOutLiquidWait
  63. //{
  64. // get => _addLiquidPotassiumPermanganateOutLiquidWait;
  65. // set => SetProperty(ref _addLiquidPotassiumPermanganateOutLiquidWait, value);
  66. //}
  67. private bool _titration1PotassiumPermanganateOutLiquidWait;
  68. public bool Titration1PotassiumPermanganateOutLiquidWait
  69. {
  70. get => _titration1PotassiumPermanganateOutLiquidWait;
  71. set => SetProperty(ref _titration1PotassiumPermanganateOutLiquidWait, value);
  72. }
  73. private bool _titration2PotassiumPermanganateOutLiquidWait;
  74. public bool Titration2PotassiumPermanganateOutLiquidWait
  75. {
  76. get => _titration2PotassiumPermanganateOutLiquidWait;
  77. set => SetProperty(ref _titration2PotassiumPermanganateOutLiquidWait, value);
  78. }
  79. #endregion
  80. #endregion
  81. public LiquidManualWindowViewModel(IManualService service)
  82. {
  83. _service = service;
  84. Sodium1OxalateInLiquidWait = false;
  85. Sodium2OxalateInLiquidWait = false;
  86. //AddLiquidPotassiumPermanganateInLiquidWait = false;
  87. Titration1PotassiumPermanganateInLiquidWait = false;
  88. Titration2PotassiumPermanganateInLiquidWait = false;
  89. Sodium1OxalateOutLiquidWait = false;
  90. Sodium2OxalateOutLiquidWait = false;
  91. //AddLiquidPotassiumPermanganateOutLiquidWait = false;
  92. Titration1PotassiumPermanganateOutLiquidWait = false;
  93. Titration2PotassiumPermanganateOutLiquidWait = false;
  94. }
  95. #region Command
  96. private DelegateCommand<object> _registerLiquidCommand;
  97. public DelegateCommand<object> RegisterLiquidCommand => _registerLiquidCommand ??= new DelegateCommand<object>(ExecuteRegisterLiquidCommand);
  98. private DelegateCommand<object> _inLiquidCommand;
  99. public DelegateCommand<object> InLiquidCommand => _inLiquidCommand ??= new DelegateCommand<object>(ExecuteInLiquidCommand);
  100. private DelegateCommand<object> _outLiquidCommand;
  101. public DelegateCommand<object> OutLiquidCommand => _outLiquidCommand ??= new DelegateCommand<object>(ExecuteOutLiquidCommand);
  102. private DelegateCommand<object> _directLiquidCommand;
  103. public DelegateCommand<object> DirectLiquidCommand => _directLiquidCommand ??= new DelegateCommand<object>(ExecuteDirectLiquidCommand);
  104. private DelegateCommand<object> _dropperFrontCommand;
  105. public DelegateCommand<object> DropperFrontCommand => _dropperFrontCommand ??= new DelegateCommand<object>(ExecuteDropperFrontCommand);
  106. private DelegateCommand<object> _dropperInversionCommand;
  107. public DelegateCommand<object> DropperInversionCommand => _dropperInversionCommand ??= new DelegateCommand<object>(ExecuteDropperInversionCommand);
  108. private DelegateCommand<object> _dropperPointCommand;
  109. public DelegateCommand<object> DropperPointCommand => _dropperPointCommand ??= new DelegateCommand<object>(ExecuteDropperPointCommand);
  110. private DelegateCommand<object> _stirStartCommand;
  111. public DelegateCommand<object> StirStartCommand => _stirStartCommand ??= new DelegateCommand<object>(ExecuteStirStartCommand);
  112. private DelegateCommand<object> _stirStopCommand;
  113. public DelegateCommand<object> StirStopCommand => _stirStopCommand ??= new DelegateCommand<object>(ExecuteStirStopCommand);
  114. private DelegateCommand<object> _moveToYDCommand;
  115. public DelegateCommand<object> MoveToYDCommand => _moveToYDCommand ??= new DelegateCommand<object>(ExecuteMoveToYDCommand);
  116. private DelegateCommand<object> _moveToJYCommand;
  117. public DelegateCommand<object> MoveToJYCommand => _moveToJYCommand ??= new DelegateCommand<object>(ExecuteMoveToJYCommand);
  118. private DelegateCommand<object> _moveToDD2Command;
  119. public DelegateCommand<object> MoveToDD2Command => _moveToDD2Command ??= new DelegateCommand<object>(ExecuteMoveToDD2Command);
  120. #endregion
  121. #region Pump Execute
  122. #region 注射泵
  123. /// <summary>
  124. /// 吸液
  125. /// </summary>
  126. /// <param name="obj"></param>
  127. public async void ExecuteInLiquidCommand(object obj)
  128. {
  129. if (obj is null)
  130. {
  131. return;
  132. }
  133. object[] receiveObj = obj as object[];
  134. if (receiveObj is null or { Length: 0 })
  135. {
  136. return;
  137. }
  138. string typeName = receiveObj[0].ToString() switch
  139. {
  140. "草酸钠(滴定2)" => EquipmentNames.Sodium2Oxalate,
  141. "草酸钠(滴定1)" => EquipmentNames.Sodium1Oxalate,
  142. "高锰酸钾(加液滴定2)" => EquipmentNames.Titration2PotassiumPermanganate,
  143. "高锰酸钾(滴定1)" => EquipmentNames.Titration1PotassiumPermanganate,
  144. _ => throw new ArgumentException("未找到相关对应"),
  145. };
  146. try
  147. {
  148. switch (typeName)
  149. {
  150. case EquipmentNames.Sodium1Oxalate:
  151. Sodium1OxalateInLiquidWait = true;
  152. break;
  153. case EquipmentNames.Sodium2Oxalate:
  154. Sodium2OxalateInLiquidWait = true;
  155. break;
  156. case EquipmentNames.Titration1PotassiumPermanganate:
  157. Titration1PotassiumPermanganateInLiquidWait = true;
  158. break;
  159. case EquipmentNames.Titration2PotassiumPermanganate:
  160. Titration2PotassiumPermanganateInLiquidWait = true;
  161. break;
  162. default:
  163. throw new ArgumentNullException(typeName);
  164. }
  165. if (typeName==EquipmentNames.Sodium1Oxalate|| typeName == EquipmentNames.Sodium2Oxalate)
  166. {
  167. await _service.ManualLiquidExecuteOxalate(typeName,LiquidSwitchPattern.In, receiveObj[1]);
  168. }
  169. else
  170. await _service.ManualLiquidExecute(typeName, LiquidSwitchPattern.In, receiveObj[1]);
  171. }
  172. catch (Exception)
  173. {
  174. Notice.Show("出了点状况,请重新再试~", "Error", 3, MessageBoxIcon.Error);
  175. }
  176. finally
  177. {
  178. switch (typeName)
  179. {
  180. case EquipmentNames.Sodium1Oxalate:
  181. Sodium1OxalateInLiquidWait = false;
  182. break;
  183. case EquipmentNames.Sodium2Oxalate:
  184. Sodium2OxalateInLiquidWait = false;
  185. break;
  186. case EquipmentNames.Titration1PotassiumPermanganate:
  187. Titration1PotassiumPermanganateInLiquidWait = false;
  188. break;
  189. case EquipmentNames.Titration2PotassiumPermanganate:
  190. Titration2PotassiumPermanganateInLiquidWait = false;
  191. break;
  192. }
  193. }
  194. }
  195. /// <summary>
  196. /// 出液
  197. /// </summary>
  198. /// <param name="obj"></param>
  199. public async void ExecuteOutLiquidCommand(object obj)
  200. {
  201. if (obj is null)
  202. {
  203. return;
  204. }
  205. object[] receiveObj = obj as object[];
  206. if (receiveObj is null or { Length: 0 })
  207. {
  208. return;
  209. }
  210. string typeName = receiveObj[0].ToString() switch
  211. {
  212. "草酸钠(滴定2)" => EquipmentNames.Sodium2Oxalate,
  213. "草酸钠(滴定1)" => EquipmentNames.Sodium1Oxalate,
  214. "高锰酸钾(加液滴定2)" => EquipmentNames.Titration2PotassiumPermanganate,
  215. "高锰酸钾(滴定1)" => EquipmentNames.Titration1PotassiumPermanganate,
  216. _ => throw new ArgumentException("未找到相关对应"),
  217. };
  218. try
  219. {
  220. switch (typeName)
  221. {
  222. case EquipmentNames.Sodium1Oxalate:
  223. Sodium1OxalateOutLiquidWait = true;
  224. break;
  225. case EquipmentNames.Sodium2Oxalate:
  226. Sodium2OxalateOutLiquidWait = true;
  227. break;
  228. case EquipmentNames.Titration1PotassiumPermanganate:
  229. Titration1PotassiumPermanganateOutLiquidWait = true;
  230. break;
  231. case EquipmentNames.Titration2PotassiumPermanganate:
  232. Titration2PotassiumPermanganateOutLiquidWait = true;
  233. break;
  234. default:
  235. throw new ArgumentNullException(typeName);
  236. }
  237. if (typeName == EquipmentNames.Sodium1Oxalate || typeName == EquipmentNames.Sodium2Oxalate)
  238. {
  239. await _service.ManualLiquidExecuteOxalate(typeName, LiquidSwitchPattern.Out, receiveObj[1]);
  240. }
  241. else
  242. await _service.ManualLiquidExecute(typeName, LiquidSwitchPattern.Out, receiveObj[1]);
  243. }
  244. catch (Exception)
  245. {
  246. Notice.Show("出了点状况,请重新再试~", "Error", 3, MessageBoxIcon.Error);
  247. }
  248. finally
  249. {
  250. switch (typeName)
  251. {
  252. case EquipmentNames.Sodium1Oxalate:
  253. Sodium1OxalateOutLiquidWait = false;
  254. break;
  255. case EquipmentNames.Sodium2Oxalate:
  256. Sodium2OxalateOutLiquidWait = false;
  257. break;
  258. case EquipmentNames.Titration1PotassiumPermanganate:
  259. Titration1PotassiumPermanganateOutLiquidWait = false;
  260. break;
  261. case EquipmentNames.Titration2PotassiumPermanganate:
  262. Titration2PotassiumPermanganateOutLiquidWait = false;
  263. break;
  264. }
  265. }
  266. }
  267. #endregion
  268. #region 柱塞泵(本项目未使用)
  269. /// <summary>
  270. /// 柱塞泵
  271. /// </summary>
  272. /// <param name="obj"></param>
  273. private void ExecuteDirectLiquidCommand(object obj)
  274. {
  275. if (obj is null)
  276. {
  277. return;
  278. }
  279. object[] receiveObj = obj as object[];
  280. if (receiveObj is null or { Length: 0 })
  281. {
  282. return;
  283. }
  284. string typeName = receiveObj[0].ToString() switch
  285. {
  286. "硫酸亚铁铵" => "FAS",
  287. _ => throw new ArgumentException("未找到相关对应"),
  288. };
  289. _service.ManualDirectOutLiquidAsync(typeName, receiveObj[1]);
  290. }
  291. #endregion
  292. #region 蠕动泵
  293. /// <summary>
  294. /// 蠕动泵
  295. /// </summary>
  296. /// <param name="obj"></param>
  297. private void ExecuteRegisterLiquidCommand(object obj)
  298. {
  299. if (obj is null)
  300. {
  301. return;
  302. }
  303. object[] receiveObj = obj as object[];
  304. if (receiveObj is null or { Length: 0 })
  305. {
  306. return;
  307. }
  308. double receiveValue = Math.Abs(Convert.ToDouble(receiveObj[1]));
  309. (string motorName, double value) = receiveObj[0].ToString()?.Trim() switch
  310. {
  311. "氢氧化钠(加液)" => (EquipmentNames.Sodium2Hydroxide, receiveValue),
  312. "氢氧化钠(滴定1)" => (EquipmentNames.Sodium1Hydroxide, receiveValue),
  313. "硫酸(加液滴定2)" => (EquipmentNames.Titration2Vitriol, receiveValue),
  314. "硫酸(滴定1)" => (EquipmentNames.Titration1Vitriol, receiveValue),
  315. _ => throw new ArgumentNullException(receiveObj[0].ToString()?.Trim())
  316. };
  317. _service.ManualWriteRegisterAsync(motorName, value);
  318. }
  319. #endregion
  320. #region 其他
  321. /// <summary>
  322. /// 搅拌开始
  323. /// </summary>
  324. /// <param name="obj"></param>
  325. private void ExecuteStirStartCommand(object obj)
  326. {
  327. OperationRegister(obj, "Stir", RegisterExecuteType.Open);
  328. }
  329. /// <summary>
  330. /// 搅拌结束
  331. /// </summary>
  332. private void ExecuteStirStopCommand(object obj)
  333. {
  334. OperationRegister(obj, "Stir", RegisterExecuteType.Close);
  335. }
  336. /// <summary>
  337. /// 滴嘴移动到原点
  338. /// </summary>
  339. private void ExecuteMoveToYDCommand(object obj)
  340. {
  341. MoveDropper("OrignalPoint");
  342. }
  343. /// <summary>
  344. /// 滴嘴移动到加液
  345. /// </summary>
  346. private void ExecuteMoveToJYCommand(object obj)
  347. {
  348. MoveDropper("AddLiquid");
  349. }
  350. /// <summary>
  351. /// 滴嘴移动到滴定2
  352. /// </summary>
  353. private void ExecuteMoveToDD2Command(object obj)
  354. {
  355. MoveDropper("Titration2");
  356. }
  357. private async void MoveDropper(Object obj)
  358. {
  359. if (obj.ToString()?.Trim() == "OrignalPoint")
  360. {
  361. bool res3 = await _service.MotorGoBackAsync(EquipmentNames.AxisD);
  362. Notice.Show($"返回原点{(res3 ? "成功" : "失败")}", "Info", 3, MessageBoxIcon.Info);
  363. }
  364. else
  365. {
  366. double value = obj.ToString()?.Trim() switch
  367. {
  368. "Titration2" => -1*70,
  369. "AddLiquid" => -1*170,
  370. _ => throw new ArgumentNullException(obj.ToString()?.Trim())
  371. };
  372. bool res2 = await _service.ManualWriteMoveToDMotor(EquipmentNames.AxisD, value, MotorManualMoveType.Forward);
  373. Notice.Show($"滴嘴运动到位{(res2 ? "成功" : "失败")}", "Info", 3, MessageBoxIcon.Info);
  374. }
  375. }
  376. /// <summary>
  377. /// 滴嘴正向
  378. /// </summary>
  379. /// <param name="obj"></param>
  380. private void ExecuteDropperFrontCommand(object obj)
  381. {
  382. string epType = obj.ToString() switch
  383. {
  384. "《" => "TitrationMove",
  385. "-" => "TitrationStop",
  386. "正" => "Titration",
  387. _ => throw new ArgumentNullException(obj.ToString()),
  388. };
  389. _service.ElectricDropper(epType, RegisterExecuteType.Open);
  390. }
  391. /// <summary>
  392. /// 滴嘴反向
  393. /// </summary>
  394. /// <param name="obj"></param>
  395. private void ExecuteDropperInversionCommand(object obj)
  396. {
  397. string epType = obj.ToString() switch
  398. {
  399. "》" => "TitrationMove",
  400. "反" => "Titration",
  401. _ => throw new ArgumentNullException(obj.ToString()),
  402. };
  403. _service.ElectricDropper(epType, RegisterExecuteType.Close);
  404. }
  405. private void ExecuteDropperPointCommand(object obj)
  406. {
  407. string epType = obj.ToString() switch
  408. {
  409. "原点" => "Titration",
  410. _ => throw new ArgumentNullException(obj.ToString()),
  411. };
  412. _service.ElectricDropper(epType, RegisterExecuteType.Point);
  413. }
  414. #endregion
  415. #endregion
  416. #region Method
  417. /// <summary>
  418. /// 寄存器操作
  419. /// </summary>
  420. /// <param name="obj">名称</param>
  421. /// <param name="type">类型</param>
  422. /// <param name="opKey">操作符</param>
  423. private bool OperationRegister(object obj, string element, RegisterExecuteType type)
  424. {
  425. ConvertToEquipmentType(obj, out string epType);
  426. return _service.ManualControlRegister(string.Concat(epType, element), type);
  427. }
  428. /// <summary>
  429. /// 获取设备名称
  430. /// </summary>
  431. private static void ConvertToEquipmentType(object obj, out string epType)
  432. {
  433. epType = obj.ToString() switch
  434. {
  435. "加液" => "AddLiquid",
  436. "滴定" => "Titration",
  437. "滴定2" => "Titration2",
  438. _ => throw new ArgumentNullException(obj.ToString()),
  439. };
  440. }
  441. #endregion
  442. }
  443. }