|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- 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.MorkTHQ.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>
-
- public BPARelayCommand Button_SetValueCommand { get; set; }
-
- private void Button_SetValue()
- {
- EventBus.GetInstance.Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
- }
- private void Button_RobotControl(object o)
- {
- EventBus.GetInstance.Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
- }
-
- #endregion
-
- #region 冰淇淋机器
- /// <summary>
- /// 制作冰淇淋
- /// </summary>
- public BPARelayCommand Button_MakeIceCreamCommand { get; set; }
- /// <summary>
- /// 选择冰淇淋模式
- /// </summary>
- public BPARelayCommand 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.GetInstance.Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId });
- }
- private void Button_SetIceCreamModel()
- {
- MORKI_MODE mORKI_MODE = (MORKI_MODE)Enum.Parse(typeof(MORKI_MODE), SelecteIceCreamdMode);
- new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = mORKI_MODE }.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 CoffeeAppStatus { get { return _coffeAappStatus; } set { _coffeAappStatus = value; OnPropertyChanged(); } }
- private string _coffeAappStatus { get; set; }
- /// <summary>
- /// 告警
- /// </summary>
- public string CoffeeWarning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
- private string _warning { get; set; }
- /// <summary>
- /// 故障信息
- /// </summary>
- public string CoffeeFault { get { return _coffeeFault; } set { _coffeeFault = value; OnPropertyChanged(); } }
- private string _coffeeFault { get; set; }
-
- public string Coffeeprogress { get { return _coffeeprogress; } set { _coffeeprogress = value; OnPropertyChanged(); } }
- private string _coffeeprogress { 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 单片机
- /// <summary>
- /// 单片机连接状态
- /// </summary>
- public string SCChipIsConnect { get { return _sCChipIsConnect; } set { _sCChipIsConnect = value; OnPropertyChanged(); } }
- private string _sCChipIsConnect { get; set; }
- /// <summary>
- /// 咖啡杯或冰淇淋杯落杯
- /// </summary>
- public BPARelayCommand<object> Button_CupControlCommand { get; set; }
- /// <summary>
- /// 单片机冰淇淋机器制冷
- /// </summary>
- public BPARelayCommand Button_SCChipRefrigerationCommand { get; set; }
- /// <summary>
- /// 单片机冰淇淋机器打料
- /// </summary>
- public BPARelayCommand Button_SCChipDischargeCommand { get; set; }
- /// <summary>
- /// 模拟测试
- /// </summary>
- public BPARelayCommand Button_SCChipTestCommand { get; set; }
-
- private void Button_CupControl(object CupType)
- {
- EventBus.GetInstance.Publish(new SCChip_TakeCupEvent() { DeviceId = DeviceId, Cup = (IC_CUP)Enum.Parse(typeof(IC_CUP), CupType.ToString()) });
- }
-
- private void Button_SCChipRefrigeration()
- {
- EventBus.GetInstance.Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
- Thread.Sleep(500);
- EventBus.GetInstance.Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
-
- }
-
- private void Button_SCChipDischarge()
- {
- EventBus.GetInstance.Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });
- }
-
- #endregion
-
- #region 果汁机
- /// <summary>
- /// 果汁机连接状态
- /// </summary>
- public string JuiceIsConnect { get { return _juiceIsConnect; } set { _juiceIsConnect = value; OnPropertyChanged(); } }
- private string _juiceIsConnect { get; set; }
-
- public List<string> Juice { get; set; } = new List<string>() { "果汁1", "果汁2", "果汁3", "果汁4" };
- public string SelectedJuice { get; set; } = "果汁1";
-
- public List<string> Temperature { get; set; } = new List<string>() { "冷", "热" };
-
- public string SelectedTemperature { get; set; } = "冷";
-
- public BPARelayCommand MakeJuiceCommand { get; set; }
-
- private void MakeJuice()
- {
- switch (SelectedJuice)
- {
- case "果汁1":
- if (SelectedTemperature == "冷")
- {
- MakeJuiceEvent(0x01);
- }
- else MakeJuiceEvent(0x00);
- break;
- case "果汁2":
- if (SelectedTemperature == "冷")
- {
- MakeJuiceEvent(0x03);
- }
- else MakeJuiceEvent(0x02);
- break;
- case "果汁3":
- if (SelectedTemperature == "冷")
- {
- MakeJuiceEvent(0x05);
- }
- else MakeJuiceEvent(0x04);
- break;
- case "果汁4":
- if (SelectedTemperature == "冷")
- {
- MakeJuiceEvent(0x07);
- }
- else MakeJuiceEvent(0x06);
- break;
- default:
- MakeJuiceEvent(0x00);
- break;
- }
- }
- private void MakeJuiceEvent(byte b)
- {
- EventBus.GetInstance.Publish(new WriteJuicer { DeviceId = DeviceId, Value = b });
- }
- #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_SetValueCommand = new BPARelayCommand(Button_SetValue);
-
- Button_MakeIceCreamCommand = new BPARelayCommand(Button_MakeIceCream);
- Button_SetIceCreamModelCommand = new BPARelayCommand(Button_SetIceCreamModel);
-
- Button_MakeCoffeeCommand = new BPARelayCommand(Button_MakeCoffee);
- Button_StopMakeCoffeCommand = new BPARelayCommand(Button_StopMakeCoffe);
- Button_CoffeeModeSetCommand = new BPARelayCommand(Button_CoffeeModeSet);
-
- Button_CupControlCommand = new BPARelayCommand<object>(Button_CupControl);
- Button_SCChipRefrigerationCommand = new BPARelayCommand(Button_SCChipRefrigeration);
- Button_SCChipDischargeCommand = new BPARelayCommand(Button_SCChipDischarge);
- Button_SCChipTestCommand = new BPARelayCommand(() =>
- {
- Button_SCChipRefrigeration();
- Thread.Sleep(50);
- Button_SCChipDischarge();
- });
-
- MakeJuiceCommand = new BPARelayCommand(MakeJuice);
-
- foreach (DrinkType code in Enum.GetValues(typeof(DrinkType)))
- {
- 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 == "MorkTHQ") 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" ? "已连接" : "未连接";
- IceCreamConnected = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- SCChipIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
- JuiceIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
-
- RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
-
- CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
- CoffeeAppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
- CoffeeWarning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
- CoffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
- Coffeeprogress = 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-状态刷新");
- }
-
- }
- }
|