using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; using System.Collections.ObjectModel; using BPA.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 : 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 < 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 BPARelayCommand((o) => { ActionManage.GetInstance.Send("ManualOpen", o); }); Close = new BPARelayCommand((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"); }); } /// /// 升降气缸 /// public static ObservableCollection cylinderModels { get; set; } = new ObservableCollection(); /// /// 阻挡气缸 /// public static ObservableCollection BlockCylinders { get; set; } = new ObservableCollection(); /// /// 托盘气缸 /// public static ObservableCollection PalletCylinders { get; set; } = new ObservableCollection(); 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 StaticPropertyChanged; private static void OnStaticPropertyChanged([CallerMemberName] string PropName = "") { StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName)); } public BPARelayCommand Open { get; set; } public BPARelayCommand 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; } /// /// 系统模式改变 /// 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; /// /// 自动模式 /// public static bool AutoModeStatus { get { return _mAutoModeStatus; } set { if (_mAutoModeStatus != value || (!_mAutoModeStatus && !_mManualMode)) { if (value) ProcessControl.GetInstance.HKDevice.HK_PLC_S7.Write("DB44.DBX0.1", false); _mAutoModeStatus = value; OnStaticPropertyChanged(); } } } private static bool _mAutoModeStatus; /// /// 手动模式 /// public static bool ManualMode { get { return _mManualMode; } set { if (_mManualMode != value || (!_mAutoModeStatus && !_mManualMode)) { if (value) ProcessControl.GetInstance.HKDevice.HK_PLC_S7.Write("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; } }