终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

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