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 BPA.Helper; using BPA.Helper; 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 : NotifyBase { public ManualFlowViewModel() { time = GVL_SmallStation.GetInstance.Time; Test4Command = new BPARelayCommand(() => { 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 BPARelayCommand(() => { App.Current.Dispatcher.Invoke(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【PLC配方清零】操作")) { ActionManage.GetInstance.Send("CLearRecipeInfo"); MessageNotify.GetInstance.ShowUserLog("手动点击按钮,PLC配方清零"); } }); }); SystemReset = new BPARelayCommand(() => { App.Current.Dispatcher.Invoke(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【PLC系统复位】操作")) { ActionManage.GetInstance.Send("ManualSystemReset"); MessageNotify.GetInstance.ShowUserLog("手动点击按钮,PLC系统复位"); } }); }); BPAResetCommand = new BPARelayCommand(() => { App.Current.Dispatcher.Invoke(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【上位机初始化】操作")) { ActionManage.GetInstance.Send("BPASystemReset"); MessageNotify.GetInstance.ShowUserLog("手动点击按钮,上位机初始化"); } }); }); StockbinDosingComple = new BPARelayCommand(() => { 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 BPARelayCommand(() => { }); CancelRecipeCommand = new BPARelayCommand(() => { 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 BPARelayCommand(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否将配方完成数目清零?", DialogType.Warning)) { GVL_SmallStation.GetInstance.RecipeDosingCompleNum = 0; NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", "配方完成数目清零成功!"); MessageNotify.GetInstance.ShowUserLog("手动清零配方完成数目。"); } }); TaskManage.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 BPARelayCommand(() => { GVL_SmallStation.GetInstance.Time = time; MessageNotify.GetInstance.ShowUserLog($"设置柔性味魔方复位时间:{time}s"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{time.ToString()}:设置成功!"); }); HKPlcIsConnect = ProcessControl.GetInstance.HKDevice.IsConnected; } public BPARelayCommand Test4Command { get; set; } public BPARelayCommand TimeSet { get; set; } public BPARelayCommand 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 BPARelayCommand CLearRecipeInfo { get; set; } public BPARelayCommand SystemReset { get; set; } public BPARelayCommand 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 BPARelayCommand StockbinDosingComple { get; set; } public BPARelayCommand StockbinDosingCompleClear { get; set; } public BPARelayCommand 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; } } }