| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- using System;
- using Prism.Mvvm;
- using Prism.Commands;
- using Panuon.UI.Silver;
- using SHJX.Service.Model.Enums;
- using SHJX.Service.Common.Constants;
- using SHJX.Service.Control.Interface;
- namespace SHJX.Service.Shell.ViewModels.Manual
- {
- public class LiquidManualWindowViewModel : BindableBase
- {
- #region Field
- private readonly IManualService _service;
- #endregion
- #region Properties
- #region In Wait
- private bool _sodium1OxalateInLiquidWait;
- public bool Sodium1OxalateInLiquidWait
- {
- get => _sodium1OxalateInLiquidWait;
- set => SetProperty(ref _sodium1OxalateInLiquidWait, value);
- }
- private bool _sodium2OxalateInLiquidWait;
- public bool Sodium2OxalateInLiquidWait
- {
- get => _sodium2OxalateInLiquidWait;
- set => SetProperty(ref _sodium2OxalateInLiquidWait, value);
- }
- //private bool _addLiquidPotassiumPermanganateInLiquidWait;
- //public bool AddLiquidPotassiumPermanganateInLiquidWait
- //{
- // get => _addLiquidPotassiumPermanganateInLiquidWait;
- // set => SetProperty(ref _addLiquidPotassiumPermanganateInLiquidWait, value);
- //}
- private bool _titration1PotassiumPermanganateInLiquidWait;
- public bool Titration1PotassiumPermanganateInLiquidWait
- {
- get => _titration1PotassiumPermanganateInLiquidWait;
- set => SetProperty(ref _titration1PotassiumPermanganateInLiquidWait, value);
- }
- private bool _titration2PotassiumPermanganateInLiquidWait;
- public bool Titration2PotassiumPermanganateInLiquidWait
- {
- get => _titration2PotassiumPermanganateInLiquidWait;
- set => SetProperty(ref _titration2PotassiumPermanganateInLiquidWait, value);
- }
- #endregion
- #region Out Wait
- private bool _sodium1OxalateOutLiquidWait;
- public bool Sodium1OxalateOutLiquidWait
- {
- get => _sodium1OxalateOutLiquidWait;
- set => SetProperty(ref _sodium1OxalateOutLiquidWait, value);
- }
- private bool _sodium2OxalateOutLiquidWait;
- public bool Sodium2OxalateOutLiquidWait
- {
- get => _sodium2OxalateOutLiquidWait;
- set => SetProperty(ref _sodium2OxalateOutLiquidWait, value);
- }
- //private bool _addLiquidPotassiumPermanganateOutLiquidWait;
- //public bool AddLiquidPotassiumPermanganateOutLiquidWait
- //{
- // get => _addLiquidPotassiumPermanganateOutLiquidWait;
- // set => SetProperty(ref _addLiquidPotassiumPermanganateOutLiquidWait, value);
- //}
- private bool _titration1PotassiumPermanganateOutLiquidWait;
- public bool Titration1PotassiumPermanganateOutLiquidWait
- {
- get => _titration1PotassiumPermanganateOutLiquidWait;
- set => SetProperty(ref _titration1PotassiumPermanganateOutLiquidWait, value);
- }
- private bool _titration2PotassiumPermanganateOutLiquidWait;
- public bool Titration2PotassiumPermanganateOutLiquidWait
- {
- get => _titration2PotassiumPermanganateOutLiquidWait;
- set => SetProperty(ref _titration2PotassiumPermanganateOutLiquidWait, value);
- }
- #endregion
- #endregion
- public LiquidManualWindowViewModel(IManualService service)
- {
- _service = service;
- Sodium1OxalateInLiquidWait = false;
- Sodium2OxalateInLiquidWait = false;
- //AddLiquidPotassiumPermanganateInLiquidWait = false;
- Titration1PotassiumPermanganateInLiquidWait = false;
- Titration2PotassiumPermanganateInLiquidWait = false;
- Sodium1OxalateOutLiquidWait = false;
- Sodium2OxalateOutLiquidWait = false;
- //AddLiquidPotassiumPermanganateOutLiquidWait = false;
- Titration1PotassiumPermanganateOutLiquidWait = false;
- Titration2PotassiumPermanganateOutLiquidWait = false;
- }
- #region Command
- private DelegateCommand<object> _registerLiquidCommand;
- public DelegateCommand<object> RegisterLiquidCommand => _registerLiquidCommand ??= new DelegateCommand<object>(ExecuteRegisterLiquidCommand);
- private DelegateCommand<object> _inLiquidCommand;
- public DelegateCommand<object> InLiquidCommand => _inLiquidCommand ??= new DelegateCommand<object>(ExecuteInLiquidCommand);
- private DelegateCommand<object> _outLiquidCommand;
- public DelegateCommand<object> OutLiquidCommand => _outLiquidCommand ??= new DelegateCommand<object>(ExecuteOutLiquidCommand);
- private DelegateCommand<object> _directLiquidCommand;
- public DelegateCommand<object> DirectLiquidCommand => _directLiquidCommand ??= new DelegateCommand<object>(ExecuteDirectLiquidCommand);
- private DelegateCommand<object> _dropperFrontCommand;
- public DelegateCommand<object> DropperFrontCommand => _dropperFrontCommand ??= new DelegateCommand<object>(ExecuteDropperFrontCommand);
- private DelegateCommand<object> _dropperInversionCommand;
- public DelegateCommand<object> DropperInversionCommand => _dropperInversionCommand ??= new DelegateCommand<object>(ExecuteDropperInversionCommand);
- private DelegateCommand<object> _dropperPointCommand;
- public DelegateCommand<object> DropperPointCommand => _dropperPointCommand ??= new DelegateCommand<object>(ExecuteDropperPointCommand);
- private DelegateCommand<object> _stirStartCommand;
- public DelegateCommand<object> StirStartCommand => _stirStartCommand ??= new DelegateCommand<object>(ExecuteStirStartCommand);
- private DelegateCommand<object> _stirStopCommand;
- public DelegateCommand<object> StirStopCommand => _stirStopCommand ??= new DelegateCommand<object>(ExecuteStirStopCommand);
- private DelegateCommand<object> _moveToYDCommand;
- public DelegateCommand<object> MoveToYDCommand => _moveToYDCommand ??= new DelegateCommand<object>(ExecuteMoveToYDCommand);
- private DelegateCommand<object> _moveToJYCommand;
- public DelegateCommand<object> MoveToJYCommand => _moveToJYCommand ??= new DelegateCommand<object>(ExecuteMoveToJYCommand);
- private DelegateCommand<object> _moveToDD2Command;
- public DelegateCommand<object> MoveToDD2Command => _moveToDD2Command ??= new DelegateCommand<object>(ExecuteMoveToDD2Command);
- #endregion
- #region Pump Execute
- #region 注射泵
- /// <summary>
- /// 吸液
- /// </summary>
- /// <param name="obj"></param>
- public async void ExecuteInLiquidCommand(object obj)
- {
- if (obj is null)
- {
- return;
- }
- object[] receiveObj = obj as object[];
- if (receiveObj is null or { Length: 0 })
- {
- return;
- }
- string typeName = receiveObj[0].ToString() switch
- {
- "草酸钠(滴定2)" => EquipmentNames.Sodium2Oxalate,
- "草酸钠(滴定1)" => EquipmentNames.Sodium1Oxalate,
- "高锰酸钾(加液滴定2)" => EquipmentNames.Titration2PotassiumPermanganate,
- "高锰酸钾(滴定1)" => EquipmentNames.Titration1PotassiumPermanganate,
- _ => throw new ArgumentException("未找到相关对应"),
- };
- try
- {
- switch (typeName)
- {
- case EquipmentNames.Sodium1Oxalate:
- Sodium1OxalateInLiquidWait = true;
- break;
- case EquipmentNames.Sodium2Oxalate:
- Sodium2OxalateInLiquidWait = true;
- break;
- case EquipmentNames.Titration1PotassiumPermanganate:
- Titration1PotassiumPermanganateInLiquidWait = true;
- break;
- case EquipmentNames.Titration2PotassiumPermanganate:
- Titration2PotassiumPermanganateInLiquidWait = true;
- break;
- default:
- throw new ArgumentNullException(typeName);
- }
- if (typeName==EquipmentNames.Sodium1Oxalate|| typeName == EquipmentNames.Sodium2Oxalate)
- {
- await _service.ManualLiquidExecuteOxalate(typeName,LiquidSwitchPattern.In, receiveObj[1]);
- }
- else
- await _service.ManualLiquidExecute(typeName, LiquidSwitchPattern.In, receiveObj[1]);
- }
- catch (Exception)
- {
- Notice.Show("出了点状况,请重新再试~", "Error", 3, MessageBoxIcon.Error);
- }
- finally
- {
- switch (typeName)
- {
- case EquipmentNames.Sodium1Oxalate:
- Sodium1OxalateInLiquidWait = false;
- break;
- case EquipmentNames.Sodium2Oxalate:
- Sodium2OxalateInLiquidWait = false;
- break;
- case EquipmentNames.Titration1PotassiumPermanganate:
- Titration1PotassiumPermanganateInLiquidWait = false;
- break;
- case EquipmentNames.Titration2PotassiumPermanganate:
- Titration2PotassiumPermanganateInLiquidWait = false;
- break;
- }
- }
- }
- /// <summary>
- /// 出液
- /// </summary>
- /// <param name="obj"></param>
- public async void ExecuteOutLiquidCommand(object obj)
- {
- if (obj is null)
- {
- return;
- }
- object[] receiveObj = obj as object[];
- if (receiveObj is null or { Length: 0 })
- {
- return;
- }
- string typeName = receiveObj[0].ToString() switch
- {
- "草酸钠(滴定2)" => EquipmentNames.Sodium2Oxalate,
- "草酸钠(滴定1)" => EquipmentNames.Sodium1Oxalate,
- "高锰酸钾(加液滴定2)" => EquipmentNames.Titration2PotassiumPermanganate,
- "高锰酸钾(滴定1)" => EquipmentNames.Titration1PotassiumPermanganate,
- _ => throw new ArgumentException("未找到相关对应"),
- };
- try
- {
- switch (typeName)
- {
- case EquipmentNames.Sodium1Oxalate:
- Sodium1OxalateOutLiquidWait = true;
- break;
- case EquipmentNames.Sodium2Oxalate:
- Sodium2OxalateOutLiquidWait = true;
- break;
- case EquipmentNames.Titration1PotassiumPermanganate:
- Titration1PotassiumPermanganateOutLiquidWait = true;
- break;
- case EquipmentNames.Titration2PotassiumPermanganate:
- Titration2PotassiumPermanganateOutLiquidWait = true;
- break;
- default:
- throw new ArgumentNullException(typeName);
- }
- if (typeName == EquipmentNames.Sodium1Oxalate || typeName == EquipmentNames.Sodium2Oxalate)
- {
- await _service.ManualLiquidExecuteOxalate(typeName, LiquidSwitchPattern.Out, receiveObj[1]);
- }
- else
- await _service.ManualLiquidExecute(typeName, LiquidSwitchPattern.Out, receiveObj[1]);
- }
- catch (Exception)
- {
- Notice.Show("出了点状况,请重新再试~", "Error", 3, MessageBoxIcon.Error);
- }
- finally
- {
- switch (typeName)
- {
- case EquipmentNames.Sodium1Oxalate:
- Sodium1OxalateOutLiquidWait = false;
- break;
- case EquipmentNames.Sodium2Oxalate:
- Sodium2OxalateOutLiquidWait = false;
- break;
- case EquipmentNames.Titration1PotassiumPermanganate:
- Titration1PotassiumPermanganateOutLiquidWait = false;
- break;
- case EquipmentNames.Titration2PotassiumPermanganate:
- Titration2PotassiumPermanganateOutLiquidWait = false;
- break;
- }
- }
- }
- #endregion
- #region 柱塞泵(本项目未使用)
- /// <summary>
- /// 柱塞泵
- /// </summary>
- /// <param name="obj"></param>
- private void ExecuteDirectLiquidCommand(object obj)
- {
- if (obj is null)
- {
- return;
- }
- object[] receiveObj = obj as object[];
- if (receiveObj is null or { Length: 0 })
- {
- return;
- }
- string typeName = receiveObj[0].ToString() switch
- {
- "硫酸亚铁铵" => "FAS",
- _ => throw new ArgumentException("未找到相关对应"),
- };
- _service.ManualDirectOutLiquidAsync(typeName, receiveObj[1]);
- }
- #endregion
- #region 蠕动泵
- /// <summary>
- /// 蠕动泵
- /// </summary>
- /// <param name="obj"></param>
- private void ExecuteRegisterLiquidCommand(object obj)
- {
- if (obj is null)
- {
- return;
- }
- object[] receiveObj = obj as object[];
- if (receiveObj is null or { Length: 0 })
- {
- return;
- }
- double receiveValue = Math.Abs(Convert.ToDouble(receiveObj[1]));
- (string motorName, double value) = receiveObj[0].ToString()?.Trim() switch
- {
- "氢氧化钠(加液)" => (EquipmentNames.Sodium2Hydroxide, receiveValue),
- "氢氧化钠(滴定1)" => (EquipmentNames.Sodium1Hydroxide, receiveValue),
- "硫酸(加液滴定2)" => (EquipmentNames.Titration2Vitriol, receiveValue),
- "硫酸(滴定1)" => (EquipmentNames.Titration1Vitriol, receiveValue),
- _ => throw new ArgumentNullException(receiveObj[0].ToString()?.Trim())
- };
- _service.ManualWriteRegisterAsync(motorName, value);
- }
- #endregion
- #region 其他
- /// <summary>
- /// 搅拌开始
- /// </summary>
- /// <param name="obj"></param>
- private void ExecuteStirStartCommand(object obj)
- {
- OperationRegister(obj, "Stir", RegisterExecuteType.Open);
- }
- /// <summary>
- /// 搅拌结束
- /// </summary>
- private void ExecuteStirStopCommand(object obj)
- {
- OperationRegister(obj, "Stir", RegisterExecuteType.Close);
- }
- /// <summary>
- /// 滴嘴移动到原点
- /// </summary>
- private void ExecuteMoveToYDCommand(object obj)
- {
- MoveDropper("OrignalPoint");
- }
- /// <summary>
- /// 滴嘴移动到加液
- /// </summary>
- private void ExecuteMoveToJYCommand(object obj)
- {
- MoveDropper("AddLiquid");
- }
- /// <summary>
- /// 滴嘴移动到滴定2
- /// </summary>
- private void ExecuteMoveToDD2Command(object obj)
- {
- MoveDropper("Titration2");
- }
- private async void MoveDropper(Object obj)
- {
- if (obj.ToString()?.Trim() == "OrignalPoint")
- {
- bool res3 = await _service.MotorGoBackAsync(EquipmentNames.AxisD);
- Notice.Show($"返回原点{(res3 ? "成功" : "失败")}", "Info", 3, MessageBoxIcon.Info);
- }
- else
- {
- double value = obj.ToString()?.Trim() switch
- {
- "Titration2" => -1*70,
- "AddLiquid" => -1*170,
- _ => throw new ArgumentNullException(obj.ToString()?.Trim())
- };
- bool res2 = await _service.ManualWriteMoveToDMotor(EquipmentNames.AxisD, value, MotorManualMoveType.Forward);
- Notice.Show($"滴嘴运动到位{(res2 ? "成功" : "失败")}", "Info", 3, MessageBoxIcon.Info);
- }
- }
- /// <summary>
- /// 滴嘴正向
- /// </summary>
- /// <param name="obj"></param>
- private void ExecuteDropperFrontCommand(object obj)
- {
- string epType = obj.ToString() switch
- {
- "《" => "TitrationMove",
- "-" => "TitrationStop",
- "正" => "Titration",
- _ => throw new ArgumentNullException(obj.ToString()),
- };
- _service.ElectricDropper(epType, RegisterExecuteType.Open);
- }
- /// <summary>
- /// 滴嘴反向
- /// </summary>
- /// <param name="obj"></param>
- private void ExecuteDropperInversionCommand(object obj)
- {
- string epType = obj.ToString() switch
- {
- "》" => "TitrationMove",
- "反" => "Titration",
- _ => throw new ArgumentNullException(obj.ToString()),
- };
- _service.ElectricDropper(epType, RegisterExecuteType.Close);
- }
- private void ExecuteDropperPointCommand(object obj)
- {
- string epType = obj.ToString() switch
- {
- "原点" => "Titration",
- _ => throw new ArgumentNullException(obj.ToString()),
- };
- _service.ElectricDropper(epType, RegisterExecuteType.Point);
- }
-
- #endregion
- #endregion
- #region Method
- /// <summary>
- /// 寄存器操作
- /// </summary>
- /// <param name="obj">名称</param>
- /// <param name="type">类型</param>
- /// <param name="opKey">操作符</param>
- private bool OperationRegister(object obj, string element, RegisterExecuteType type)
- {
- ConvertToEquipmentType(obj, out string epType);
- return _service.ManualControlRegister(string.Concat(epType, element), type);
- }
- /// <summary>
- /// 获取设备名称
- /// </summary>
- private static void ConvertToEquipmentType(object obj, out string epType)
- {
- epType = obj.ToString() switch
- {
- "加液" => "AddLiquid",
- "滴定" => "Titration",
- "滴定2" => "Titration2",
- _ => throw new ArgumentNullException(obj.ToString()),
- };
- }
- #endregion
- }
- }
|