终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

ManualControlViewModel.cs 16 KiB

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