终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

170 lines
6.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BPA.Helper;
  7. using System.Collections.ObjectModel;
  8. using System.Threading;
  9. namespace BPASmartClient.DosingSystem.ViewModel
  10. {
  11. public class ManualControlViewModel : NotifyBase
  12. {
  13. public ManualControlViewModel()
  14. {
  15. for (int i = 0; i < Json<DevicePar>.Data.BaseParModel.LiftCylinderCount; i++)
  16. {
  17. cylinderModels.Add(new CylinderModel()
  18. {
  19. Name = $"升降气缸 {i + 1}",
  20. LeftTog = false,
  21. RightTog = false,
  22. Num = i + 1,
  23. });
  24. }
  25. for (int i = 0; i < Json<DevicePar>.Data.BaseParModel.BlockCylinderCount; i++)
  26. {
  27. BlockCylinders.Add(new CylinderModel()
  28. {
  29. Name = $"阻挡气缸 {i + 1}",
  30. LeftTog = false,
  31. RightTog = false,
  32. Num = i + 1,
  33. });
  34. }
  35. for (int i = 0; i < Json<DevicePar>.Data.BaseParModel.PalletCylinderCount; i++)
  36. {
  37. PalletCylinders.Add(new CylinderModel()
  38. {
  39. Name = $"托盘气缸 {i + 1}",
  40. LeftTog = false,
  41. RightTog = false,
  42. Num = i + 1,
  43. });
  44. }
  45. OtherHandCylinders.Add(new CylinderModel() { Name = "上桶工位气缸" });
  46. OtherHandCylinders.Add(new CylinderModel() { Name = "下桶工位气缸" });
  47. Open = new BPARelayCommand<object>((o) =>
  48. {
  49. if (o != null)
  50. {
  51. if (o.ToString().Contains("升降气缸"))
  52. {
  53. int index = Array.FindIndex(cylinderModels.ToArray(), p => p.Name == o.ToString());
  54. if (index >= 0 && index < cylinderModels.Count)
  55. {
  56. var addRes = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", cylinderModels.ElementAt(index).Num);
  57. SiemensDevice.GetInstance.MySiemens.Write(addRes, true);
  58. }
  59. }
  60. else if (o.ToString().Contains("上桶工位气缸"))
  61. {
  62. SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.0", true);
  63. }
  64. else if (o.ToString().Contains("下桶工位气缸"))
  65. {
  66. SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.1", true);
  67. }
  68. }
  69. });
  70. Close = new BPARelayCommand<object>((o) =>
  71. {
  72. if (o != null)
  73. {
  74. if (o.ToString().Contains("升降气缸"))
  75. {
  76. int index = Array.FindIndex(cylinderModels.ToArray(), p => p.Name == o.ToString());
  77. if (index >= 0 && index < cylinderModels.Count)
  78. {
  79. var addRes = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", cylinderModels.ElementAt(index).Num);
  80. SiemensDevice.GetInstance.MySiemens.Write(addRes, false);
  81. }
  82. }
  83. else if (o.ToString().Contains("上桶工位气缸"))
  84. {
  85. SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.0", false);
  86. }
  87. else if (o.ToString().Contains("下桶工位气缸"))
  88. {
  89. SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.1", false);
  90. }
  91. }
  92. });
  93. ThreadManage.GetInstance().StartLong(new Action(() =>
  94. {
  95. for (int i = 0; i < cylinderModels.Count; i++)
  96. {
  97. //升降气缸状态
  98. cylinderModels.ElementAt(i).RightTog = (bool)GlobalDevice.PlcData.cylinderFlagBitStatus[i]?.HomeSignal;
  99. cylinderModels.ElementAt(i).LeftTog = (bool)GlobalDevice.PlcData.cylinderFlagBitStatus[i]?.InPlaceSignal;
  100. }
  101. //上桶工位气缸状态
  102. OtherHandCylinders.ElementAt(0).RightTog = GlobalDevice.PlcData.OnCylinderDetection.HomeSignal;
  103. OtherHandCylinders.ElementAt(0).LeftTog = GlobalDevice.PlcData.OnCylinderDetection.InPlaceSignal;
  104. //下桶工位气缸状态
  105. OtherHandCylinders.ElementAt(1).RightTog = GlobalDevice.PlcData.UnderCylinderDetection.HomeSignal;
  106. OtherHandCylinders.ElementAt(1).LeftTog = GlobalDevice.PlcData.UnderCylinderDetection.InPlaceSignal;
  107. Thread.Sleep(100);
  108. }), "手动气缸状态监控");
  109. }
  110. /// <summary>
  111. /// 升降气缸
  112. /// </summary>
  113. public ObservableCollection<CylinderModel> cylinderModels { get; set; } = new ObservableCollection<CylinderModel>();
  114. /// <summary>
  115. /// 阻挡气缸
  116. /// </summary>
  117. public ObservableCollection<CylinderModel> BlockCylinders { get; set; } = new ObservableCollection<CylinderModel>();
  118. /// <summary>
  119. /// 托盘气缸
  120. /// </summary>
  121. public ObservableCollection<CylinderModel> PalletCylinders { get; set; } = new ObservableCollection<CylinderModel>();
  122. /// <summary>
  123. /// 其它手动控制气缸
  124. /// </summary>
  125. public ObservableCollection<CylinderModel> OtherHandCylinders { get; set; } = new ObservableCollection<CylinderModel>();
  126. public BPARelayCommand<object> Open { get; set; }
  127. public BPARelayCommand<object> Close { get; set; }
  128. }
  129. public class CylinderModel : NotifyBase
  130. {
  131. public bool LeftTog { get { return _mLeftTog; } set { _mLeftTog = value; OnPropertyChanged(); } }
  132. private bool _mLeftTog;
  133. public bool RightTog { get { return _mRightTog; } set { _mRightTog = value; OnPropertyChanged(); } }
  134. private bool _mRightTog;
  135. public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } }
  136. private string _mName;
  137. public bool Control { get { return _mControl; } set { _mControl = value; OnPropertyChanged(); } }
  138. private bool _mControl;
  139. /// <summary>
  140. /// 气缸默认编号
  141. /// </summary>
  142. public int Num { get; set; }
  143. }
  144. }