|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using System.Collections.ObjectModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using BPASmartClient.Helper;
- using BPASmartClient.JXJFoodSmallStation.Model;
- using System.Threading;
- using System.ComponentModel;
- using System.Runtime.CompilerServices;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.CustomResource.UserControls;
-
- namespace BPASmartClient.JXJFoodSmallStation.ViewModel
- {
- public class ManualControlViewModel : ObservableObject
- {
- public ManualControlViewModel()
- {
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- PlcSystemMode = GVL_SmallStation.GetInstance.PlcSystemMode;
- //SystemMode = GVL_SmallStation.GetInstance.PlcSystemMode ? "手动" : "自动";
- //if (GVL_SmallStation.GetInstance.PlcSystemMode) ManualMode = true;
- //else AutoModeStatus = true;
- if (GVL_SmallStation.GetInstance.PlcSystemIsAutoRun)
- {
- SystemStatus = GVL_SmallStation.GetInstance.PlcSystemIsPause ? "暂停" : "运行";
- //if (GVL_SmallStation.GetInstance.PlcSystemIsPause)
- //{
- // SystemStatus = "暂停";
- //}
- //else
- //{
- // SystemStatus = "运行";
- //}
- }
- else
- {
- SystemStatus = "停止";
- }
- for (int i = 0; i < 15; i++)
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[i])
- {
- cylinderModels.ElementAt(i).LeftTog = true;
- cylinderModels.ElementAt(i).RightTog = false;
- }
- else
- {
- cylinderModels.ElementAt(i).LeftTog = false;
- cylinderModels.ElementAt(i).RightTog = true;
- }
- }
- foreach (var item in PalletCylinders)
- {
- if (item.Name == "进料桶顶升气缸")
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[20])
- {
- item.LeftTog = true;
- item.RightTog = false;
- }
- else
- {
- item.LeftTog = false;
- item.RightTog = true;
- }
- }
- if (item.Name == "出料桶顶升气缸1")
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[21])
- {
- item.LeftTog = true;
- item.RightTog = false;
- }
- else
- {
- item.LeftTog = false;
- item.RightTog = true;
- }
- }
- if (item.Name == "出料桶顶升气缸2")
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[22])
- {
- item.LeftTog = true;
- item.RightTog = false;
- }
- else
- {
- item.LeftTog = false;
- item.RightTog = true;
- }
- }
- if (item.Name == "出料桶顶升气缸3")
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[23])
- {
- item.LeftTog = true;
- item.RightTog = false;
- }
- else
- {
- item.LeftTog = false;
- item.RightTog = true;
- }
- }
- if (item.Name == "托盘气缸1_1")
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[24])
- {
- item.LeftTog = false;
- item.RightTog = true;
- }
- else
- {
- item.LeftTog = true;
- item.RightTog = false;
- }
- }
- if (item.Name == "托盘气缸1_2")
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[25])
- {
- item.LeftTog = false;
- item.RightTog = true;
- }
- else
- {
- item.LeftTog = true;
- item.RightTog = false;
- }
- }
- if (item.Name == "托盘气缸2_1")
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[26])
- {
- item.LeftTog = false;
- item.RightTog = true;
- }
- else
- {
- item.LeftTog = true;
- item.RightTog = false;
- }
- }
- if (item.Name == "托盘气缸2_2")
- {
- if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[27])
- {
- item.LeftTog = false;
- item.RightTog = true;
- }
- else
- {
- item.LeftTog = true;
- item.RightTog = false;
- }
- }
- }
- Thread.Sleep(200);
- }), "获取系统状态", true);
- if (cylinderModels.Count < 15)
- {
- for (int i = 0; i < 15; i++)
- {
- cylinderModels.Add(new CylinderModel()
- {
- Name = $"升降气缸 {i + 1}",
- LeftTog = false,
- RightTog = false,
- });
-
- BlockCylinders.Add(new CylinderModel()
- {
- Name = $"阻挡气缸 {i + 1}",
- LeftTog = false,
- RightTog = false,
- });
- }
- }
- if (PalletCylinders.Count < 8)
- {
- for (int i = 1; i < 3; i++)
- {
- PalletCylinders.Add(new CylinderModel()
- {
- Name = $"托盘气缸1_{(i + 1) % 2 + 1}",
- LeftTog = false,
- RightTog = false,
- });
- }
- for (int i = 1; i < 3; i++)
- {
- PalletCylinders.Add(new CylinderModel()
- {
- Name = $"托盘气缸2_{(i + 1) % 2 + 1}",
- LeftTog = false,
- RightTog = false,
- });
- }
- PalletCylinders.Add(new CylinderModel()
- {
- Name = $"进料桶顶升气缸",
- LeftTog = false,
- RightTog = false,
- });
- for (int i = 0; i < 3; i++)
- {
- PalletCylinders.Add(new CylinderModel()
- {
- Name = $"出料桶顶升气缸{i + 1}",
- LeftTog = false,
- RightTog = false,
- });
- }
- }
- Open = new RelayCommand<object>((o) =>
- {
- ActionManage.GetInstance.Send("ManualOpen", o);
-
- });
- Close = new RelayCommand<object>((o) =>
- {
- ActionManage.GetInstance.Send("ManualClose", o);
- });
- StartAxisLoadCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxisLoadCommand");
- });
- StopAxisLoadCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxisLoadCommand");
- });
- StartAxisMidCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxisMidCommand");
- });
- StopAxisMidCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxisMidCommand");
- });
- StartAxisUnLoadCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxisUnLoadCommand");
- });
- StopAxisUnLoadCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxisUnLoadCommand");
- });
- StartAxis1Command = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxis1Command");
- });
- StopAxis1Command = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxis1Command");
- });
- StartAxis2Command = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxis2Command");
- });
- StopAxis2Command = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxis2Command");
- });
-
- SystemStartCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("SystemStart");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统启动!");
- });
- SystemStopCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("SystemStop");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统停止!");
- });
- SystemPauseCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("SystemPause");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统暂停!");
- });
- SystemResetCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("SystemReset");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统暂停后复位!");
- });
- DebugMode = new RelayCommand(() =>
- {
- // ActionManage.GetInstance.Send("SystemDebugMode");
- });
- AutoMode = new RelayCommand(() =>
- {
- // ActionManage.GetInstance.Send("SystemAutoMode");
- });
- }
-
- /// <summary>
- /// 升降气缸
- /// </summary>
- public static ObservableCollection<CylinderModel> cylinderModels { get; set; } = new ObservableCollection<CylinderModel>();
-
- /// <summary>
- /// 阻挡气缸
- /// </summary>
- public static ObservableCollection<CylinderModel> BlockCylinders { get; set; } = new ObservableCollection<CylinderModel>();
-
- /// <summary>
- /// 托盘气缸
- /// </summary>
- public static ObservableCollection<CylinderModel> PalletCylinders { get; set; } = new ObservableCollection<CylinderModel>();
- public static string SystemMode { get { return _mSystemMode; } set { _mSystemMode = value; OnStaticPropertyChanged(); } }
- private static string _mSystemMode = String.Empty;
-
-
- public static string SystemStatus { get { return _mSystemStatus; } set { _mSystemStatus = value; OnStaticPropertyChanged(); } }
- private static string _mSystemStatus;
- public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
- private static void OnStaticPropertyChanged([CallerMemberName] string PropName = "")
- {
- StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName));
- }
- public RelayCommand<object> Open { get; set; }
-
- public RelayCommand<object> Close { get; set; }
-
- //五个电机手动控制
- public RelayCommand StartAxisLoadCommand { get; set; }
- public RelayCommand StopAxisLoadCommand { get; set; }
- public RelayCommand StartAxisMidCommand { get; set; }
- public RelayCommand StopAxisMidCommand { get; set; }
- public RelayCommand StartAxisUnLoadCommand { get; set; }
- public RelayCommand StopAxisUnLoadCommand { get; set; }
- public RelayCommand StartAxis1Command { get; set; }
- public RelayCommand StopAxis1Command { get; set; }
- public RelayCommand StartAxis2Command { get; set; }
- public RelayCommand StopAxis2Command { get; set; }
-
- public RelayCommand SystemStartCommand { get; set; }
- public RelayCommand SystemStopCommand { get; set; }
- public RelayCommand SystemPauseCommand { get; set; }
-
- public RelayCommand SystemResetCommand { get; set; }
-
- public RelayCommand AutoMode { get; set; }
- public RelayCommand DebugMode { get; set; }
-
- /// <summary>
- /// 系统模式改变
- /// </summary>
- public static bool PlcSystemMode
- {
- get { return _mPlcSystemMode; }
- set
- {
- if (_mPlcSystemMode != value || string.IsNullOrEmpty(SystemMode))
- {
- _mPlcSystemMode = value;
- SystemMode = value ? "手动" : "自动";
- if (value) ManualMode = true;
- else AutoModeStatus = true;
- }
-
- }
- }
- private static bool _mPlcSystemMode;
-
-
- /// <summary>
- /// 自动模式
- /// </summary>
- public static bool AutoModeStatus
- {
- get { return _mAutoModeStatus; }
- set
- {
- if (_mAutoModeStatus != value || (!_mAutoModeStatus && !_mManualMode))
- {
- if (value)
- ProcessControl.GetInstance.HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", false);
- _mAutoModeStatus = value;
- OnStaticPropertyChanged();
- }
- }
- }
- private static bool _mAutoModeStatus;
-
- /// <summary>
- /// 手动模式
- /// </summary>
- public static bool ManualMode
- {
- get { return _mManualMode; }
- set
- {
- if (_mManualMode != value || (!_mAutoModeStatus && !_mManualMode))
- {
- if (value)
- ProcessControl.GetInstance.HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", true);
- _mManualMode = value;
- OnStaticPropertyChanged();
- }
- }
- }
- private static bool _mManualMode;
- }
-
-
-
- public class CylinderModel : ObservableObject
- {
- public bool LeftTog { get { return _mLeftTog; } set { _mLeftTog = value; OnPropertyChanged(); } }
- private bool _mLeftTog;
-
- public bool RightTog { get { return _mRightTog; } set { _mRightTog = value; OnPropertyChanged(); } }
- private bool _mRightTog;
-
- public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } }
- private string _mName;
- }
- }
|