|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- using BPASmartClient.Business;
- using BPASmartClient.Device;
- using BPASmartClient.DRCoffee;
- using BPASmartClient.EventBus;
- using BPASmartClient.GSIceCream;
- using BPASmartClient.Helper;
- using BPASmartClient.LebaiRobot;
- using BPASmartClient.Message;
- using BPASmartClient.Model;
- using BPASmartClient.Model.乐白机器人;
- using BPASmartClient.Model.乐白机器人.Enum;
- using BPASmartClient.Model.冰淇淋.Enum;
- using BPASmartClient.Model.单片机;
- using BPASmartClient.Model.单片机.Enum;
- using BPASmartClient.Model.咖啡机.Enum;
- using BPASmartClient.MorkT.Model;
- 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.ViewModel
- {
- public class DebugViewModel : 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 int TimeInterval { get { return Global.TimeInterval; } set { Global.TimeInterval = value; OnPropertyChanged(); } }
- //private int _timeInterval { get; set; } = Global.TimeInterval;
-
- /// <summary>
- /// 机器人控制指令
- /// </summary>
- public RelayCommand<object> Button_RobotControlCommand { get; set; }
- /// <summary>
- /// 机器人控制
- /// </summary>
- /// <param name="o"></param>
-
-
- public RelayCommand Button_SetValueCommand { get; set; }
-
- public RelayCommand Button_GoToHomeCommand { get; set; }
-
- private void Button_SetValue()
- {
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
- }
- private void Button_RobotControl(object o)
- {
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
- }
-
- private void Button_GoToHome()
- {
- //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
- //MessageLog.GetInstance.Show("开始执行乐白机器人回原点");
- //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_机器人回原点 });
- //MessageLog.GetInstance.Show("开始执行乐白机器人回原点-----");
- }
-
- #endregion
-
- #region 冰淇淋机器
- /// <summary>
- /// 制作冰淇淋
- /// </summary>
- public RelayCommand Button_MakeIceCreamCommand { get; set; }
- /// <summary>
- /// 选择冰淇淋模式
- /// </summary>
- public RelayCommand Button_SetIceCreamModelCommand { get; set; }
-
- /// <summary>
- /// 冰淇淋连接状态
- /// </summary>
- public string IceCreamConnected { get { return _iceCreamConnected; } set { _iceCreamConnected = value; OnPropertyChanged(); } }
- private string _iceCreamConnected { get; set; }
- /// <summary>
- /// 预冷温度
- /// </summary>
- public string YLWD { get { return _yLWD; } set { _yLWD = value; OnPropertyChanged(); } }
- private string _yLWD { get; set; }
- /// <summary>
- /// 回气温度
- /// </summary>
- public string HQWD { get { return _hQWD; } set { _hQWD = value; OnPropertyChanged(); } }
- private string _hQWD { get; set; }
- /// <summary>
- /// 环境温度
- /// </summary>
- public string HJWD { get { return _hJWD; } set { _hJWD = value; OnPropertyChanged(); } }
- private string _hJWD { get; set; }
- /// <summary>
- /// 电流
- /// </summary>
- public string DL { get { return _DL; } set { _DL = value; OnPropertyChanged(); } }
- private string _DL { get; set; }
- /// <summary>
- /// 电压
- /// </summary>
- public string DY { get { return _dy; } set { _dy = value; OnPropertyChanged(); } }
- private string _dy { get; set; }
- /// <summary>
- /// 当前模式
- /// </summary>
- public string CurrentMode { get { return _CurrentMode; } set { _CurrentMode = value; OnPropertyChanged(); } }
- private string _CurrentMode;
- /// <summary>
- /// 故障
- /// </summary>
- public string IceCreamFault { get { return _IceCreamFault; } set { _IceCreamFault = value; OnPropertyChanged(); } }
- private string _IceCreamFault { get; set; }
- /// <summary>
- /// 成型比
- /// </summary>
- public string CXB { get { return _cXB; } set { _cXB = value; OnPropertyChanged(); } }
- private string _cXB { get; set; }
- /// <summary>
- /// 打料完成状态
- /// </summary>
- public string DLCompleted { get { return _dLCompleted; } set { _dLCompleted = value; OnPropertyChanged(); } }
- private string _dLCompleted { get; set; }
-
- public List<string> IceCreamModes { get; set; } = new List<string>();
- public string SelecteIceCreamdMode { get; set; }
-
- private void Button_MakeIceCream()
- {
- EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId });
- }
- private void Button_SetIceCreamModel()
- {
- MORKI_MODE mORKI_MODE = (MORKI_MODE)Enum.Parse(typeof(MORKI_MODE), SelecteIceCreamdMode);
- EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = mORKI_MODE });
- }
- #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 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
-
- #region 单片机
- /// <summary>
- /// 单片机连接状态
- /// </summary>
- public string SCChipIsConnect { get { return _sCChipIsConnect; } set { _sCChipIsConnect = value; OnPropertyChanged(); } }
- private string _sCChipIsConnect { get; set; }
- /// <summary>
- /// 咖啡杯或冰淇淋杯落杯
- /// </summary>
- public RelayCommand<object> Button_CupControlCommand { get; set; }
- /// <summary>
- /// 单片机冰淇淋机器制冷
- /// </summary>
- public RelayCommand Button_SCChipRefrigerationCommand { get; set; }
- /// <summary>
- /// 单片机冰淇淋机器打料
- /// </summary>
- public RelayCommand Button_SCChipDischargeCommand { get; set; }
- /// <summary>
- /// 模拟测试
- /// </summary>
- public RelayCommand Button_SCChipTestCommand { get; set; }
-
- private void Button_CupControl(object CupType)
- {
- EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent() { DeviceId = DeviceId, Cup = (IC_CUP)Enum.Parse(typeof(IC_CUP), CupType.ToString()) });
- }
-
- private void Button_SCChipRefrigeration()
- {
- //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
- //Thread.Sleep(500);
- //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Value = true, Pin = 1 });
- Thread.Sleep(500);
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Value = false, Pin = 1 });
-
- }
-
- private void Button_SCChipDischarge()
- {
- EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });
- }
-
- #endregion
-
- /// <summary>
- /// 设备ID
- /// </summary>
- public int DeviceId { get; set; }
- /// <summary>
- /// 设备数据
- /// </summary>
- public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
-
- public DebugViewModel()
- {
- Button_RobotControlCommand = new RelayCommand<object>(Button_RobotControl);
- Button_SetValueCommand = new RelayCommand(Button_SetValue);
- Button_GoToHomeCommand = new RelayCommand(Button_GoToHome);
-
- Button_MakeIceCreamCommand = new RelayCommand(Button_MakeIceCream);
- Button_SetIceCreamModelCommand = new RelayCommand(Button_SetIceCreamModel);
-
- Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee);
- Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe);
- Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet);
-
- Button_CupControlCommand = new RelayCommand<object>(Button_CupControl);
- Button_SCChipRefrigerationCommand = new RelayCommand(Button_SCChipRefrigeration);
- Button_SCChipDischargeCommand = new RelayCommand(Button_SCChipDischarge);
- Button_SCChipTestCommand = new RelayCommand(() =>
- {
- Button_SCChipRefrigeration();
- Thread.Sleep(50);
- Button_SCChipDischarge();
- });
-
- 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];
-
- foreach (MORKI_MODE code in Enum.GetValues(typeof(MORKI_MODE)))
- {
- IceCreamModes.Add(code.ToString());
- }
- SelecteIceCreamdMode = IceCreamModes[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)
- {
- RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- IceCreamConnected = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- SCChipIsConnect = 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;
-
- YLWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器预冷温度").CurrentValue;
- HQWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器回气温度").CurrentValue;
- HJWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器环境温度").CurrentValue;
- DL = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电流").CurrentValue;
- DY = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电压").CurrentValue;
- CurrentMode = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器模式").CurrentValue;
- IceCreamFault = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器异常").CurrentValue;
- CXB = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器成型比").CurrentValue;
- DLCompleted = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器打料完成")?.CurrentValue == "True" ? "打料完成" : "打料中";
- }
- Thread.Sleep(500);
- }), "MorkT-状态刷新");
- }
-
- }
- }
|