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

310 lines
17 KiB

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