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

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