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