|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPA.Helper;
- using System.Collections.ObjectModel;
- using System.Threading;
- using BPASmartClient.S7Net;
-
- namespace BPASmartClient.DosingSystem.ViewModel
- {
- public class ManualControlViewModel : NotifyBase
- {
- public ManualControlViewModel()
- {
- Init();
- for (int i = 0; i < Json<DevicePar>.Data.BaseParModel.LiftCylinderCount; i++)
- {
- cylinderModels.Add(new CylinderModel()
- {
- Name = $"升降气缸 {i + 1}",
- LeftTog = false,
- RightTog = false,
- Num = i + 1,
- });
- }
-
- for (int i = 0; i < Json<DevicePar>.Data.BaseParModel.BlockCylinderCount; i++)
- {
- BlockCylinders.Add(new CylinderModel()
- {
- Name = $"阻挡气缸 {i + 1}",
- LeftTog = false,
- RightTog = false,
- Num = i + 1,
- });
- }
-
- for (int i = 0; i < Json<DevicePar>.Data.BaseParModel.PalletCylinderCount; i++)
- {
- PalletCylinders.Add(new CylinderModel()
- {
- Name = $"托盘气缸 {i + 1}",
- LeftTog = false,
- RightTog = false,
- Num = i + 1,
- });
- }
-
- OtherHandCylinders.Add(new CylinderModel() { Name = "上桶工位气缸" });
- OtherHandCylinders.Add(new CylinderModel() { Name = "下桶工位气缸" });
-
- Open = new BPARelayCommand<object>((o) =>
- {
- if (o != null)
- {
- if (o.ToString().Contains("升降气缸"))
- {
- int index = Array.FindIndex(cylinderModels.ToArray(), p => p.Name == o.ToString());
- if (index >= 0 && index < cylinderModels.Count)
- {
- var addRes = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", cylinderModels.ElementAt(index).Num);
- SiemensDevice.GetInstance.MySiemens.Write(addRes, true);
- }
- }
- else if (o.ToString().Contains("上桶工位气缸"))
- {
- SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.0", true);
- }
- else if (o.ToString().Contains("下桶工位气缸"))
- {
- SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.1", true);
- }
- }
- });
-
-
- Close = new BPARelayCommand<object>((o) =>
- {
- if (o != null)
- {
- if (o.ToString().Contains("升降气缸"))
- {
- int index = Array.FindIndex(cylinderModels.ToArray(), p => p.Name == o.ToString());
- if (index >= 0 && index < cylinderModels.Count)
- {
- var addRes = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", cylinderModels.ElementAt(index).Num);
- SiemensDevice.GetInstance.MySiemens.Write(addRes, false);
- }
- }
- else if (o.ToString().Contains("上桶工位气缸"))
- {
- SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.0", false);
- }
- else if (o.ToString().Contains("下桶工位气缸"))
- {
- SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.1", false);
- }
- }
- });
-
- SystemStart = new BPARelayCommand(() =>
- {
- SiemensDevice.GetInstance.MySiemens.Write("M10.0", SystemControlText == "停止" ? false : true);
- Thread.Sleep(100);
- var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.0");
- SystemControlText = res ? "停止" : "启动";
- });
- ModelSwitch = new BPARelayCommand(() =>
- {
- SiemensDevice.GetInstance.MySiemens.Write("M10.1", ModelSwitchText == "手动" ? true : false);
- Thread.Sleep(100);
- var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.1");
- ModelSwitchText = res ? "自动" : "手动";
- });
-
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- for (int i = 0; i < cylinderModels.Count; i++)
- {
- //升降气缸状态
- cylinderModels.ElementAt(i).RightTog = (bool)GlobalDevice.PlcData.cylinderFlagBitStatus[i]?.HomeSignal;
- cylinderModels.ElementAt(i).LeftTog = (bool)GlobalDevice.PlcData.cylinderFlagBitStatus[i]?.InPlaceSignal;
- }
-
- //上桶工位气缸状态
- OtherHandCylinders.ElementAt(0).RightTog = GlobalDevice.PlcData.OnCylinderDetection.HomeSignal;
- OtherHandCylinders.ElementAt(0).LeftTog = GlobalDevice.PlcData.OnCylinderDetection.InPlaceSignal;
-
- //下桶工位气缸状态
- OtherHandCylinders.ElementAt(1).RightTog = GlobalDevice.PlcData.UnderCylinderDetection.HomeSignal;
- OtherHandCylinders.ElementAt(1).LeftTog = GlobalDevice.PlcData.UnderCylinderDetection.InPlaceSignal;
-
- SystemStatus = GlobalDevice.PlcData.SystemStartOrStop ? "启动" : "停止";
- SystemMode = GlobalDevice.PlcData.HandOrAuto ? "自动" : "手动";
-
- Thread.Sleep(100);
- }), "手动气缸状态监控",true);
- }
-
- private void Init()
- {
- var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.0");
- SystemControlText = res ? "停止" : "启动";
- SystemStatus = res ? "停止" : "启动";
-
- var res1 = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.1");
- ModelSwitchText = res1 ? "自动" : "手动";
- SystemStatus = res ? "自动" : "手动";
- }
-
- /// <summary>
- /// 升降气缸
- /// </summary>
- public ObservableCollection<CylinderModel> cylinderModels { get; set; } = new ObservableCollection<CylinderModel>();
-
- /// <summary>
- /// 阻挡气缸
- /// </summary>
- public ObservableCollection<CylinderModel> BlockCylinders { get; set; } = new ObservableCollection<CylinderModel>();
-
- /// <summary>
- /// 托盘气缸
- /// </summary>
- public ObservableCollection<CylinderModel> PalletCylinders { get; set; } = new ObservableCollection<CylinderModel>();
-
- /// <summary>
- /// 其它手动控制气缸
- /// </summary>
- public ObservableCollection<CylinderModel> OtherHandCylinders { get; set; } = new ObservableCollection<CylinderModel>();
-
- public BPARelayCommand<object> Open { get; set; }
-
- public BPARelayCommand<object> Close { get; set; }
-
- public BPARelayCommand SystemStart { get; set; }
- public BPARelayCommand ModelSwitch { get; set; }
-
-
- public string SystemControlText { get { return _mSystemControlText; } set { _mSystemControlText = value; OnPropertyChanged(); } }
- private string _mSystemControlText;
-
-
- public string ModelSwitchText { get { return _mModelSwitchText; } set { _mModelSwitchText = value; OnPropertyChanged(); } }
- private string _mModelSwitchText;
-
- public string SystemMode { get { return _mSystemMode; } set { _mSystemMode = value; OnPropertyChanged(); } }
- private string _mSystemMode;
-
- public string SystemStatus { get { return _mSystemStatus; } set { _mSystemStatus = value; OnPropertyChanged(); } }
- private string _mSystemStatus;
- }
-
- 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;
-
- public bool Control { get { return _mControl; } set { _mControl = value; OnPropertyChanged(); } }
- private bool _mControl;
-
- /// <summary>
- /// 气缸默认编号
- /// </summary>
- public int Num { get; set; }
-
- }
- }
|