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

337 regels
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. Recipe1DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[0].ToBinString();
  147. Recipe2DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[1].ToBinString();
  148. Recipe3DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[2].ToBinString();
  149. Recipe4DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[3].ToBinString();
  150. Recipe5DosingComplete = GVL_SmallStation.GetInstance.RecipeStockBinDosing[4].ToBinString();
  151. Heartbeat = GVL_SmallStation.GetInstance.HeartBeatFromPlc;
  152. switch (GVL_SmallStation.GetInstance.SiemensSendRecipeStatus)
  153. {
  154. case 0:
  155. OrderStatus = IssueRecipeCondition.等待小料站PLC允许下配方.ToString();
  156. break;
  157. case 1:
  158. OrderStatus = IssueRecipeCondition.等待西门子下发配方.ToString();
  159. break;
  160. case 2:
  161. OrderStatus = IssueRecipeCondition.等待西门子下发配方信号复位.ToString();
  162. break;
  163. case 3:
  164. OrderStatus = IssueRecipeCondition.等待上位机请求配料.ToString();
  165. break;
  166. case 4:
  167. OrderStatus = IssueRecipeCondition.等待西门子确认配料.ToString();
  168. break;
  169. case 5:
  170. OrderStatus = IssueRecipeCondition.等待西门子确认配料信号复位.ToString();
  171. break;
  172. case 6:
  173. OrderStatus = "上位机将配方添加到队列中";
  174. break;
  175. default:
  176. OrderStatus = "无意义";
  177. break;
  178. }
  179. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[0])
  180. {
  181. case 0:
  182. Recipe1DosingStatus = ProcessCondition.等待AGV到位.ToString();
  183. break;
  184. case 1:
  185. Recipe1DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  186. break;
  187. case 2:
  188. Recipe1DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  189. break;
  190. default:
  191. break;
  192. }
  193. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[1])
  194. {
  195. case 0:
  196. Recipe2DosingStatus = ProcessCondition.等待AGV到位.ToString();
  197. break;
  198. case 1:
  199. Recipe2DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  200. break;
  201. case 2:
  202. Recipe2DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  203. break;
  204. default:
  205. break;
  206. }
  207. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[2])
  208. {
  209. case 0:
  210. Recipe3DosingStatus = ProcessCondition.等待AGV到位.ToString();
  211. break;
  212. case 1:
  213. Recipe3DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  214. break;
  215. case 2:
  216. Recipe3DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  217. break;
  218. default:
  219. break;
  220. }
  221. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[3])
  222. {
  223. case 0:
  224. Recipe4DosingStatus = ProcessCondition.等待AGV到位.ToString();
  225. break;
  226. case 1:
  227. Recipe4DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  228. break;
  229. case 2:
  230. Recipe4DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  231. break;
  232. default:
  233. break;
  234. }
  235. switch (GVL_SmallStation.GetInstance.RecipeProcessStatus[4])
  236. {
  237. case 0:
  238. Recipe5DosingStatus = ProcessCondition.等待AGV到位.ToString();
  239. break;
  240. case 1:
  241. Recipe5DosingStatus = ProcessCondition.等待小料站PLC接受配方完成.ToString();
  242. break;
  243. case 2:
  244. Recipe5DosingStatus = ProcessCondition.等待配方配料完成.ToString();
  245. break;
  246. default:
  247. break;
  248. }
  249. Thread.Sleep(100);
  250. }), "流程手动设备状态读取", true);
  251. TimeSet = new RelayCommand(() =>
  252. {
  253. GVL_SmallStation.GetInstance.Time = time;
  254. MessageNotify.GetInstance.ShowUserLog($"设置柔性味魔方复位时间:{time}s");
  255. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{time.ToString()}:设置成功!");
  256. });
  257. SiemensIsConnect = ProcessControl.GetInstance.SiemensDevice.IsConnected;
  258. HKPlcIsConnect = ProcessControl.GetInstance.HKDevice.IsConnected;
  259. WindSendIsConnect = ProcessControl.GetInstance.WindSendDevice.IsConnected;
  260. }
  261. public RelayCommand Test1Command { get; set; }
  262. public RelayCommand Test2Command { get; set; }
  263. public RelayCommand Test3Command { get; set; }
  264. public RelayCommand Test4Command { get; set; }
  265. public RelayCommand Test5Command { get; set; }
  266. public RelayCommand Test6Command { get; set; }
  267. public RelayCommand TimeSet { get; set; }
  268. public static bool Heartbeat { get { return _mHeartbeat; } set { _mHeartbeat = value; OnStaticPropertyChanged(); } }
  269. private static bool _mHeartbeat;
  270. public int time { get { return _mtime; } set { _mtime = value; OnStaticPropertyChanged(); } }
  271. private int _mtime;
  272. public static string OrderStatus { get { return _mOrderStatus; } set { _mOrderStatus = value; OnStaticPropertyChanged(); } }
  273. private static string _mOrderStatus = "无意义";
  274. public static string Recipe1DosingStatus { get { return _mRecipe1DosingStatus; } set { _mRecipe1DosingStatus = value; OnStaticPropertyChanged(); } }
  275. private static string _mRecipe1DosingStatus = "无意义";
  276. public static string Recipe2DosingStatus { get { return _mRecipe2DosingStatus; } set { _mRecipe2DosingStatus = value; OnStaticPropertyChanged(); } }
  277. private static string _mRecipe2DosingStatus = "无意义";
  278. public static string Recipe3DosingStatus { get { return _mRecipe3DosingStatus; } set { _mRecipe3DosingStatus = value; OnStaticPropertyChanged(); } }
  279. private static string _mRecipe3DosingStatus = "无意义";
  280. public static string Recipe4DosingStatus { get { return _mRecipe4DosingStatus; } set { _mRecipe4DosingStatus = value; OnStaticPropertyChanged(); } }
  281. private static string _mRecipe4DosingStatus = "无意义";
  282. public static string Recipe5DosingStatus { get { return _mRecipe5DosingStatus; } set { _mRecipe5DosingStatus = value; OnStaticPropertyChanged(); } }
  283. private static string _mRecipe5DosingStatus = "无意义";
  284. public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
  285. public static void OnStaticPropertyChanged([CallerMemberName] string PropName = "")
  286. {
  287. StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName));
  288. }
  289. public RelayCommand CLearRecipeInfo { get; set; }
  290. public RelayCommand SystemReset { get; set; }
  291. public RelayCommand BPAResetCommand { get; set; }
  292. private bool _SiemensIsConnect { get; set; }
  293. public bool SiemensIsConnect { get { return _SiemensIsConnect; } set { _SiemensIsConnect = value; OnPropertyChanged(); } }
  294. private bool _HKPlcIsConnect { get; set; }
  295. public bool HKPlcIsConnect { get { return _HKPlcIsConnect; } set { _HKPlcIsConnect = value; OnPropertyChanged(); } }
  296. private bool _WindSendIsConnect { get; set; }
  297. public bool WindSendIsConnect { get { return _WindSendIsConnect; } set { _WindSendIsConnect = value; OnPropertyChanged(); } }
  298. private static string _Recipe1DosingComplete { get; set; }
  299. public static string Recipe1DosingComplete { get { return _Recipe1DosingComplete; } set { _Recipe1DosingComplete = value; OnStaticPropertyChanged(); } }
  300. private static string _Recipe2DosingComplete { get; set; }
  301. public static string Recipe2DosingComplete { get { return _Recipe2DosingComplete; } set { _Recipe2DosingComplete = value; OnStaticPropertyChanged(); } }
  302. private static string _Recipe3DosingComplete { get; set; }
  303. public static string Recipe3DosingComplete { get { return _Recipe3DosingComplete; } set { _Recipe3DosingComplete = value; OnStaticPropertyChanged(); } }
  304. private static string _Recipe4DosingComplete { get; set; }
  305. public static string Recipe4DosingComplete { get { return _Recipe4DosingComplete; } set { _Recipe4DosingComplete = value; OnStaticPropertyChanged(); } }
  306. private static string _Recipe5DosingComplete { get; set; }
  307. public static string Recipe5DosingComplete { get { return _Recipe5DosingComplete; } set { _Recipe5DosingComplete = value; OnStaticPropertyChanged(); } }
  308. public RelayCommand StockbinDosingComple { get; set; }
  309. public RelayCommand StockbinDosingCompleClear { get; set; }
  310. private static int _StockbinDosingCompleNum { get; set; }
  311. public static int StockbinDosingCompleNum { get { return _StockbinDosingCompleNum; } set { _StockbinDosingCompleNum = value; OnStaticPropertyChanged(); } }
  312. public static Visibility VisibilityBtn1 { get { return _VisibilityBtn1; } set { _VisibilityBtn1 = value; OnStaticPropertyChanged(); } }
  313. private static Visibility _VisibilityBtn1 = Visibility.Visible;
  314. public static Visibility VisibilityBtn2 { get { return _VisibilityBtn2; } set { _VisibilityBtn2 = value; OnStaticPropertyChanged(); } }
  315. private static Visibility _VisibilityBtn2 = Visibility.Hidden;
  316. public static Visibility VisibilityBtn3 { get { return _VisibilityBtn3; } set { _VisibilityBtn3 = value; OnStaticPropertyChanged(); } }
  317. private static Visibility _VisibilityBtn3 = Visibility.Hidden;
  318. }
  319. }