|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.MorkCL.HelpClass;
- using System.Reflection.Metadata;
- using System.Windows.Markup;
-
- namespace BPASmartClient.MorkCL.ViewModel
- {
- public class DebugViewModel : NotifyBase
- {
- private ushort heatGear;
- private ushort agitaFrequency;
-
- public DebugViewModel()
- {
- WriteAgitaParamCommand = new(async () =>
- {
- //if (!GetDeviceIsIdle(FryingPanSelect))
- //{
- // return;
- //}
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(FryingPanSelect, "LW1", (ushort)(AgitaFrequency*100)));
-
- await SendWriteRequest("LB10");
-
- ShowNotify($"写入搅拌参数成功。");
- });
-
- StartAgitateCommand = new(() =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB0", true));
- ShowNotify($"写入搅拌启动成功。");
- });
- StopAgitateCommand = new(() =>
- {
- //if (!GetDeviceIsIdle(FryingPanSelect))
- //{
- // return;
- //}
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB0", false));
- ShowNotify($"写入搅拌停止成功。");
- });
-
- WriteHeatParamCommand = new(async () =>
- {
- //if (!GetDeviceIsIdle(FryingPanSelect))
- //{
- // return;
- //}
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(FryingPanSelect, "LW0", HeatGear));
-
- await SendWriteRequest("LB9");
- ShowNotify($"写入加热参数成功。");
- });
-
- StartHeatCommand = new(() =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB3", true));
- ShowNotify($"写入加热启动成功。");
- });
-
- StopHeatCommand = new(() =>
- {
- //if (!GetDeviceIsIdle(FryingPanSelect))
- //{
- // return;
- //}
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB3", false));
- ShowNotify($"写入加热停止成功。");
- });
-
- ChannelCuttingCommand = new(async () =>
- {
- //var channelIndex = ChannelSelect;
- //var weight = Convert.ToUInt16(Weight);
- //byte[] LWOffset = new byte[3] { 3, 4, 5 };
- //byte[] LBOffset = new byte[3] { 6, 7, 8 };
-
- //ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(FryingPanSelect, $"LW{LWOffset[channelIndex]}", weight));
- //await SendWriteRequest($"LB{LBOffset[channelIndex]}");
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- object[] para = new object[3];
- para[0]= FryingPanSelect;
- para[1] = ChannelSelect+1;
- para[2] = Convert.ToUInt16(Weight);
-
- await Task.Run(() => ActionManage.GetInstance.Send("DeviceCuttingControl", para));
- ShowNotify($"写入通道下料控制成功。");
- });
-
- GoFryLocCommand = new(async () =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- var loc = StirFryLocSelect + 17;
-
- await SendWriteRequest($"LB{loc}");
- ShowNotify($"写入去炒制位成功。");
- });
- GoHomeCommand = new(async () =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- await SendWriteRequest("LB12");
- ShowNotify($"写入回原点成功。");
- });
- GoSeasoningFeddLocCommand = new(async () =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- await SendWriteRequest("LB16");
- ShowNotify($"写入去调料投料位成功。");
- });
-
- OutDiningStartCommand = new(async () =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- await SendWriteRequest("LB13");
- ShowNotify($"写入出餐启动成功。");
- });
-
- FryPanCleanCommand = new(async () =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- await SendWriteRequest("LB14");
- ShowNotify($"写入炒锅清洗成功。");
- });
-
- SetAutoModeCommand = new(() =>
- {
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB20", true));
- ShowNotify($"设置设备自动模式成功。");
- });
-
- SetManualModeCommand = new(() =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, "LB20", false));
- ShowNotify($"设置设备手动模式成功。");
- });
- InitalDeviceCommand = new(async () =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- //复位所有变量。
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- ResetFryPanVariable(FryingPanSelect);
- await SendWriteRequest("LB21");
- ShowNotify($"设置设备初始化成功。");
- });
-
- StopDeviceCommand = new(async () =>
- {
- //if (!GetDeviceIsIdle(FryingPanSelect))
- //{
- // return;
- //}
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- await SendWriteRequest("LB22");
- ShowNotify($"设置设备停止成功。");
- });
-
- //炒锅那边复位变量没有使用。
- GoCleanLocCommand = new(async () =>
- {
- if (!GetDeviceIsIdle(FryingPanSelect))
- {
- return;
- }
- if (!MessageNotify.GetInstance.ShowDialog("确认是否进行手动操作?"))
- {
- return;
- }
- await SendWriteRequest("LB23");
- ShowNotify($"设置设备去洗锅位成功。");
- });
-
- CancelFryPanTaskCommand = new((string device) =>
- {
- ActionManage.GetInstance.Send("CancelFryPanTask", device);
- ShowNotify($"[{device}#]取消当前任务成功");
- });
-
-
- ClearFryPanTaskCommand_1 = new(() =>
- {
-
- });
- ClearFryPanTaskCommand_2 = new(() =>
- {
- });
-
- InitRobotVarCommand = new(() =>
- {
- Task.Run(() =>
- {
- ActionManage.GetInstance.Send("InitRobotAllVar");
- });
- });
-
- RobotGoCleanLocCommand = new(() =>
- {
- if (!MessageNotify.GetInstance.ShowDialog("确认是否将机械手移动到清洗位?"))
- {
- return;
- }
- ActionManage.GetInstance.Send("RobotGoCleanLoc");
- });
- }
-
- #region 私有方法
-
- private async Task SendWriteRequest(string address)
- {
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, address, false));
- await Task.Delay(400);
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, address, true));
- await Task.Delay(400);
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(FryingPanSelect, address, false));
- }
-
- private void ShowNotify(string info)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", info);
- }
-
- private bool GetDeviceIsIdle(EDeviceType device)
- {
- if (ActionManage.GetInstance.SendResult("GetDeviceIsIdle", FryingPanSelect) is bool frypanisIdle)
- {
- if (frypanisIdle)
- {
- return true;
- }
- else
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", "当前炒锅正在炒菜,稍后再试。");
- }
- }
- return false;
- }
- /// <summary>
- /// 复位指定炒锅的所有变量。
- /// </summary>
- /// <param name="deviceType"></param>
- private void ResetFryPanVariable(EDeviceType deviceType)
- {
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB0", false));
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB3", false));
- for (int i = 6; i <= 19; i++)
- {
- ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB" + i, false));
- }
- for (int i = 0; i <= 5; i++)
- {
- ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(deviceType, "LW" + i, 0));
- }
- }
- #endregion 私有方法
-
- #region 属性
-
- private EDeviceType fryingPanSelect = EDeviceType.炒锅1;
-
- /// <summary>炒锅选择。</summary>
- public EDeviceType FryingPanSelect
- {
- get { return fryingPanSelect; }
- set { fryingPanSelect = value; OnPropertyChanged(); }
- }
-
- /// <summary>搅拌频率</summary>
- public ushort AgitaFrequency
- {
- get => agitaFrequency; set
- {
- if (value >= 50)
- agitaFrequency = 50;
- else if (value <= 1)
- agitaFrequency = 1;
- else
- agitaFrequency = value;
- OnPropertyChanged();
- }
- }
-
- /// <summary>加热档位</summary>
- public ushort HeatGear
- {
- get => heatGear; set
- {
- if (value >= 8)
- heatGear = 8;
- else if (value <= 1)
- heatGear = 1;
- else
- heatGear = value;
- OnPropertyChanged();
- }
- }
-
- private float weight;
-
- /// <summary>下料重量</summary>
- public float Weight
- {
- get { return weight; }
- set { weight = value; }
- }
-
- private int channelSelect;
-
- /// <summary>下料通道选择。</summary>
- public int ChannelSelect
- {
- get { return channelSelect; }
- set { channelSelect = value; OnPropertyChanged(); }
- }
-
- private int stirFryLocSelect;
-
- /// <summary>炒制位选择。</summary>
- public int StirFryLocSelect
- {
- get { return stirFryLocSelect; }
- set { stirFryLocSelect = value; OnPropertyChanged(); }
- }
-
- public ObservableCollection<EDeviceType> DeviceTypes { get; set; } = new ObservableCollection<EDeviceType>() { EDeviceType.炒锅1, EDeviceType.炒锅2 };
-
- #endregion 属性
-
- #region 命令
-
- /// <summary>写入搅拌参数。</summary>
- public BPARelayCommand WriteAgitaParamCommand { get; set; }
-
- /// <summary>开始搅拌。</summary>
- public BPARelayCommand StartAgitateCommand { get; set; }
-
- /// <summary>停止搅拌。</summary>
- public BPARelayCommand StopAgitateCommand { get; set; }
-
- /// <summary>写入加热参数。</summary>
- public BPARelayCommand WriteHeatParamCommand { get; set; }
-
- /// <summary>开始加热。</summary>
- public BPARelayCommand StartHeatCommand { get; set; }
-
- /// <summary>停止加热。</summary>
- public BPARelayCommand StopHeatCommand { get; set; }
-
- /// <summary>通道下料启动。</summary>
- public BPARelayCommand ChannelCuttingCommand { get; set; }
-
- /// <summary>去炒制位。</summary>
- public BPARelayCommand GoFryLocCommand { get; set; }
-
- /// <summary>回原点/投料位置。</summary>
- public BPARelayCommand GoHomeCommand { get; set; }
-
- /// <summary>去调料投料位。</summary>
- public BPARelayCommand GoSeasoningFeddLocCommand { get; set; }
-
- /// <summary>出餐启动。</summary>
- public BPARelayCommand OutDiningStartCommand { get; set; }
-
- /// <summary>炒锅清洗。</summary>
- public BPARelayCommand FryPanCleanCommand { get; set; }
- /// <summary>
- /// 设为自动模式。
- /// </summary>
- public BPARelayCommand SetAutoModeCommand { get; set; }
- /// <summary>
- /// 设为手动模式。
- /// </summary>
- public BPARelayCommand SetManualModeCommand { get; set; }
- /// <summary>
- /// 初始化设备。
- /// </summary>
- public BPARelayCommand InitalDeviceCommand { get; set; }
- /// <summary>
- /// 设备停止。
- /// </summary>
- public BPARelayCommand StopDeviceCommand { get; set; }
- /// <summary>
- /// 设备去洗锅位置。
- /// </summary>
- public BPARelayCommand GoCleanLocCommand { get; set; }
- /// <summary>
- /// 取消指定炒锅当前任务。
- /// </summary>
- public BPARelayCommand<string> CancelFryPanTaskCommand { get; set; }
- /// <summary>
- /// 清空1#炒锅所有任务。
- /// </summary>
- public BPARelayCommand ClearFryPanTaskCommand_1 { get; set; }
- /// <summary>
- /// 清空2#炒锅所有任务。
- /// </summary>
- public BPARelayCommand ClearFryPanTaskCommand_2 { get; set; }
- /// <summary>
- /// 复位机器人所有由上位机下发的变量。
- /// </summary>
- public BPARelayCommand InitRobotVarCommand { get; set; }
-
- public BPARelayCommand RobotGoCleanLocCommand { get; set; }
-
- #endregion 命令
- }
- }
|