终端一体化运控平台
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.
 
 
 

424 satır
16 KiB

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