using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.FoodStationTest.Model; using BPASmartClient.FoodStationTest.Model.HK_PLC; using BPASmartClient.Helper; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using System.Windows; namespace BPASmartClient.FoodStationTest.ViewModel { public class ManualFlowViewModel : ObservableObject { public ManualFlowViewModel() { time = GVL_SmallStation.GetInstance.Time; Test4Command = new RelayCommand(() => { ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX1.5", PlcVarType = PlcVarType.Bool, Value = true }); //GVL_SmallStation.GetInstance.CylinderReset = true; MessageNotify.GetInstance.ShowUserLog("手动点击按钮,气缸收紧错位复位"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,气缸收紧错位复位"); }); CLearRecipeInfo = new RelayCommand(() => { App.Current.Dispatcher.Invoke(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【PLC配方清零】操作")) { ActionManage.GetInstance.Send("CLearRecipeInfo"); MessageNotify.GetInstance.ShowUserLog("手动点击按钮,PLC配方清零"); } }); }); SystemReset = new RelayCommand(() => { App.Current.Dispatcher.Invoke(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【PLC系统复位】操作")) { ActionManage.GetInstance.Send("ManualSystemReset"); MessageNotify.GetInstance.ShowUserLog("手动点击按钮,PLC系统复位"); } }); }); BPAResetCommand = new RelayCommand(() => { App.Current.Dispatcher.Invoke(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【上位机初始化】操作")) { ActionManage.GetInstance.Send("BPASystemReset"); MessageNotify.GetInstance.ShowUserLog("手动点击按钮,上位机初始化"); } }); }); StockbinDosingComple = new RelayCommand(() => { int loc = StockbinDosingCompleNum; if (loc >= 1 && loc <= 8) { ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX12." + (loc - 1), PlcVarType = PlcVarType.Bool, Value = true }); MessageNotify.GetInstance.ShowUserLog($"手动点击按钮,给plc料仓{loc}配料完成信号"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,手动设置料仓{loc}配料完成"); } else if (loc >= 9 && loc <= 15) { ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX13." + (loc - 9), PlcVarType = PlcVarType.Bool, Value = true }); MessageNotify.GetInstance.ShowUserLog($"手动点击按钮,给plc料仓{loc}配料完成信号"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,手动设置料仓{loc}配料完成"); } else { MessageNotify.GetInstance.ShowUserLog("料仓编号不正确"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,手动设置料仓{loc}配料,料仓编号不正确"); } }); StockbinDosingCompleClear = new RelayCommand(() => { }); CancelRecipeCommand = new RelayCommand(() => { string cancelRecipeCode = CancelRecipeCode.Trim(); if (!String.IsNullOrEmpty(cancelRecipeCode) && MessageNotify.GetInstance.ShowDialog($"请确认,是否进行删除订单【{cancelRecipeCode}】操作?")) { if (Json.Data.Recipes != null) { int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeCode == cancelRecipeCode); if (index >= 0) { GVL_SmallStation.GetInstance.Order_Cancel = true; GVL_SmallStation.GetInstance.Order_CancelRecipeCode = cancelRecipeCode; MessageNotify.GetInstance.ShowUserLog($"手动删除订单【{cancelRecipeCode}】。"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"删除订单【{cancelRecipeCode}】成功!"); return; } NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"删除订单【{cancelRecipeCode}】失败,未找到该订单。"); } } }); CompletedNumResetCommand = new RelayCommand(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否将配方完成数目清零?", DialogType.Warning)) { GVL_SmallStation.GetInstance.RecipeDosingCompleNum = 0; NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", "配方完成数目清零成功!"); MessageNotify.GetInstance.ShowUserLog("手动清零配方完成数目。"); } }); ThreadManage.GetInstance().StartLong(new Action(() => { RecipeDosingCompleNum = GVL_SmallStation.GetInstance.RecipeDosingCompleNum; Recipe1DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[0].ToBinString(); Recipe2DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[1].ToBinString(); Recipe3DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[2].ToBinString(); Recipe4DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[3].ToBinString(); Recipe5DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[4].ToBinString(); Heartbeat = GVL_SmallStation.GetInstance.HeartBeatFromPlc; switch (GVL_SmallStation.GetInstance.SiemensSendRecipeStatus) { case 0: OrderStatus = IssueRecipeCondition.等待小料站PLC允许下配方.ToString(); break; case 1: OrderStatus = IssueRecipeCondition.等待西门子下发配方.ToString(); break; case 2: OrderStatus = IssueRecipeCondition.等待西门子下发配方信号复位.ToString(); break; case 3: OrderStatus = IssueRecipeCondition.等待上位机请求配料.ToString(); break; case 4: OrderStatus = IssueRecipeCondition.等待西门子确认配料.ToString(); break; case 5: OrderStatus = IssueRecipeCondition.等待西门子确认配料信号复位.ToString(); break; case 6: OrderStatus = "上位机将配方添加到队列中"; break; default: OrderStatus = "无意义"; break; } switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[0]) { case 0: Recipe1DosingStatus = ProcessCondition.等待AGV到位.ToString(); break; case 1: Recipe1DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString(); break; case 2: Recipe1DosingStatus = ProcessCondition.等待配方配料完成.ToString(); break; default: break; } switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[1]) { case 0: Recipe2DosingStatus = ProcessCondition.等待AGV到位.ToString(); break; case 1: Recipe2DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString(); break; case 2: Recipe2DosingStatus = ProcessCondition.等待配方配料完成.ToString(); break; default: break; } switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[2]) { case 0: Recipe3DosingStatus = ProcessCondition.等待AGV到位.ToString(); break; case 1: Recipe3DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString(); break; case 2: Recipe3DosingStatus = ProcessCondition.等待配方配料完成.ToString(); break; default: break; } switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[3]) { case 0: Recipe4DosingStatus = ProcessCondition.等待AGV到位.ToString(); break; case 1: Recipe4DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString(); break; case 2: Recipe4DosingStatus = ProcessCondition.等待配方配料完成.ToString(); break; default: break; } switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[4]) { case 0: Recipe5DosingStatus = ProcessCondition.等待AGV到位.ToString(); break; case 1: Recipe5DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString(); break; case 2: Recipe5DosingStatus = ProcessCondition.等待配方配料完成.ToString(); break; default: break; } Thread.Sleep(100); }), "流程手动设备状态读取", true); TimeSet = new RelayCommand(() => { GVL_SmallStation.GetInstance.Time = time; MessageNotify.GetInstance.ShowUserLog($"设置柔性味魔方复位时间:{time}s"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{time.ToString()}:设置成功!"); }); HKPlcIsConnect = ProcessControl.GetInstance.HKDevice.IsConnected; } public RelayCommand Test4Command { get; set; } public RelayCommand TimeSet { get; set; } public RelayCommand CompletedNumResetCommand { get; set; } public static bool Heartbeat { get { return _mHeartbeat; } set { _mHeartbeat = value; OnStaticPropertyChanged(); } } private static bool _mHeartbeat; public int time { get { return _mtime; } set { _mtime = value; OnStaticPropertyChanged(); } } private int _mtime; public static string OrderStatus { get { return _mOrderStatus; } set { _mOrderStatus = value; OnStaticPropertyChanged(); } } private static string _mOrderStatus = "无意义"; public static string Recipe1DosingStatus { get { return _mRecipe1DosingStatus; } set { _mRecipe1DosingStatus = value; OnStaticPropertyChanged(); } } private static string _mRecipe1DosingStatus = "无意义"; public static string Recipe2DosingStatus { get { return _mRecipe2DosingStatus; } set { _mRecipe2DosingStatus = value; OnStaticPropertyChanged(); } } private static string _mRecipe2DosingStatus = "无意义"; public static string Recipe3DosingStatus { get { return _mRecipe3DosingStatus; } set { _mRecipe3DosingStatus = value; OnStaticPropertyChanged(); } } private static string _mRecipe3DosingStatus = "无意义"; public static string Recipe4DosingStatus { get { return _mRecipe4DosingStatus; } set { _mRecipe4DosingStatus = value; OnStaticPropertyChanged(); } } private static string _mRecipe4DosingStatus = "无意义"; public static string Recipe5DosingStatus { get { return _mRecipe5DosingStatus; } set { _mRecipe5DosingStatus = value; OnStaticPropertyChanged(); } } private static string _mRecipe5DosingStatus = "无意义"; public static event EventHandler StaticPropertyChanged; public static void OnStaticPropertyChanged([CallerMemberName] string PropName = "") { StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName)); } public RelayCommand CLearRecipeInfo { get; set; } public RelayCommand SystemReset { get; set; } public RelayCommand BPAResetCommand { get; set; } private bool _SiemensIsConnect { get; set; } public bool SiemensIsConnect { get { return _SiemensIsConnect; } set { _SiemensIsConnect = value; OnPropertyChanged(); } } private bool _HKPlcIsConnect { get; set; } public bool HKPlcIsConnect { get { return _HKPlcIsConnect; } set { _HKPlcIsConnect = value; OnPropertyChanged(); } } private bool _WindSendIsConnect { get; set; } public bool WindSendIsConnect { get { return _WindSendIsConnect; } set { _WindSendIsConnect = value; OnPropertyChanged(); } } private static string _Recipe1DosingComplete { get; set; } public static string Recipe1DosingComplete { get { return _Recipe1DosingComplete; } set { _Recipe1DosingComplete = value; OnStaticPropertyChanged(); } } private static string _Recipe2DosingComplete { get; set; } public static string Recipe2DosingComplete { get { return _Recipe2DosingComplete; } set { _Recipe2DosingComplete = value; OnStaticPropertyChanged(); } } private static string _Recipe3DosingComplete { get; set; } public static string Recipe3DosingComplete { get { return _Recipe3DosingComplete; } set { _Recipe3DosingComplete = value; OnStaticPropertyChanged(); } } private static string _Recipe4DosingComplete { get; set; } public static string Recipe4DosingComplete { get { return _Recipe4DosingComplete; } set { _Recipe4DosingComplete = value; OnStaticPropertyChanged(); } } private static string _Recipe5DosingComplete { get; set; } public static string Recipe5DosingComplete { get { return _Recipe5DosingComplete; } set { _Recipe5DosingComplete = value; OnStaticPropertyChanged(); } } public RelayCommand StockbinDosingComple { get; set; } public RelayCommand StockbinDosingCompleClear { get; set; } public RelayCommand CancelRecipeCommand { get; set; } private static int _StockbinDosingCompleNum { get; set; } public static int StockbinDosingCompleNum { get { return _StockbinDosingCompleNum; } set { _StockbinDosingCompleNum = value; OnStaticPropertyChanged(); } } private static int _RecipeDosingCompleNum { get; set; } public static int RecipeDosingCompleNum { get { return _RecipeDosingCompleNum; } set { _RecipeDosingCompleNum = value; OnStaticPropertyChanged(); } } public string CancelRecipeCode { get { return _CancelRecipeCode; } set { _CancelRecipeCode = value; OnPropertyChanged(); } } public string _CancelRecipeCode { get; set; } } }