|
- using BPASmartClient.CustomResource.UserControls;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.FoodStationTest.Model;
- using BPA.Helper;
- using BPA.Helper;
-
- using System;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Threading;
-
- namespace BPASmartClient.FoodStationTest.ViewModel
- {
- public class ManualControlViewModel : NotifyBase
- {
- public ManualControlViewModel()
- {
- TaskManage.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 < Json<LocalPar>.Data.RawMaterialDeviceNum)
- {
- for (int i = 0; i < Json<LocalPar>.Data.RawMaterialDeviceNum; 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 BPARelayCommand<object>((o) =>
- {
- ActionManage.GetInstance.Send("ManualOpen", o);
- });
- Close = new BPARelayCommand<object>((o) =>
- {
- ActionManage.GetInstance.Send("ManualClose", o);
- });
- StartAxisLoadCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxisLoadCommand");
- });
- StopAxisLoadCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxisLoadCommand");
- });
- StartAxisMidCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxisMidCommand");
- });
- StopAxisMidCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxisMidCommand");
- });
- StartAxisUnLoadCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxisUnLoadCommand");
- });
- StopAxisUnLoadCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxisUnLoadCommand");
- });
- StartAxis1Command = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxis1Command");
- });
- StopAxis1Command = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxis1Command");
- });
- StartAxis2Command = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StartAxis2Command");
- });
- StopAxis2Command = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("StopAxis2Command");
- });
-
- SystemStartCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("SystemStart");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统启动!");
- });
- SystemStopCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("SystemStop");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统停止!");
- });
- SystemPauseCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("SystemPause");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统暂停!");
- });
- SystemResetCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("SystemReset");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统暂停后复位!");
- });
- DebugMode = new BPARelayCommand(() =>
- {
- // ActionManage.GetInstance.Send("SystemDebugMode");
- });
- AutoMode = new BPARelayCommand(() =>
- {
- // 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 BPARelayCommand<object> Open { get; set; }
-
- public BPARelayCommand<object> Close { get; set; }
-
- //五个电机手动控制
- public BPARelayCommand StartAxisLoadCommand { get; set; }
- public BPARelayCommand StopAxisLoadCommand { get; set; }
- public BPARelayCommand StartAxisMidCommand { get; set; }
- public BPARelayCommand StopAxisMidCommand { get; set; }
- public BPARelayCommand StartAxisUnLoadCommand { get; set; }
- public BPARelayCommand StopAxisUnLoadCommand { get; set; }
- public BPARelayCommand StartAxis1Command { get; set; }
- public BPARelayCommand StopAxis1Command { get; set; }
- public BPARelayCommand StartAxis2Command { get; set; }
- public BPARelayCommand StopAxis2Command { get; set; }
-
- public BPARelayCommand SystemStartCommand { get; set; }
- public BPARelayCommand SystemStopCommand { get; set; }
- public BPARelayCommand SystemPauseCommand { get; set; }
-
- public BPARelayCommand SystemResetCommand { get; set; }
-
- public BPARelayCommand AutoMode { get; set; }
- public BPARelayCommand 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 : NotifyBase
- {
- 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;
- }
- }
|