|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- using BPASmartClient.Business;
- using BPASmartClient.Device;
- using BPASmartClient.DRCoffee;
- using BPASmartClient.EventBus;
- using BPASmartClient.Helper;
- using BPASmartClient.LebaiRobot;
- using BPASmartClient.Message;
- using BPASmartClient.Model;
- using BPASmartClient.Model.乐白机器人;
- using BPASmartClient.Model.冰淇淋.Enum;
- using BPASmartClient.Model.单片机;
- using BPASmartClient.Model.单片机.Enum;
- using BPASmartClient.Model.咖啡机.Enum;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Threading;
- namespace BPASmartClient.MorkT_BarCounter.ViewModel;
- public class TestViewModel : ObservableObject
- {
-
- #region 乐白机器人
- /// <summary>
- /// 乐白机器人连接状态
- /// </summary>
- public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } }
- private string _robotConnected { get; set; }
- /// <summary>
- /// 乐白机器人的模式状态
- /// </summary>
- public string RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } }
- private string _robotMode { get; set; }
- /// <summary>
- /// 机器人控制指令
- /// </summary>
- public RelayCommand<object> Button_RobotControlCommand { get; set; }
-
- public RelayCommand Robot_DOutput { get; set; }
- /// <summary>
- /// 机器人控制
- /// </summary>
- /// <param name="o"></param>
- private void Button_RobotControl(object o)
- {
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
- }
- private void Button_RobotDoutput()
- {
- bool DO_Value =int.Parse(Robot_DOutput_Value) == 0;
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { Pin = int.Parse(Robot_DOutput_Pin), Value = DO_Value });
- }
- public string Robot_TCPDI0 { get { return _robot_TCPDI0; } set { _robot_TCPDI0 = value;OnPropertyChanged(); } }
- private string _robot_TCPDI0;
-
- public string Robot_DI0 { get { return _robot_DI0; } set { _robot_DI0 = value; OnPropertyChanged(); } }
- private string _robot_DI0;
- public string Robot_DI1 { get { return _robot_DI1; } set { _robot_DI1 = value; OnPropertyChanged(); } }
- private string _robot_DI1;
- public string Robot_DI2 { get { return _robot_DI2; } set { _robot_DI2 = value; OnPropertyChanged(); } }
- private string _robot_DI2;
- public string Robot_DI3 { get { return _robot_DI3; } set { _robot_DI3 = value; OnPropertyChanged(); } }
- private string _robot_DI3;
-
-
- public string Robot_DOutput_Pin { get { return _robot_DOutput_Pin; } set { _robot_DOutput_Pin = value; OnPropertyChanged(); } }
- private string _robot_DOutput_Pin { get; set; }
- public string Robot_DOutput_Value { get { return _robot_DOutput_Valuet; } set { _robot_DOutput_Valuet = value; OnPropertyChanged(); } }
- private string _robot_DOutput_Valuet { get; set; }
- #endregion
- #region 单片机
- public string MCUConnected { get { return _mcuConnected; } set { _mcuConnected = value; OnPropertyChanged(); } }
- private string _mcuConnected { get; set; }
-
- public string MCUDI0 { get { return _mCUDI0; } set { _mCUDI0 = value; OnPropertyChanged(); } }
- private string _mCUDI0 { get; set; }
- public string MCUDI1 { get { return _mCUDI1; } set { _mCUDI1 = value; OnPropertyChanged(); } }
- private string _mCUDI1 { get; set; }
- public string MCUDI2 { get { return _mCUDI2; } set { _mCUDI2 = value; OnPropertyChanged(); } }
- private string _mCUDI2 { get; set; }
- public string MCUDI3 { get { return _mCUDI3; } set { _mCUDI3 = value; OnPropertyChanged(); } }
- private string _mCUDI3 { get; set; }
- public string MCUDI4 { get { return _mCUDI4; } set { _mCUDI4 = value; OnPropertyChanged(); } }
- private string _mCUDI4 { get; set; }
- public string MCUDI5 { get { return _mCUDI5; } set { _mCUDI5 = value; OnPropertyChanged(); } }
- private string _mCUDI5 { get; set; }
- public string MCUDI6 { get { return _mCUDI6; } set { _mCUDI6 = value; OnPropertyChanged(); } }
- private string _mCUDI6 { get; set; }
- public string MCUDI7 { get { return _mCUDI7; } set { _mCUDI7 = value; OnPropertyChanged(); } }
- private string _mCUDI7 { get; set; }
-
- public RelayCommand Button_MCUOuputCommand { get; set; }
- public RelayCommand Button_MCUDOuputCommand { get; set; }
-
- public int MCU_PWM_CH { get { return _choosePWM; } set { _choosePWM = value; OnPropertyChanged(); } }
- private int _choosePWM = 1;
- public int PWMInputNumber { get { return _pwmInputNumber; } set { _pwmInputNumber = value; OnPropertyChanged(); } }
- private int _pwmInputNumber = 1;
-
- private int[] DICH { get { return _diCH; } set { _diCH = value; OnPropertyChanged(); } }
- private int[] _diCH = new int[8];
-
- public int MCU_DO_CH { get { return _mcuDO_CH; } set { _mcuDO_CH = value; OnPropertyChanged(); } }
- private int _mcuDO_CH = 1;
- public bool MCU_DO_Value { get { return _mcu_DO_Valuer; } set { _mcu_DO_Valuer = value; OnPropertyChanged(); } }
- private bool _mcu_DO_Valuer = true;
-
- private void Button_McuPWMOutput()
- {
- string sChoosePWM = Convert.ToString(MCU_PWM_CH + 1);
- new WriteMcu() { TagName = "ServoControl", Address = sChoosePWM, Value = PWMInputNumber }.Publish();
- }
- private void Button_McuDOutput()
- {
- string sChooseDO = Convert.ToString(MCU_DO_CH + 1);
- new WriteMcu() { TagName = "OutputControl", Address = sChooseDO, Value = MCU_DO_Value }.Publish();
- }
- #endregion
- #region 果汁机
- /// <summary>
- /// 果汁机的连接状态
- /// </summary>
- public string JuicerConnected { get { return _JuicerConnected; } set { _JuicerConnected = value; OnPropertyChanged(); } }
- private string _JuicerConnected { get; set; }
-
- public string JuiceState_Heating { get { return _juiceState_Heating; } set { _juiceState_Heating = value;OnPropertyChanged(); } }
- public string _juiceState_Heating { get; set; }
- public string JuiceState_Cooling { get { return _juiceState_Cooling; } set { _juiceState_Cooling = value; OnPropertyChanged(); } }
- public string _juiceState_Cooling { get; set; }
- public string JuiceState_LackOfWater { get { return _juiceState_LackOfWater; } set { _juiceState_LackOfWater = value; OnPropertyChanged(); } }
- public string _juiceState_LackOfWater { get; set; }
- public string JuiceState_ChildLocks { get { return _juiceState_ChildLocks; } set { _juiceState_ChildLocks = value; OnPropertyChanged(); } }
- public string _juiceState_ChildLocks { get; set; }
- public string JuiceState_Using { get { return _juiceState_Using; } set { _juiceState_Using = value; OnPropertyChanged(); } }
- public string _juiceState_Using { get; set; }
-
- public string MakeJuice_Index { get { return _makeJuice_Index; } set { _makeJuice_Index = value; OnPropertyChanged(); } }
- public string _makeJuice_Index { get; set; }
-
- public RelayCommand Button_MakeJuiceCommand { get; set; }
-
- public void Button_MakeJuice()
- {
- new WriteJuicer() { Value = MakeJuice_Index }.Publish();
- }
- #endregion
- #region 制冰机
- public string IceMakerConnect { get { return _iceMakerConnect; } set { _iceMakerConnect = value;OnPropertyChanged(); } }
- private string _iceMakerConnect { get; set; }
- public string IceMakerState { get { return _iceMakerState; } set { _iceMakerState = value; OnPropertyChanged(); } }
- private string _iceMakerState { get; set; }
- public int IceMaker_IceTime { get { return _iceMaker_IceTime; } set { _iceMaker_IceTime = value; OnPropertyChanged(); } }
- private int _iceMaker_IceTime = 3;
-
- #region 订单模拟
- public RelayCommand SimOrderMakeCoffee { get; set; }
- public RelayCommand SimOrderMakeJuice { get; set; }
- public RelayCommand SimOrderMakeTea { get; set; }
- public RelayCommand SimOrderMakeWater { get; set; }
-
- public int SimOrder_JuiceList { get { return _simOrder_JuiceList; } set { _simOrder_JuiceList = value; OnPropertyChanged(); } }
- public int _simOrder_JuiceList { get; set; }
- public string SimOrder_JuiceMakeID { get { return _simOrder_JuiceMakeID; } set { _simOrder_JuiceMakeID = value; OnPropertyChanged(); } }
- public string _simOrder_JuiceMakeID { get; set; }
- #endregion
-
- public RelayCommand IceMaker_BtnPowerOn { get; set; }
- public RelayCommand IceMaker_BtnStandby { get; set;}
- public RelayCommand IceMaker_BtnPump { get; set;}
-
- public RelayCommand IceMaker_BtnStart { get; set; }
- public RelayCommand IceMaker_BtnEnd { get; set; }
- public RelayCommand IceMaker_BtnSetIceTime { get; set; }
-
- private void IceMaker_BtnPowerOnCommand()
- {
- new PowerOnMakeIce().Publish();
- }
- private void IceMaker_BtnStandbyCommand()
- {
- new StandbyMakeIce().Publish();
- }
- private void IceMaker_BtnPumpCommand()
- {
- new PumpMakeIce().Publish();
- }
- private void IceMaker_BtnStartCommand()
- {
- new StartMakeIce().Publish();
- }
- private void IceMaker_BtnEndCommand()
- {
- new StopMakeIce().Publish();
- }
- private void IceMaker_BtnSetIceTimeCommand()
- {
- new SetIceNumber{ Value= IceMaker_IceTime }.Publish();
- }
- #endregion
- #region 咖啡机
- /// <summary>
- /// 咖啡机连接状态
- /// </summary>
- public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } }
- private string _coffeeConnected { get; set; }
- /// <summary>
- /// 咖啡机状态
- /// </summary>
- public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } }
- private string _coffeeStatus { get; set; }
- /// <summary>
- /// 应用状态
- /// </summary>
- public string AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } }
- private string _appStatus { get; set; }
- /// <summary>
- /// 告警
- /// </summary>
- public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
- public string _warning { get; set; }
- /// <summary>
- /// 故障信息
- /// </summary>
- public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } }
- public string _caffeeFault { get; set; }
-
- public List<string> Coffees { get; set; } = new List<string>();
- public string SelectedCoffee { get { return _selectedCoffee; } set { _selectedCoffee = value; OnPropertyChanged(); } }
- public string _selectedCoffee { get; set; }
-
- public List<string> CoffeeCmds { get; set; } = new List<string>();
- public string SelectedCoffeeCmd { get; set; }
-
-
- public string SimOrderCoffeeList { get { return _simOrderCoffeeList; } set { _simOrderCoffeeList = value; OnPropertyChanged(); } }
- public string _simOrderCoffeeList { get; set; }
-
- /// <summary>
- /// 制作咖啡
- /// </summary>
- public RelayCommand Button_MakeCoffeeCommand { get; set; }
- /// <summary>
- /// 停止制作咖啡
- /// </summary>
- public RelayCommand Button_StopMakeCoffeCommand { get; set; }
- /// <summary>
- /// 咖啡模式设置
- /// </summary>
- public RelayCommand Button_CoffeeModeSetCommand { get; set; }
-
- private void Button_MakeCoffee()
- {
- EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee) });
- }
- private void Button_StopMakeCoffe()
- {
- EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
- }
- private void Button_CoffeeModeSet()
- {
- EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd) });
- }
-
- #endregion
- /// <summary>
- /// 设备ID
- /// </summary>
- public int DeviceId { get; set; }
- /// <summary>
- /// 设备数据
- /// </summary>
- public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
-
- public TestViewModel()
- {
- SimOrderMakeCoffee = new RelayCommand(() =>
- {
- new MorkTSimOrder() { OrderNum = 1, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SimOrderCoffeeList) }.Publish();
- });
- SimOrderMakeJuice = new RelayCommand(() =>
- {
- new MorkTSimOrder() { OrderNum = 2, JuiceList = SimOrder_JuiceList, JuiceMakeID = SimOrder_JuiceMakeID }.Publish();
- });
- SimOrderMakeTea = new RelayCommand(() =>
- {
- new MorkTSimOrder() { OrderNum = 3 }.Publish();
- });
- SimOrderMakeWater = new RelayCommand(() =>
- {
- new MorkTSimOrder() { OrderNum = 4 }.Publish();
- });
- Button_RobotControlCommand = new RelayCommand<object>(Button_RobotControl);
- Robot_DOutput = new RelayCommand(Button_RobotDoutput);
-
- Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee);
- Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe);
- Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet);
-
- Button_MCUOuputCommand = new RelayCommand(Button_McuPWMOutput);
- Button_MCUDOuputCommand = new RelayCommand(Button_McuDOutput);
-
- Button_MakeJuiceCommand = new RelayCommand(Button_MakeJuice);
-
- IceMaker_BtnPowerOn = new RelayCommand(IceMaker_BtnPowerOnCommand);
- IceMaker_BtnStandby = new RelayCommand(IceMaker_BtnStandbyCommand);
- IceMaker_BtnPump = new RelayCommand(IceMaker_BtnPumpCommand);
- IceMaker_BtnStart = new RelayCommand(IceMaker_BtnStartCommand);
- IceMaker_BtnEnd = new RelayCommand(IceMaker_BtnEndCommand);
- IceMaker_BtnSetIceTime = new RelayCommand(IceMaker_BtnSetIceTimeCommand);
-
- foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode)))
- {
- Coffees.Add(code.ToString());
- }
- SelectedCoffee = Coffees[0];
- SimOrderCoffeeList = Coffees[0];
- foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
- {
- CoffeeCmds.Add(code.ToString());
- }
- SelectedCoffeeCmd = CoffeeCmds[0];
-
- Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
- {
- if (device.Name == "MorkT") DeviceId = device.DeviceId
- ;
- });
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- variableMonitors = Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
- if (variableMonitors != null && variableMonitors.Count > 0)
- {
- #region 机器人
- RobotConnected = variableMonitors.FirstOrDefault(p => p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
- Robot_TCPDI0 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人TCP输入状态").CurrentValue;
- Robot_DI0 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入0状态").CurrentValue;
- Robot_DI1 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入1状态").CurrentValue;
- Robot_DI2 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入2状态").CurrentValue;
- Robot_DI3 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入3状态").CurrentValue;
-
- #endregion
-
- #region 咖啡机
- CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
- AppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
- Warning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
- CaffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
- #endregion
-
- #region 单片机
- MCUConnected = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- MCUDI0 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入0状态").CurrentValue;
- MCUDI1 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入1状态").CurrentValue;
- MCUDI2 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入2状态").CurrentValue;
- MCUDI3 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入3状态").CurrentValue;
- MCUDI4 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入4状态").CurrentValue;
- MCUDI5 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入5状态").CurrentValue;
- MCUDI6 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入6状态").CurrentValue;
- MCUDI7 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入7状态").CurrentValue;
- #endregion
-
- #region 制冰机
- IceMakerConnect = variableMonitors.FirstOrDefault(p => p.Notes == "制冰机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- IceMakerState = variableMonitors.FirstOrDefault(p => p.Notes == "制冰机设备状态").CurrentValue;
- #endregion
-
-
- #region 果汁机
- JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- JuiceState_Heating = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机制热").CurrentValue;
- JuiceState_Cooling = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机制冷").CurrentValue;
- JuiceState_LackOfWater = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机缺水").CurrentValue;
- JuiceState_ChildLocks = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机童锁").CurrentValue;
- JuiceState_Using = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机使用").CurrentValue;
-
- #endregion
- }
- Thread.Sleep(500);
- }), "MorkT-状态刷新");
- }
- }
-
|