终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1 рік тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using BPA.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Linq;
  6. using System.Threading;
  7. namespace BPASmartClient.DosingSystem.ViewModel
  8. {
  9. public class UHardwareStatusViewModel : NotifyBase
  10. {
  11. public UHardwareStatusViewModel()
  12. {
  13. //TopDeviceCurrentStatuses = new ObservableCollection<DeviceCurrentStatus>();
  14. //TopDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 }) ;
  15. //TopDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  16. //TopDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  17. //TopDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  18. //TopDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  19. //TopDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  20. //BottomDeviceCurrentStatuses = new ObservableCollection<DeviceCurrentStatus>();
  21. //BottomDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  22. //BottomDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  23. //BottomDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  24. //BottomDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  25. //BottomDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  26. //BottomDeviceCurrentStatuses.Add(new DeviceCurrentStatus { DeviceNum = 1 });
  27. //TopDeviceCurrentStatuses = DeviceInquire.GetInstance.TopDeviceCurrentStatuses;
  28. //BottomDeviceCurrentStatuses = DeviceInquire.GetInstance.BottomDeviceCurrentStatuses;
  29. //2023/7/3调整
  30. TopDeviceCurrentStatuses = ConvertToObservableCollention(DeviceInquire.GetInstance.TopDeviceCurrentStatuses.OrderByDescending(p => p.DeviceNum).Reverse());
  31. BottomDeviceCurrentStatuses = ConvertToObservableCollention(DeviceInquire.GetInstance.BottomDeviceCurrentStatuses.OrderByDescending(p => p.DeviceNum).Reverse());
  32. UnifordColumNum();
  33. TaskManage.GetInstance.StartLong(new Action(() =>
  34. {
  35. for (int i = 0; i < Json<DevicePar>.Data.OutletInfoModels.Count; i++)
  36. {
  37. int count = Json<DevicePar>.Data.OutletInfoModels.ElementAt(i).SiloInfos.Count;
  38. if (count >= 1)
  39. {
  40. for (int m = 0; m < count; m++)
  41. {
  42. var deviceName = Json<DevicePar>.Data.OutletInfoModels.ElementAt(i).SiloInfos.ElementAt(m);
  43. int topIndex = TopDeviceCurrentStatuses.ToList().FindIndex(p => p.DeviceName == deviceName);
  44. int bottomIndex = BottomDeviceCurrentStatuses.ToList().FindIndex(p => p.DeviceName == deviceName);
  45. if (topIndex >= 0 && topIndex < TopDeviceCurrentStatuses.Count)
  46. TopDeviceCurrentStatuses.ElementAt(i).BucketFlagbit = GlobalDevice.PlcData.StationDetection[i];
  47. if (bottomIndex >= 0 && bottomIndex < BottomDeviceCurrentStatuses.Count)
  48. BottomDeviceCurrentStatuses.ElementAt(i).BucketFlagbit = GlobalDevice.PlcData.StationDetection[i];
  49. }
  50. }
  51. }
  52. StatusUpdate(TopDeviceCurrentStatuses);
  53. StatusUpdate(BottomDeviceCurrentStatuses);
  54. OnDetection = GlobalDevice.PlcData.OnDetection;
  55. UnderDetection = GlobalDevice.PlcData.UnderDetection;
  56. ConveyerBeltStatus = GlobalDevice.MotorControlFeedback > 0 ? 2 : GlobalDevice.MotorControlFeedback;
  57. Thread.Sleep(100);
  58. }), "输送带料仓状态监控", true);
  59. RecipeControlCommand = new BPARelayCommand<object>((o) =>
  60. {
  61. if (o != null && o is DeviceCurrentStatus currentStatus)
  62. {
  63. var res = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == currentStatus.DeviceName);
  64. if (res != null)
  65. {
  66. DeviceInquire.GetInstance.GetDevice(res.IpAddress).Start(currentStatus.SetWeight);
  67. }
  68. }
  69. });
  70. }
  71. private void StatusUpdate(ObservableCollection<DeviceCurrentStatus> devices)
  72. {
  73. if (devices == null) return;
  74. for (int i = 0; i < devices.Count; i++)
  75. {
  76. if (devices.ElementAt(i).BaitingControl)
  77. {
  78. var res = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == devices.ElementAt(i).DeviceName);
  79. if (res != null)
  80. {
  81. var runStatus = DeviceInquire.GetInstance.GetDevice(res.IpAddress).deviceStatus.RunStatus;
  82. if (runStatus == 3)
  83. {
  84. if (TopDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == devices.ElementAt(i).DeviceName) != null)
  85. {
  86. TopDeviceCurrentStatuses.ElementAt(i).BaitingControl = false;
  87. }
  88. else if (BottomDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == devices.ElementAt(i).DeviceName) != null)
  89. {
  90. BottomDeviceCurrentStatuses.ElementAt(i).BaitingControl = false;
  91. }
  92. DeviceInquire.GetInstance.GetDevice(res.IpAddress).StatusReset();
  93. }
  94. }
  95. }
  96. }
  97. }
  98. /// <summary>
  99. /// 根据料仓数来进行uniform列划分
  100. /// </summary>
  101. private void UnifordColumNum()
  102. {
  103. //StockNum = Json<DevicePar>.Data.BaseParModel.StockCount;
  104. StockNum = TopDeviceCurrentStatuses.Count >= BottomDeviceCurrentStatuses.Count ? TopDeviceCurrentStatuses.Count : BottomDeviceCurrentStatuses.Count;
  105. }
  106. /// <summary>
  107. /// 数组集合转换
  108. /// </summary>
  109. /// <typeparam name="T"></typeparam>
  110. /// <param name="array"></param>
  111. /// <returns></returns>
  112. public ObservableCollection<T> ConvertToObservableCollention<T>(IEnumerable<T> array)
  113. {
  114. ObservableCollection<T> collec = new ObservableCollection<T>();
  115. foreach (var item in array)
  116. {
  117. collec.Add(item);
  118. }
  119. return collec;
  120. }
  121. public ObservableCollection<DeviceCurrentStatus> TopDeviceCurrentStatuses { get; set; }
  122. public ObservableCollection<DeviceCurrentStatus> BottomDeviceCurrentStatuses { get; set; }
  123. public ObservableCollection<ConveyerBeltModel> ConveyerBeltModels { get; set; } = new ObservableCollection<ConveyerBeltModel>();
  124. public BPARelayCommand<object> ConveyerBeltControlCommand { get; set; }
  125. public BPARelayCommand<object> RecipeControlCommand { get; set; }
  126. /// <summary>
  127. /// Uniford根据料仓数量来划分列数量
  128. /// </summary>
  129. private int _stockNum;
  130. public int StockNum { get { return _stockNum; } set { _stockNum = value; OnPropertyChanged(); } }
  131. /// <summary>
  132. /// 输送带状态
  133. /// </summary>
  134. public uint ConveyerBeltStatus { get { return _mConveyerBeltStatus; } set { _mConveyerBeltStatus = value; OnPropertyChanged(); } }
  135. private uint _mConveyerBeltStatus;
  136. /// <summary>
  137. /// 上桶工位检测
  138. /// </summary>
  139. public bool OnDetection { get { return _mOnDetection; } set { _mOnDetection = value; OnPropertyChanged(); } }
  140. private bool _mOnDetection;
  141. /// <summary>
  142. /// 下桶工位检测
  143. /// </summary>
  144. public bool UnderDetection { get { return _mUnderDetection; } set { _mUnderDetection = value; OnPropertyChanged(); } }
  145. private bool _mUnderDetection;
  146. }
  147. }