|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- using BPASmartClient.CustomResource.UserControls;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.FoodStationTest.Model;
- using BPASmartClient.Helper;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- 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 : 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 < 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 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;
- }
- }
|