终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

374 lines
14 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.ObjectModel;
  8. using Microsoft.Toolkit.Mvvm.Input;
  9. using BPASmartClient.Helper;
  10. using BPASmartClient.JXJFoodSmallStation.Model;
  11. using System.Threading;
  12. using System.ComponentModel;
  13. using System.Runtime.CompilerServices;
  14. using BPASmartClient.CustomResource.UserControls.MessageShow;
  15. using BPASmartClient.CustomResource.UserControls;
  16. namespace BPASmartClient.JXJFoodSmallStation.ViewModel
  17. {
  18. public class ManualControlViewModel : ObservableObject
  19. {
  20. public ManualControlViewModel()
  21. {
  22. ThreadManage.GetInstance().StartLong(new Action(() =>
  23. {
  24. SystemMode = GVL_SmallStation.GetInstance.PlcSystemMode ? "手动" : "自动";
  25. if (GVL_SmallStation.GetInstance.PlcSystemMode) ManualMode = true;
  26. else AutoModeStatus = true;
  27. if (GVL_SmallStation.GetInstance.PlcSystemIsAutoRun)
  28. {
  29. if (GVL_SmallStation.GetInstance.PlcSystemIsPause)
  30. {
  31. SystemStatus = "暂停";
  32. }
  33. else
  34. {
  35. SystemStatus = "运行";
  36. }
  37. }
  38. else
  39. {
  40. SystemStatus = "停止";
  41. }
  42. for (int i = 0; i < 15; i++)
  43. {
  44. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[i])
  45. {
  46. cylinderModels.ElementAt(i).LeftTog = true;
  47. cylinderModels.ElementAt(i).RightTog = false;
  48. }
  49. else
  50. {
  51. cylinderModels.ElementAt(i).LeftTog = false;
  52. cylinderModels.ElementAt(i).RightTog = true;
  53. }
  54. }
  55. foreach (var item in PalletCylinders)
  56. {
  57. if (item.Name == "进料桶顶升气缸")
  58. {
  59. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[20])
  60. {
  61. item.LeftTog = true;
  62. item.RightTog = false;
  63. }
  64. else
  65. {
  66. item.LeftTog = false;
  67. item.RightTog = true;
  68. }
  69. }
  70. if (item.Name == "出料桶顶升气缸1")
  71. {
  72. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[21])
  73. {
  74. item.LeftTog = true;
  75. item.RightTog = false;
  76. }
  77. else
  78. {
  79. item.LeftTog = false;
  80. item.RightTog = true;
  81. }
  82. }
  83. if (item.Name == "出料桶顶升气缸2")
  84. {
  85. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[22])
  86. {
  87. item.LeftTog = true;
  88. item.RightTog = false;
  89. }
  90. else
  91. {
  92. item.LeftTog = false;
  93. item.RightTog = true;
  94. }
  95. }
  96. if (item.Name == "出料桶顶升气缸3")
  97. {
  98. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[23])
  99. {
  100. item.LeftTog = true;
  101. item.RightTog = false;
  102. }
  103. else
  104. {
  105. item.LeftTog = false;
  106. item.RightTog = true;
  107. }
  108. }
  109. if (item.Name == "托盘气缸1_1")
  110. {
  111. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[24])
  112. {
  113. item.LeftTog = false;
  114. item.RightTog = true;
  115. }
  116. else
  117. {
  118. item.LeftTog = true;
  119. item.RightTog = false;
  120. }
  121. }
  122. if (item.Name == "托盘气缸1_2")
  123. {
  124. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[25])
  125. {
  126. item.LeftTog = false;
  127. item.RightTog = true;
  128. }
  129. else
  130. {
  131. item.LeftTog = true;
  132. item.RightTog = false;
  133. }
  134. }
  135. if (item.Name == "托盘气缸2_1")
  136. {
  137. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[26])
  138. {
  139. item.LeftTog = false;
  140. item.RightTog = true;
  141. }
  142. else
  143. {
  144. item.LeftTog = true;
  145. item.RightTog = false;
  146. }
  147. }
  148. if (item.Name == "托盘气缸2_2")
  149. {
  150. if (GVL_SmallStation.GetInstance.Cylinder_JackInfo[27])
  151. {
  152. item.LeftTog = false;
  153. item.RightTog = true;
  154. }
  155. else
  156. {
  157. item.LeftTog = true;
  158. item.RightTog = false;
  159. }
  160. }
  161. }
  162. Thread.Sleep(200);
  163. }), "获取系统状态", true);
  164. if (cylinderModels.Count < 15)
  165. {
  166. for (int i = 0; i < 15; i++)
  167. {
  168. cylinderModels.Add(new CylinderModel()
  169. {
  170. Name = $"升降气缸 {i + 1}",
  171. LeftTog = false,
  172. RightTog = false,
  173. });
  174. BlockCylinders.Add(new CylinderModel()
  175. {
  176. Name = $"阻挡气缸 {i + 1}",
  177. LeftTog = false,
  178. RightTog = false,
  179. });
  180. }
  181. }
  182. if (PalletCylinders.Count < 8)
  183. {
  184. for (int i = 1; i < 3; i++)
  185. {
  186. PalletCylinders.Add(new CylinderModel()
  187. {
  188. Name = $"托盘气缸1_{(i + 1) % 2 + 1}",
  189. LeftTog = false,
  190. RightTog = false,
  191. });
  192. }
  193. for (int i = 1; i < 3; i++)
  194. {
  195. PalletCylinders.Add(new CylinderModel()
  196. {
  197. Name = $"托盘气缸2_{(i + 1) % 2 + 1}",
  198. LeftTog = false,
  199. RightTog = false,
  200. });
  201. }
  202. PalletCylinders.Add(new CylinderModel()
  203. {
  204. Name = $"进料桶顶升气缸",
  205. LeftTog = false,
  206. RightTog = false,
  207. });
  208. for (int i = 0; i < 3; i++)
  209. {
  210. PalletCylinders.Add(new CylinderModel()
  211. {
  212. Name = $"出料桶顶升气缸{i + 1}",
  213. LeftTog = false,
  214. RightTog = false,
  215. });
  216. }
  217. }
  218. Open = new RelayCommand<object>((o) =>
  219. {
  220. ActionManage.GetInstance.Send("ManualOpen", o);
  221. });
  222. Close = new RelayCommand<object>((o) =>
  223. {
  224. ActionManage.GetInstance.Send("ManualClose", o);
  225. });
  226. StartAxisLoadCommand = new RelayCommand(() =>
  227. {
  228. ActionManage.GetInstance.Send("StartAxisLoadCommand");
  229. });
  230. StopAxisLoadCommand = new RelayCommand(() =>
  231. {
  232. ActionManage.GetInstance.Send("StopAxisLoadCommand");
  233. });
  234. StartAxisMidCommand = new RelayCommand(() =>
  235. {
  236. ActionManage.GetInstance.Send("StartAxisMidCommand");
  237. });
  238. StopAxisMidCommand = new RelayCommand(() =>
  239. {
  240. ActionManage.GetInstance.Send("StopAxisMidCommand");
  241. });
  242. StartAxisUnLoadCommand = new RelayCommand(() =>
  243. {
  244. ActionManage.GetInstance.Send("StartAxisUnLoadCommand");
  245. });
  246. StopAxisUnLoadCommand = new RelayCommand(() =>
  247. {
  248. ActionManage.GetInstance.Send("StopAxisUnLoadCommand");
  249. });
  250. StartAxis1Command = new RelayCommand(() =>
  251. {
  252. ActionManage.GetInstance.Send("StartAxis1Command");
  253. });
  254. StopAxis1Command = new RelayCommand(() =>
  255. {
  256. ActionManage.GetInstance.Send("StopAxis1Command");
  257. });
  258. StartAxis2Command = new RelayCommand(() =>
  259. {
  260. ActionManage.GetInstance.Send("StartAxis2Command");
  261. });
  262. StopAxis2Command = new RelayCommand(() =>
  263. {
  264. ActionManage.GetInstance.Send("StopAxis2Command");
  265. });
  266. SystemStartCommand = new RelayCommand(() =>
  267. {
  268. ActionManage.GetInstance.Send("SystemStart");
  269. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统启动!");
  270. });
  271. SystemStopCommand = new RelayCommand(() =>
  272. {
  273. ActionManage.GetInstance.Send("SystemStop");
  274. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统停止!");
  275. });
  276. SystemPauseCommand = new RelayCommand(() =>
  277. {
  278. ActionManage.GetInstance.Send("SystemPause");
  279. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统暂停!");
  280. });
  281. SystemResetCommand = new RelayCommand(() =>
  282. {
  283. ActionManage.GetInstance.Send("SystemReset");
  284. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"系统暂停后复位!");
  285. });
  286. DebugMode = new RelayCommand(() =>
  287. {
  288. ActionManage.GetInstance.Send("SystemDebugMode");
  289. });
  290. AutoMode = new RelayCommand(() =>
  291. {
  292. ActionManage.GetInstance.Send("SystemAutoMode");
  293. });
  294. }
  295. /// <summary>
  296. /// 升降气缸
  297. /// </summary>
  298. public static ObservableCollection<CylinderModel> cylinderModels { get; set; } = new ObservableCollection<CylinderModel>();
  299. /// <summary>
  300. /// 阻挡气缸
  301. /// </summary>
  302. public static ObservableCollection<CylinderModel> BlockCylinders { get; set; } = new ObservableCollection<CylinderModel>();
  303. /// <summary>
  304. /// 托盘气缸
  305. /// </summary>
  306. public static ObservableCollection<CylinderModel> PalletCylinders { get; set; } = new ObservableCollection<CylinderModel>();
  307. public static string SystemMode { get { return _mSystemMode; } set { _mSystemMode = value; OnStaticPropertyChanged(); } }
  308. private static string _mSystemMode = String.Empty;
  309. public static string SystemStatus { get { return _mSystemStatus; } set { _mSystemStatus = value; OnStaticPropertyChanged(); } }
  310. private static string _mSystemStatus;
  311. public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
  312. private static void OnStaticPropertyChanged([CallerMemberName] string PropName = "")
  313. {
  314. StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName));
  315. }
  316. public RelayCommand<object> Open { get; set; }
  317. public RelayCommand<object> Close { get; set; }
  318. //五个电机手动控制
  319. public RelayCommand StartAxisLoadCommand { get; set; }
  320. public RelayCommand StopAxisLoadCommand { get; set; }
  321. public RelayCommand StartAxisMidCommand { get; set; }
  322. public RelayCommand StopAxisMidCommand { get; set; }
  323. public RelayCommand StartAxisUnLoadCommand { get; set; }
  324. public RelayCommand StopAxisUnLoadCommand { get; set; }
  325. public RelayCommand StartAxis1Command { get; set; }
  326. public RelayCommand StopAxis1Command { get; set; }
  327. public RelayCommand StartAxis2Command { get; set; }
  328. public RelayCommand StopAxis2Command { get; set; }
  329. public RelayCommand SystemStartCommand { get; set; }
  330. public RelayCommand SystemStopCommand { get; set; }
  331. public RelayCommand SystemPauseCommand { get; set; }
  332. public RelayCommand SystemResetCommand { get; set; }
  333. public RelayCommand AutoMode { get; set; }
  334. public RelayCommand DebugMode { get; set; }
  335. public bool AutoModeStatus { get { return _mAutoModeStatus; } set { _mAutoModeStatus = value; OnPropertyChanged(); } }
  336. private bool _mAutoModeStatus;
  337. public bool ManualMode { get { return _mManualMode; } set { _mManualMode = value; OnPropertyChanged(); } }
  338. private bool _mManualMode;
  339. }
  340. public class CylinderModel : ObservableObject
  341. {
  342. public bool LeftTog { get { return _mLeftTog; } set { _mLeftTog = value; OnPropertyChanged(); } }
  343. private bool _mLeftTog;
  344. public bool RightTog { get { return _mRightTog; } set { _mRightTog = value; OnPropertyChanged(); } }
  345. private bool _mRightTog;
  346. public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } }
  347. private string _mName;
  348. }
  349. }