|
- 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;
-
- namespace BPASmartClient.DosingSystem.ViewModel
- {
- public class ManualControlViewModel : NotifyBase
- {
- public ManualControlViewModel()
- {
- 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);
- }
- }
- });
-
- 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;
-
- Thread.Sleep(100);
- }), "手动气缸状态监控");
- }
-
- /// <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 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; }
-
- }
- }
|