|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- 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);
- var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.0");
- SystemControlText = res ? "停止" : "启动";
- });
- ModelSwitch = new BPARelayCommand(() =>
- {
- SiemensDevice.GetInstance.MySiemens.Write("M10.1", ModelSwitchText == "手动" ? true : false);
- 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;
-
- //SystemControlText = GlobalDevice.PlcData.SystemStartOrStop ? "停止系统" : "启动系统";
- //ModelSwitchText = GlobalDevice.PlcData.HandOrAuto ? "自动" : "手动";
-
- Thread.Sleep(100);
- }), "手动气缸状态监控");
- }
-
- private void Init()
- {
- var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.0");
- SystemControlText = res ? "停止" : "启动";
-
- var res1 = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.1");
- ModelSwitchText = res1 ? "自动" : "手动";
- }
-
- /// <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 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; }
-
- }
- }
|