终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

341 lines
19 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 BPASmartClient.JXJFoodSmallStation.Model;
  9. using BPASmartClient.Helper;
  10. using Microsoft.Toolkit.Mvvm.Input;
  11. using BPASmartClient.CustomResource.UserControls.MessageShow;
  12. using BPASmartClient.CustomResource.UserControls;
  13. using System.Diagnostics;
  14. using BPASmartClient.JXJFoodSmallStation.Model.Siemens;
  15. using BPASmartClient.JXJFoodSmallStation.Model.HK_PLC;
  16. using System.Threading;
  17. using System.ComponentModel;
  18. using System.Runtime.CompilerServices;
  19. using BPASmartClient.CustomResource.Pages.Model;
  20. using System.Windows;
  21. namespace BPASmartClient.JXJFoodSmallStation.ViewModel
  22. {
  23. public class ManualFlowViewModel : ObservableObject
  24. {
  25. public ManualFlowViewModel()
  26. {
  27. time = GVL_SmallStation.GetInstance.Time;
  28. Test1Command = new RelayCommand(() =>
  29. {
  30. ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX8.0", PlcVarType = PlcVarType.Bool, Value = true });
  31. //Thread.Sleep(200);
  32. //ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX8.0", PlcVarType = PlcVarType.Bool, Value = false });
  33. //GVL_SmallStation.GetInstance.AGV_PutTray1Finish = true;
  34. MessageNotify.GetInstance.ShowUserLog("手动点击按钮,AGV送托盘完成");
  35. VisibilityBtn1 = Visibility.Hidden;
  36. VisibilityBtn2 = Visibility.Visible;
  37. VisibilityBtn3 = Visibility.Hidden;
  38. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,AGV送托盘完成");
  39. });
  40. Test2Command = new RelayCommand(() =>
  41. {
  42. ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX4.0", PlcVarType = PlcVarType.Bool, Value = true });
  43. //Thread.Sleep(200);
  44. //ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX4.0", PlcVarType = PlcVarType.Bool, Value = false });
  45. //GVL_SmallStation.GetInstance.WindSendDosingComple = true;
  46. MessageNotify.GetInstance.ShowUserLog("手动点击按钮,粉料仓配料完成");
  47. VisibilityBtn1 = Visibility.Hidden;
  48. VisibilityBtn2 = Visibility.Hidden;
  49. VisibilityBtn3 = Visibility.Visible;
  50. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,粉料仓配料完成");
  51. });
  52. Test3Command = new RelayCommand(() =>
  53. {
  54. ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX10.0", PlcVarType = PlcVarType.Bool, Value = true });
  55. //Thread.Sleep(200);
  56. //ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX10.0", PlcVarType = PlcVarType.Bool, Value = false });
  57. //GVL_SmallStation.GetInstance.AGV_GetTray1Finish = true;
  58. MessageNotify.GetInstance.ShowUserLog("手动点击按钮,AGV取托盘完成");
  59. VisibilityBtn1 = Visibility.Visible;
  60. VisibilityBtn2 = Visibility.Hidden;
  61. VisibilityBtn3 = Visibility.Hidden;
  62. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,AGV取托盘完成");
  63. });
  64. Test4Command = new RelayCommand(() =>
  65. {
  66. ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX1.5", PlcVarType = PlcVarType.Bool, Value = true });
  67. //GVL_SmallStation.GetInstance.CylinderReset = true;
  68. MessageNotify.GetInstance.ShowUserLog("手动点击按钮,气缸收紧错位复位");
  69. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,气缸收紧错位复位");
  70. });
  71. //Test5Command = new RelayCommand(() =>
  72. //{
  73. // GVL_SmallStation.GetInstance.WindSendAllowAGVPutGet = true;
  74. // MessageNotify.GetInstance.ShowUserLog("手动点击按钮,粉料仓提升到位");
  75. //});
  76. Test6Command = new RelayCommand(() =>
  77. {
  78. ActionManage.GetInstance.Send("AGVPutTrayFinish");
  79. MessageNotify.GetInstance.ShowUserLog("手动点击按钮,AGV放货架流程完成");
  80. });
  81. CLearRecipeInfo = new RelayCommand(() =>
  82. {
  83. App.Current.Dispatcher.Invoke(() =>
  84. {
  85. if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【PLC配方清零】操作"))
  86. {
  87. ActionManage.GetInstance.Send("CLearRecipeInfo");
  88. MessageNotify.GetInstance.ShowUserLog("手动点击按钮,PLC配方清零");
  89. }
  90. });
  91. });
  92. SystemReset = new RelayCommand(() =>
  93. {
  94. App.Current.Dispatcher.Invoke(() =>
  95. {
  96. if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【PLC系统复位】操作"))
  97. {
  98. ActionManage.GetInstance.Send("ManualSystemReset");
  99. MessageNotify.GetInstance.ShowUserLog("手动点击按钮,PLC系统复位");
  100. }
  101. });
  102. });
  103. BPAResetCommand = new RelayCommand(() =>
  104. {
  105. App.Current.Dispatcher.Invoke(() =>
  106. {
  107. if (MessageNotify.GetInstance.ShowDialog("请确认,是否进行【上位机初始化】操作"))
  108. {
  109. ActionManage.GetInstance.Send("BPASystemReset");
  110. MessageNotify.GetInstance.ShowUserLog("手动点击按钮,上位机初始化");
  111. }
  112. });
  113. });
  114. StockbinDosingComple = new RelayCommand(() =>
  115. {
  116. int loc = StockbinDosingCompleNum;
  117. if (loc >= 1 && loc <= 8)
  118. {
  119. ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX12." + (loc - 1), PlcVarType = PlcVarType.Bool, Value = true });
  120. MessageNotify.GetInstance.ShowUserLog($"手动点击按钮,给plc料仓{loc}配料完成信号");
  121. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,手动设置料仓{loc}配料完成");
  122. }
  123. else if (loc >= 9 && loc <= 15)
  124. {
  125. ActionManage.GetInstance.Send("PLCWrite", new HKDeviceWrite() { Address = "DB4.DBX13." + (loc - 9), PlcVarType = PlcVarType.Bool, Value = true });
  126. MessageNotify.GetInstance.ShowUserLog($"手动点击按钮,给plc料仓{loc}配料完成信号");
  127. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,手动设置料仓{loc}配料完成");
  128. }
  129. else
  130. {
  131. MessageNotify.GetInstance.ShowUserLog("料仓编号不正确");
  132. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"手动点击按钮,手动设置料仓{loc}配料,料仓编号不正确");
  133. }
  134. });
  135. StockbinDosingCompleClear = new RelayCommand(() =>
  136. {
  137. //for (int i = 0; i < GVL_SmallStation.GetInstance.StockInDosingComple.Length; i++)
  138. //{
  139. // GVL_SmallStation.GetInstance.StockInDosingComple[i] = false;
  140. //}
  141. //MessageNotify.GetInstance.ShowUserLog($"手动点击按钮,清除所有手动配料完成信号");
  142. //NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"清除所有手动配料完成信号");
  143. });
  144. ThreadManage.GetInstance().StartLong(new Action(() =>
  145. {
  146. RecipeDosingCompleNum = GVL_SmallStation.GetInstance.RecipeDosingCompleNum;
  147. Recipe1DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[0].ToBinString();
  148. Recipe2DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[1].ToBinString();
  149. Recipe3DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[2].ToBinString();
  150. Recipe4DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[3].ToBinString();
  151. Recipe5DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[4].ToBinString();
  152. Heartbeat = GVL_SmallStation.GetInstance.HeartBeatFromPlc;
  153. switch (GVL_SmallStation.GetInstance.SiemensSendRecipeStatus)
  154. {
  155. case 0:
  156. OrderStatus = IssueRecipeCondition.等待小料站PLC允许下配方.ToString();
  157. break;
  158. case 1:
  159. OrderStatus = IssueRecipeCondition.等待西门子下发配方.ToString();
  160. break;
  161. case 2:
  162. OrderStatus = IssueRecipeCondition.等待西门子下发配方信号复位.ToString();
  163. break;
  164. case 3:
  165. OrderStatus = IssueRecipeCondition.等待上位机请求配料.ToString();
  166. break;
  167. case 4:
  168. OrderStatus = IssueRecipeCondition.等待西门子确认配料.ToString();
  169. break;
  170. case 5:
  171. OrderStatus = IssueRecipeCondition.等待西门子确认配料信号复位.ToString();
  172. break;
  173. case 6:
  174. OrderStatus = "上位机将配方添加到队列中";
  175. break;
  176. default:
  177. OrderStatus = "无意义";
  178. break;
  179. }
  180. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[0])
  181. {
  182. case 0:
  183. Recipe1DosingStatus = ProcessCondition.等待AGV到位.ToString();
  184. break;
  185. case 1:
  186. Recipe1DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  187. break;
  188. case 2:
  189. Recipe1DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  190. break;
  191. default:
  192. break;
  193. }
  194. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[1])
  195. {
  196. case 0:
  197. Recipe2DosingStatus = ProcessCondition.等待AGV到位.ToString();
  198. break;
  199. case 1:
  200. Recipe2DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  201. break;
  202. case 2:
  203. Recipe2DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  204. break;
  205. default:
  206. break;
  207. }
  208. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[2])
  209. {
  210. case 0:
  211. Recipe3DosingStatus = ProcessCondition.等待AGV到位.ToString();
  212. break;
  213. case 1:
  214. Recipe3DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  215. break;
  216. case 2:
  217. Recipe3DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  218. break;
  219. default:
  220. break;
  221. }
  222. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[3])
  223. {
  224. case 0:
  225. Recipe4DosingStatus = ProcessCondition.等待AGV到位.ToString();
  226. break;
  227. case 1:
  228. Recipe4DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  229. break;
  230. case 2:
  231. Recipe4DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  232. break;
  233. default:
  234. break;
  235. }
  236. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[4])
  237. {
  238. case 0:
  239. Recipe5DosingStatus = ProcessCondition.等待AGV到位.ToString();
  240. break;
  241. case 1:
  242. Recipe5DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  243. break;
  244. case 2:
  245. Recipe5DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  246. break;
  247. default:
  248. break;
  249. }
  250. Thread.Sleep(100);
  251. }), "流程手动设备状态读取", true);
  252. TimeSet = new RelayCommand(() =>
  253. {
  254. GVL_SmallStation.GetInstance.Time = time;
  255. MessageNotify.GetInstance.ShowUserLog($"设置柔性味魔方复位时间:{time}s");
  256. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{time.ToString()}:设置成功!");
  257. });
  258. SiemensIsConnect = ProcessControl.GetInstance.SiemensDevice.IsConnected;
  259. HKPlcIsConnect = ProcessControl.GetInstance.HKDevice.IsConnected;
  260. WindSendIsConnect = ProcessControl.GetInstance.WindSendDevice.IsConnected;
  261. }
  262. public RelayCommand Test1Command { get; set; }
  263. public RelayCommand Test2Command { get; set; }
  264. public RelayCommand Test3Command { get; set; }
  265. public RelayCommand Test4Command { get; set; }
  266. public RelayCommand Test5Command { get; set; }
  267. public RelayCommand Test6Command { get; set; }
  268. public RelayCommand TimeSet { get; set; }
  269. public static bool Heartbeat { get { return _mHeartbeat; } set { _mHeartbeat = value; OnStaticPropertyChanged(); } }
  270. private static bool _mHeartbeat;
  271. public int time { get { return _mtime; } set { _mtime = value; OnStaticPropertyChanged(); } }
  272. private int _mtime;
  273. public static string OrderStatus { get { return _mOrderStatus; } set { _mOrderStatus = value; OnStaticPropertyChanged(); } }
  274. private static string _mOrderStatus = "无意义";
  275. public static string Recipe1DosingStatus { get { return _mRecipe1DosingStatus; } set { _mRecipe1DosingStatus = value; OnStaticPropertyChanged(); } }
  276. private static string _mRecipe1DosingStatus = "无意义";
  277. public static string Recipe2DosingStatus { get { return _mRecipe2DosingStatus; } set { _mRecipe2DosingStatus = value; OnStaticPropertyChanged(); } }
  278. private static string _mRecipe2DosingStatus = "无意义";
  279. public static string Recipe3DosingStatus { get { return _mRecipe3DosingStatus; } set { _mRecipe3DosingStatus = value; OnStaticPropertyChanged(); } }
  280. private static string _mRecipe3DosingStatus = "无意义";
  281. public static string Recipe4DosingStatus { get { return _mRecipe4DosingStatus; } set { _mRecipe4DosingStatus = value; OnStaticPropertyChanged(); } }
  282. private static string _mRecipe4DosingStatus = "无意义";
  283. public static string Recipe5DosingStatus { get { return _mRecipe5DosingStatus; } set { _mRecipe5DosingStatus = value; OnStaticPropertyChanged(); } }
  284. private static string _mRecipe5DosingStatus = "无意义";
  285. public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
  286. public static void OnStaticPropertyChanged([CallerMemberName] string PropName = "")
  287. {
  288. StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName));
  289. }
  290. public RelayCommand CLearRecipeInfo { get; set; }
  291. public RelayCommand SystemReset { get; set; }
  292. public RelayCommand BPAResetCommand { get; set; }
  293. private bool _SiemensIsConnect { get; set; }
  294. public bool SiemensIsConnect { get { return _SiemensIsConnect; } set { _SiemensIsConnect = value; OnPropertyChanged(); } }
  295. private bool _HKPlcIsConnect { get; set; }
  296. public bool HKPlcIsConnect { get { return _HKPlcIsConnect; } set { _HKPlcIsConnect = value; OnPropertyChanged(); } }
  297. private bool _WindSendIsConnect { get; set; }
  298. public bool WindSendIsConnect { get { return _WindSendIsConnect; } set { _WindSendIsConnect = value; OnPropertyChanged(); } }
  299. private static string _Recipe1DosingComplete { get; set; }
  300. public static string Recipe1DosingComplete { get { return _Recipe1DosingComplete; } set { _Recipe1DosingComplete = value; OnStaticPropertyChanged(); } }
  301. private static string _Recipe2DosingComplete { get; set; }
  302. public static string Recipe2DosingComplete { get { return _Recipe2DosingComplete; } set { _Recipe2DosingComplete = value; OnStaticPropertyChanged(); } }
  303. private static string _Recipe3DosingComplete { get; set; }
  304. public static string Recipe3DosingComplete { get { return _Recipe3DosingComplete; } set { _Recipe3DosingComplete = value; OnStaticPropertyChanged(); } }
  305. private static string _Recipe4DosingComplete { get; set; }
  306. public static string Recipe4DosingComplete { get { return _Recipe4DosingComplete; } set { _Recipe4DosingComplete = value; OnStaticPropertyChanged(); } }
  307. private static string _Recipe5DosingComplete { get; set; }
  308. public static string Recipe5DosingComplete { get { return _Recipe5DosingComplete; } set { _Recipe5DosingComplete = value; OnStaticPropertyChanged(); } }
  309. public RelayCommand StockbinDosingComple { get; set; }
  310. public RelayCommand StockbinDosingCompleClear { get; set; }
  311. private static int _StockbinDosingCompleNum { get; set; }
  312. public static int StockbinDosingCompleNum { get { return _StockbinDosingCompleNum; } set { _StockbinDosingCompleNum = value; OnStaticPropertyChanged(); } }
  313. private static int _RecipeDosingCompleNum { get; set; }
  314. public static int RecipeDosingCompleNum { get { return _RecipeDosingCompleNum; } set { _RecipeDosingCompleNum = value; OnStaticPropertyChanged(); } }
  315. public static Visibility VisibilityBtn1 { get { return _VisibilityBtn1; } set { _VisibilityBtn1 = value; OnStaticPropertyChanged(); } }
  316. private static Visibility _VisibilityBtn1 = Visibility.Visible;
  317. public static Visibility VisibilityBtn2 { get { return _VisibilityBtn2; } set { _VisibilityBtn2 = value; OnStaticPropertyChanged(); } }
  318. private static Visibility _VisibilityBtn2 = Visibility.Hidden;
  319. public static Visibility VisibilityBtn3 { get { return _VisibilityBtn3; } set { _VisibilityBtn3 = value; OnStaticPropertyChanged(); } }
  320. private static Visibility _VisibilityBtn3 = Visibility.Hidden;
  321. }
  322. }