|
- 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_Container.ViewModel;
- public class DebugViewModel : 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<object> IceMaker_State { 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 bool Robot_TCPDI0 { get { return _robot_TCPDI0; } set { _robot_TCPDI0 = value;OnPropertyChanged(); } }
- private bool _robot_TCPDI0;
-
- public bool Robot_DI0 { get { return _robot_DI0; } set { _robot_DI0 = value; OnPropertyChanged(); } }
- private bool _robot_DI0;
- public bool Robot_DI1 { get { return _robot_DI1; } set { _robot_DI1 = value; OnPropertyChanged(); } }
- private bool _robot_DI1;
- public bool Robot_DI2 { get { return _robot_DI2; } set { _robot_DI2 = value; OnPropertyChanged(); } }
- private bool _robot_DI2;
- public bool Robot_DI3 { get { return _robot_DI3; } set { _robot_DI3 = value; OnPropertyChanged(); } }
- private bool _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 bool MCUDI0 { get { return _mCUDI0; } set { _mCUDI0 = value; OnPropertyChanged(); } }
- private bool _mCUDI0 { get; set; }
- public bool MCUDI1 { get { return _mCUDI1; } set { _mCUDI1 = value; OnPropertyChanged(); } }
- private bool _mCUDI1 { get; set; }
- public bool MCUDI2 { get { return _mCUDI2; } set { _mCUDI2 = value; OnPropertyChanged(); } }
- private bool _mCUDI2 { get; set; }
- public bool MCUDI3 { get { return _mCUDI3; } set { _mCUDI3 = value; OnPropertyChanged(); } }
- private bool _mCUDI3 { get; set; }
- public bool MCUDI4 { get { return _mCUDI4; } set { _mCUDI4 = value; OnPropertyChanged(); } }
- private bool _mCUDI4 { get; set; }
- public bool MCUDI5 { get { return _mCUDI5; } set { _mCUDI5 = value; OnPropertyChanged(); } }
- private bool _mCUDI5 { get; set; }
- public bool MCUDI6 { get { return _mCUDI6; } set { _mCUDI6 = value; OnPropertyChanged(); } }
- private bool _mCUDI6 { get; set; }
- public bool MCUDI7 { get { return _mCUDI7; } set { _mCUDI7 = value; OnPropertyChanged(); } }
- private bool _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 System.Windows.Visibility JuiceState_Heating { get { return _juiceState_Heating; } set { _juiceState_Heating = value;OnPropertyChanged(); } }
- public System.Windows.Visibility _juiceState_Heating { get; set; }
- public System.Windows.Visibility JuiceState_Cooling { get { return _juiceState_Cooling; } set { _juiceState_Cooling = value; OnPropertyChanged(); } }
- public System.Windows.Visibility _juiceState_Cooling { get; set; }
- public System.Windows.Visibility JuiceState_LackOfWater { get { return _juiceState_LackOfWater; } set { _juiceState_LackOfWater = value; OnPropertyChanged(); } }
- public System.Windows.Visibility _juiceState_LackOfWater { get; set; }
- public System.Windows.Visibility JuiceState_ChildLocks { get { return _juiceState_ChildLocks; } set { _juiceState_ChildLocks = value; OnPropertyChanged(); } }
- public System.Windows.Visibility _juiceState_ChildLocks { get; set; }
- public System.Windows.Visibility JuiceState_Using { get { return _juiceState_Using; } set { _juiceState_Using = value; OnPropertyChanged(); } }
- public System.Windows.Visibility _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 int IceMakerState { get { return _iceMakerState; } set { _iceMakerState = value; OnPropertyChanged(); } }
- private int _iceMakerState { get; set; }
- public string IceMakerState1 { get { return _iceMakerState1; } set { _iceMakerState1 = value; OnPropertyChanged(); } }
- private string _iceMakerState1 { get; set; }
- public string IceMakerState2 { get { return _iceMakerState2; } set { _iceMakerState2 = value; OnPropertyChanged(); } }
- private string _iceMakerState2 { get; set; }
- public string IceMakerState3 { get { return _iceMakerState3; } set { _iceMakerState3 = value; OnPropertyChanged(); } }
- private string _iceMakerState3 { get; set; }
- public string IceMakerState4 { get { return _iceMakerState4; } set { _iceMakerState4 = value; OnPropertyChanged(); } }
- private string _iceMakerState4 { get; set; }
- public string IceMakerState5 { get { return _iceMakerState5; } set { _iceMakerState5 = value; OnPropertyChanged(); } }
- private string _iceMakerState5 { 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 * 0.1 }.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 DebugViewModel()
- {
- 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 == "Container") DeviceId = device.DeviceId
- ;
- });
- TaskManage.GetInstance.StartLong(new Action(async () =>
- {
- 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输入状态").SwitchValue;
- Robot_DI0 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入0状态").SwitchValue;
- Robot_DI1 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入1状态").SwitchValue;
- Robot_DI2 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入2状态").SwitchValue;
- Robot_DI3 = variableMonitors.FirstOrDefault(p => p.Notes == "机器人输入3状态").SwitchValue;
-
- #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状态").SwitchValue;
- MCUDI1 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入1状态").SwitchValue;
- MCUDI2 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入2状态").SwitchValue;
- MCUDI3 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入3状态").SwitchValue;
- MCUDI4 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入4状态").SwitchValue;
- MCUDI5 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入5状态").SwitchValue;
- MCUDI6 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入6状态").SwitchValue;
- MCUDI7 = variableMonitors.FirstOrDefault(p => p.Notes == "单片机输入7状态").SwitchValue;
- #endregion
-
- #region 制冰机
- IceMakerConnect = variableMonitors.FirstOrDefault(p => p.Notes == "制冰机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- IceMakerState = variableMonitors.FirstOrDefault(p => p.Notes == "制冰机设备状态").IntValue;
- if (IceMakerState>=0 && IceMakerState<=255)
- {
- byte a = (byte)IceMakerState;
- if ((a >> 0 & 1) == 1)
- {
- IceMakerState1 = "关机状态";
- }
- else
- {
- IceMakerState1 = "开机状态";
- }
- if ((a >> 1 & 1) == 1)
- {
- IceMakerState2 = "制冰状态";
- }
- else
- {
- IceMakerState2 = "待机状态";
- }
- if ((a >> 2 & 1) == 1)
- {
- IceMakerState3 = "电机故障";
- }
- else
- {
- IceMakerState3 = "正常";
- }
- if ((a >> 3 & 1) == 1)
- {
- IceMakerState4 = "缺水";
- }
- else
- {
- IceMakerState4 = "正常";
- }
- if ((a >> 4 & 1) == 1)
- {
- IceMakerState5 = "冰满";
- }
- else
- {
- IceMakerState5 = "未定义";
- }
-
- }
- #endregion
- /*
- List<int> res = new List<int>();
- byte[] receive = new byte[32] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32 };
- res.Add(receive.Skip(24).Take(4).ToArray().BytesToInt());
- res.Add(receive.Skip(28).Take(4).ToArray().BytesToInt());
- int[] am = res.ToArray();
- var Juicestate1 = Convert.ToString(am[0], 2);
- var Juicestate2 = am[1];
- int cd = Juicestate1.IndexOf("0");*/
- #region 果汁机
- JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- JuiceState_Heating = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机制热").CurrentValue == "True" ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
- JuiceState_Cooling = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机制冷").CurrentValue == "True" ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
- JuiceState_LackOfWater = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机缺水").CurrentValue == "True" ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
- JuiceState_ChildLocks = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机童锁").CurrentValue == "True" ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
- JuiceState_Using = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机使用").CurrentValue == "True" ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
- #endregion
- Thread.Sleep(200);
-
- }
- }), "MorkT-状态刷新");
- }
- }
|