|
- using BPASmartClient.Business;
- using BPASmartClient.Device;
- using BPASmartClient.DRCoffee;
-
- using BPA.Helper;
- using BPASmartClient.LebaiRobot;
-
- using BPASmartClient.Model;
- using BPASmartClient.Model.乐白机器人;
- using BPASmartClient.Model.冰淇淋.Enum;
- using BPASmartClient.Model.单片机;
- using BPASmartClient.Model.单片机.Enum;
- using BPASmartClient.Model.咖啡机.Enum;
- using BPA.Helper;
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Threading;
- namespace BPASmartClient.MorkT_BarCounter.ViewModel;
- public class TestViewModel : NotifyBase
- {
-
- #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 BPARelayCommand<object> Button_RobotControlCommand { get; set; }
-
- public BPARelayCommand Robot_DOutput { get; set; }
- /// <summary>
- /// 机器人控制
- /// </summary>
- /// <param name="o"></param>
- private void Button_RobotControl(object o)
- {
- 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.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 BPARelayCommand Button_MCUOuputCommand { get; set; }
- public BPARelayCommand 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 BPARelayCommand 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 BPARelayCommand SimOrderMakeCoffee { get; set; }
- public BPARelayCommand SimOrderMakeJuice { get; set; }
- public BPARelayCommand SimOrderMakeTea { get; set; }
- public BPARelayCommand 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 BPARelayCommand IceMaker_BtnPowerOn { get; set; }
- public BPARelayCommand IceMaker_BtnStandby { get; set;}
- public BPARelayCommand IceMaker_BtnPump { get; set;}
-
- public BPARelayCommand IceMaker_BtnStart { get; set; }
- public BPARelayCommand IceMaker_BtnEnd { get; set; }
- public BPARelayCommand 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 BPARelayCommand Button_MakeCoffeeCommand { get; set; }
- /// <summary>
- /// 停止制作咖啡
- /// </summary>
- public BPARelayCommand Button_StopMakeCoffeCommand { get; set; }
- /// <summary>
- /// 咖啡模式设置
- /// </summary>
- public BPARelayCommand Button_CoffeeModeSetCommand { get; set; }
-
- private void Button_MakeCoffee()
- {
- EventBus.GetInstance.Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee) });
- }
- private void Button_StopMakeCoffe()
- {
- EventBus.GetInstance.Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
- }
- private void Button_CoffeeModeSet()
- {
- 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 BPARelayCommand(() =>
- {
- new MorkTSimOrder() { OrderNum = 1, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SimOrderCoffeeList) }.Publish();
- });
- SimOrderMakeJuice = new BPARelayCommand(() =>
- {
- new MorkTSimOrder() { OrderNum = 2, JuiceList = SimOrder_JuiceList, JuiceMakeID = SimOrder_JuiceMakeID }.Publish();
- });
- SimOrderMakeTea = new BPARelayCommand(() =>
- {
- new MorkTSimOrder() { OrderNum = 3 }.Publish();
- });
- SimOrderMakeWater = new BPARelayCommand(() =>
- {
- new MorkTSimOrder() { OrderNum = 4 }.Publish();
- });
- Button_RobotControlCommand = new BPARelayCommand<object>(Button_RobotControl);
- Robot_DOutput = new BPARelayCommand(Button_RobotDoutput);
-
- Button_MakeCoffeeCommand = new BPARelayCommand(Button_MakeCoffee);
- Button_StopMakeCoffeCommand = new BPARelayCommand(Button_StopMakeCoffe);
- Button_CoffeeModeSetCommand = new BPARelayCommand(Button_CoffeeModeSet);
-
- Button_MCUOuputCommand = new BPARelayCommand(Button_McuPWMOutput);
- Button_MCUDOuputCommand = new BPARelayCommand(Button_McuDOutput);
-
- Button_MakeJuiceCommand = new BPARelayCommand(Button_MakeJuice);
-
- IceMaker_BtnPowerOn = new BPARelayCommand(IceMaker_BtnPowerOnCommand);
- IceMaker_BtnStandby = new BPARelayCommand(IceMaker_BtnStandbyCommand);
- IceMaker_BtnPump = new BPARelayCommand(IceMaker_BtnPumpCommand);
- IceMaker_BtnStart = new BPARelayCommand(IceMaker_BtnStartCommand);
- IceMaker_BtnEnd = new BPARelayCommand(IceMaker_BtnEndCommand);
- IceMaker_BtnSetIceTime = new BPARelayCommand(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
- ;
- });
- TaskManage.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-状态刷新");
- }
- }
|