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

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