|
- using BPASmartClient.Business;
- using BPASmartClient.Device;
- using BPASmartClient.DRCoffee;
-
- using BPASmartClient.GSIceCream;
- 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.MorkTJAKAJC.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; }
- /// <summary>
- /// 机器人控制
- /// </summary>
- /// <param name="o"></param>
- private void Button_RobotControl(object o)
- {
- EventBus.GetInstance.Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
- }
-
- #endregion
-
-
-
- #region 果汁机
- /// <summary>
- /// 果汁机的连接状态
- /// </summary>
- public string JuicerConnected { get { return _JuicerConnected; } set { _JuicerConnected = value; OnPropertyChanged(); } }
- private string _JuicerConnected { get; set; }
-
- /// <summary>
- /// 果汁机的状态
- /// </summary>
- public string JuicerState { get { return _JuicerState; } set { _JuicerState = value; OnPropertyChanged(); } }
- private string _JuicerState { get; set; }
-
- #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; set; }
-
- public List<string> CoffeeCmds { get; set; } = new List<string>();
- public string SelectedCoffeeCmd { 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
-
- #region 单片机
- public string MCUConnected { get { return _mcuConnected; } set { _mcuConnected = value; OnPropertyChanged(); } }
- private string _mcuConnected { get; set; }
-
- public BPARelayCommand Button_MCUOuputCommand { get; set; }
- public BPARelayCommand Button_MCUDOuputCommand { get; set; }
- public int PWMInputNumber { get { return _pwmInputNumber; } set { _pwmInputNumber = value; OnPropertyChanged(); } }
- private int _pwmInputNumber = 1;
-
- public int MCU_PWM_CH { get { return _choosePWM; } set { _choosePWM = value; OnPropertyChanged(); } }
- private int _choosePWM = 1;
-
- public int MCU_DO_CH { get { return _mcuDO_CH; } set { _mcuDO_CH = value; OnPropertyChanged(); } }
- private int _mcuDO_CH = 1;
-
- private int[] DICH { get { return _diCH; } set { _diCH = value; OnPropertyChanged(); } }
- private int[] _diCH = new int[8];
-
- 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_McuOutput()
- {
- 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
-
- /// <summary>
- /// 设备ID
- /// </summary>
- public int DeviceId { get; set; }
- /// <summary>
- /// 设备数据
- /// </summary>
- public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
-
- public DebugViewModel()
- {
- Button_RobotControlCommand = new BPARelayCommand<object>(Button_RobotControl);
- Button_MakeCoffeeCommand = new BPARelayCommand(Button_MakeCoffee);
- Button_StopMakeCoffeCommand = new BPARelayCommand(Button_StopMakeCoffe);
- Button_CoffeeModeSetCommand = new BPARelayCommand(Button_CoffeeModeSet);
-
- Button_MCUOuputCommand = new BPARelayCommand(Button_McuOutput);
- Button_MCUDOuputCommand = new BPARelayCommand(Button_McuDOutput);
-
- foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode)))
- {
- Coffees.Add(code.ToString());
- }
- SelectedCoffee = 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)
- {
- RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- MCUConnected = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
-
- RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
-
- 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;
-
-
- }
- Thread.Sleep(500);
- }), "MorkT-状态刷新");
- }
- }
|