终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

1282 líneas
72 KiB

  1. using BPA.Communication;
  2. using BPASmartClient.CustomResource.Pages.Model;
  3. using BPASmartClient.FoodStationTest.Model.GVL;
  4. using BPASmartClient.FoodStationTest.Model.HK_PLC;
  5. using BPASmartClient.FoodStationTest.Model.RawMaterial;
  6. using BPA.Helper;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Printing;
  13. using System.Reflection;
  14. using System.Threading;
  15. namespace BPASmartClient.FoodStationTest.Model
  16. {
  17. public class ProcessControl
  18. {
  19. private static volatile ProcessControl _Instance;
  20. public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
  21. private ProcessControl()
  22. { }
  23. /// <summary>
  24. /// 配方数据
  25. /// </summary>
  26. public ObservableCollection<RemoteRecipeData> RemoteRecipes = new ObservableCollection<RemoteRecipeData>();
  27. /// <summary>
  28. /// 原料的名称和料仓的位置对应
  29. /// </summary>
  30. public Dictionary<string, short> RawMaterialsNamePos = new Dictionary<string, short>();
  31. public ObservableCollection<RawMaterialStockBin> RawMaterialsInfo => Json<DevicePar>.Data.rawMaterialStockBin;
  32. /// <summary>
  33. /// 配方队列
  34. /// </summary>
  35. public ConcurrentQueue<string> RecipeQueueTray1 = new ConcurrentQueue<string>();
  36. /// <summary>
  37. /// 物料集合
  38. /// </summary>
  39. public Dictionary<int, ConcurrentQueue<string>> RecipeQueueTray { get; set; } = new Dictionary<int, ConcurrentQueue<string>>();
  40. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  41. public ObservableCollection<PlcInfos> CommData { get; set; } = new ObservableCollection<PlcInfos>();
  42. public ObservableCollection<PlcInfos> ProcessVar { get; set; } = new ObservableCollection<PlcInfos>();
  43. public DateTime StockBinAlarmTime = DateTime.Now;
  44. public string? HK_PLC_IP => Json<LocalPar>.Data.HK_PLC_IP;
  45. public void Init()
  46. {
  47. //初始化物料集合。
  48. for (int i = 0; i < 5; i++)
  49. {
  50. RecipeQueueTray.TryAdd(i, new ConcurrentQueue<string>());
  51. }
  52. PlcVarMonitor();
  53. StockBinNameWithPos();
  54. RawMaterialNameWithCode();
  55. RegisterInit();
  56. DeviceConnect();
  57. //Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
  58. TaskManage.GetInstance.StartLong(new Action(() =>
  59. {
  60. GVL_SmallStation.GetInstance.DisEnableStockAlarm = Json<DevicePar>.Data.deviceConnectPar.ShieldStockbinAlarm;
  61. if (HKDevice.IsConnected)
  62. {
  63. GVL_SmallStation.GetInstance.HeartBeatToPlc = !GVL_SmallStation.GetInstance.HeartBeatToPlc;
  64. HKDevice.HK_PLC_S7.Write("DB4.DBX0.0", GVL_SmallStation.GetInstance.HeartBeatToPlc);
  65. GVL_SmallStation.GetInstance.HeartBeatFromPlc = HKDevice.HK_PLC_S7.Read<bool>("DB45.DBX0.0").Content;
  66. if (DeviceInquire.GetInstance.devices.Count < Json<LocalPar>.Data.RawMaterialDeviceNum && HKDevice.IsConnected
  67. && Json<RemoteRecipeDataColl>.Data.Recipes.Count > 0 && GVL_SmallStation.GetInstance.DisEnableStockBinAlarm == false
  68. && DateTime.Now.Subtract(StockBinAlarmTime).TotalSeconds >= 60 & !GVL_SmallStation.GetInstance.DisEnableStockAlarm)
  69. {
  70. HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", true);
  71. App.Current.Dispatcher.Invoke(() =>
  72. {
  73. MessageNotify.GetInstance.ShowDialog($"未读取到全部柔性味魔方料仓。", DialogType.Error);
  74. StockBinAlarmTime = DateTime.Now;
  75. });
  76. HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", false);
  77. }
  78. }
  79. Thread.Sleep(200);
  80. }), "海科plc通信心跳", true);
  81. TaskManage.GetInstance.StartLong(new Action(() =>
  82. {
  83. if (GVL_SmallStation.GetInstance.Order_Cancel)
  84. {
  85. CancelOrder();//订单取消,不执行配方流程
  86. }
  87. else
  88. {
  89. ReceviceData();//配方请求
  90. RecipeInfoToHKPLC();//配方配料
  91. }
  92. Thread.Sleep(10);
  93. }), "小料站流程控制", true);
  94. TaskManage.GetInstance.StartLong(new Action(() =>
  95. {
  96. RealTimeData();
  97. Thread.Sleep(10);
  98. }), "西门子PLC和小料站PLC的实时数据交互流程", true);
  99. TaskManage.GetInstance.StartLong(new Action(() =>
  100. {
  101. HKPlcRead();
  102. GetStatus();
  103. Thread.Sleep(10);
  104. }), "海科PLC实时数据", true);
  105. }
  106. /// <summary>
  107. /// 气缸的传感器值
  108. /// </summary>
  109. private void GetStatus()
  110. {
  111. for (int i = 0; i < 8; i++)
  112. {
  113. GVL_SmallStation.GetInstance.Cylinder_JackInfo[i] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX0." + i).Content;
  114. }
  115. for (int i = 0; i < 7; i++)
  116. {
  117. GVL_SmallStation.GetInstance.Cylinder_JackInfo[i + 8] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX1." + i).Content;
  118. }
  119. GVL_SmallStation.GetInstance.Cylinder_JackInfo[20] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX3.6").Content;//进料桶气缸
  120. GVL_SmallStation.GetInstance.Cylinder_JackInfo[21] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX3.7").Content;//出料筒气缸1
  121. GVL_SmallStation.GetInstance.Cylinder_JackInfo[22] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.0").Content;//出料筒气缸2
  122. GVL_SmallStation.GetInstance.Cylinder_JackInfo[23] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.1").Content;//出料筒气缸3
  123. GVL_SmallStation.GetInstance.Cylinder_JackInfo[24] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.2").Content;//托盘1_1气缸
  124. GVL_SmallStation.GetInstance.Cylinder_JackInfo[25] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.3").Content;//托盘1_2气缸
  125. GVL_SmallStation.GetInstance.Cylinder_JackInfo[26] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.4").Content;//托盘2_1气缸
  126. GVL_SmallStation.GetInstance.Cylinder_JackInfo[27] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.5").Content;//托盘2_2气缸
  127. }
  128. /// <summary>
  129. /// DB块的变量实时值
  130. /// </summary>
  131. private void HKPlcRead()
  132. {
  133. if (HKDevice.IsConnected)
  134. {
  135. foreach (PropertyInfo item in typeof(PlcReadAddressDB3).GetProperties())
  136. {
  137. int index = Array.FindIndex(CommData.ToArray(), p => p.Name == item.Name);
  138. if (index >= 0)
  139. {
  140. if (item.PropertyType.IsArray)
  141. {
  142. CommData.ElementAt(index).Value = "";
  143. Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null);
  144. foreach (var values in array)
  145. {
  146. string data = values.ToString();
  147. if (data.ToLower() == "false")
  148. data = "0";
  149. if (data.ToLower() == "true")
  150. data = "1";
  151. CommData.ElementAt(index).Value = CommData.ElementAt(index).Value + data + ",";
  152. }
  153. }
  154. else
  155. {
  156. CommData.ElementAt(index).Value = GVL_SmallStation.GetInstance.plcReadDataDB3.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null).ToString();
  157. }
  158. }
  159. }
  160. }
  161. foreach (PropertyInfo item in typeof(GVL_SmallStation).GetProperties())
  162. {
  163. int index = Array.FindIndex(ProcessVar.ToArray(), p => p.Name == item.Name);
  164. if (index >= 0)
  165. {
  166. if (item.PropertyType.IsArray)
  167. {
  168. ProcessVar.ElementAt(index).Value = "";
  169. Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance, null);
  170. foreach (var values in array)
  171. {
  172. string data = values.ToString();
  173. if (data.ToLower() == "false")
  174. data = "0";
  175. if (data.ToLower() == "true")
  176. data = "1";
  177. ProcessVar.ElementAt(index).Value = ProcessVar.ElementAt(index).Value + data + ",";
  178. }
  179. }
  180. else
  181. {
  182. ProcessVar.ElementAt(index).Value = GVL_SmallStation.GetInstance.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance, null).ToString();
  183. }
  184. }
  185. }
  186. }
  187. /// <summary>
  188. /// 小料站和西门子PLC之间的实时数据
  189. /// </summary>
  190. private void RealTimeData()
  191. {
  192. if (HKDevice.IsConnected)
  193. {
  194. //获取系统状态
  195. GVL_SmallStation.GetInstance.PlcSystemIsAutoRun = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.0").Content;//系统启停
  196. GVL_SmallStation.GetInstance.PlcSystemMode = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.1").Content;//系统模式
  197. GVL_SmallStation.GetInstance.PlcSystemIsPause = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.2").Content;//系统暂停
  198. GVL_SmallStation.GetInstance.Station1HaveTray = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.0").Content;//工站1 有货架
  199. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[0] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.0").Content;
  200. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[1] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.1").Content;
  201. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[2] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.2").Content;
  202. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[3] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.3").Content;
  203. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[4] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.4").Content;
  204. if (GVL_SmallStation.GetInstance.WindSendDosingComple)
  205. {
  206. HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX4.0", true);
  207. GVL_SmallStation.GetInstance.WindSendDosingComple = false;
  208. MessageNotify.GetInstance.ShowRunLog("风送配料完成信号,发给产线plc信号");
  209. }
  210. if (Json<RemoteRecipeDataColl>.Data.Recipes.Count <= 3)
  211. {
  212. GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe = true;
  213. }
  214. GVL_SmallStation.GetInstance.Station1Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.1").Content;
  215. GVL_SmallStation.GetInstance.Station1Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.2").Content;
  216. GVL_SmallStation.GetInstance.RobotStatus = HKDevice.HK_PLC_S7.Read<byte>("DB3.DBB0").Content;
  217. GVL_SmallStation.GetInstance.RobotProgramNum = HKDevice.HK_PLC_S7.Read<byte>("DB3.DBB1").Content;
  218. }
  219. }
  220. public void CancelOrder()
  221. {
  222. if (GVL_SmallStation.GetInstance.Order_Cancel) //订单取消
  223. {
  224. if (!string.IsNullOrEmpty(GVL_SmallStation.GetInstance.Order_CancelRecipeCode))
  225. {
  226. string code = GVL_SmallStation.GetInstance.Order_CancelRecipeCode;
  227. int index = Array.FindIndex(Json<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == code);
  228. int[] cnt = new int[5] { -1, -1, -1, -1, -1 };
  229. int index1 = -1;
  230. for (int i = 0; i < 5; i++)
  231. {
  232. cnt[i] = Array.FindIndex(RecipeQueueTray[i].ToArray(), p => p == code);
  233. if (cnt[i] >= 0)
  234. {
  235. index1 = i;
  236. }
  237. }
  238. switch (GVL_SmallStation.GetInstance.OrderCancelStep)
  239. {
  240. case 0://前提条件判断
  241. if (index == -1)
  242. {
  243. GVL_SmallStation.GetInstance.OrderCancelStep = 30;
  244. MessageNotify.GetInstance.ShowRunLog($"配方中并未找到订单{code}");
  245. }
  246. else
  247. {
  248. if (index1 >= 0)
  249. {
  250. GVL_SmallStation.GetInstance.OrderCancelStep = 1;
  251. }
  252. else
  253. {
  254. GVL_SmallStation.GetInstance.OrderCancelStep = 20;
  255. }
  256. }
  257. break;
  258. //Case 1-9为
  259. case 1:
  260. if (GVL_SmallStation.GetInstance.RecipeProcessStatus[index] != 0)
  261. {
  262. GVL_SmallStation.GetInstance.RecipeProcessStatus[index] = 0;
  263. HKDevice.HK_PLC_S7.Write("DB4.DBX6." + index1, true);
  264. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,正在取消订单:{code}");
  265. GVL_SmallStation.GetInstance.OrderCancelStep = 2;
  266. }
  267. else
  268. {
  269. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
  270. GVL_SmallStation.GetInstance.OrderCancelStep = 3;
  271. }
  272. break;
  273. case 2:
  274. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX42." + index1).Content)
  275. {
  276. if (GVL_SmallStation.GetInstance.Station1Cylinder == false)
  277. {
  278. GVL_SmallStation.GetInstance.OrderCancelStep = 3;
  279. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
  280. }
  281. }
  282. break;
  283. case 3:
  284. // SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", true);
  285. GVL_SmallStation.GetInstance.OrderCancelStep = 4;
  286. break;
  287. case 4:
  288. // SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", false);
  289. GVL_SmallStation.GetInstance.OrderCancelStep = 9;
  290. MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
  291. break;
  292. case 9:
  293. App.Current.Dispatcher.Invoke(() =>
  294. {
  295. Json<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);
  296. });
  297. RecipeQueueTray1.TryDequeue(out code);
  298. GVL_SmallStation.GetInstance.RecipeProcessStatus[index] = 0;
  299. GVL_SmallStation.GetInstance.Order_Cancel = false;
  300. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
  301. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  302. break;
  303. case 20:
  304. GVL_SmallStation.GetInstance.OrderCancelStep = 21;
  305. break;
  306. case 21:
  307. GVL_SmallStation.GetInstance.OrderCancelStep = 29;
  308. MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
  309. break;
  310. case 29:
  311. App.Current.Dispatcher.Invoke(() =>
  312. {
  313. Json<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);
  314. });
  315. GVL_SmallStation.GetInstance.Order_Cancel = false;
  316. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
  317. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
  318. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  319. break;
  320. //30-39为订单还未下发至上位机
  321. case 30:
  322. GVL_SmallStation.GetInstance.OrderCancelStep = 31;
  323. break;
  324. case 31:
  325. GVL_SmallStation.GetInstance.OrderCancelStep = 39;
  326. MessageNotify.GetInstance.ShowRunLog($"西门子取消订单完成,订单号:{code}");
  327. break;
  328. case 39:
  329. GVL_SmallStation.GetInstance.Order_Cancel = false;
  330. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
  331. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  332. break;
  333. }
  334. }
  335. }
  336. }
  337. /// <summary>
  338. /// 将配方添加到配方队列中
  339. /// </summary>
  340. private void ReceviceData()
  341. {
  342. RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  343. if (RemoteRecipes.Count > 0)
  344. {
  345. foreach (var data in RemoteRecipes)
  346. {
  347. if (data.TrayCode == 1)
  348. {
  349. for (int i = 0; i < 5; i++)
  350. {
  351. if (GVL_SmallStation.GetInstance.NotUseSmallStation)
  352. {
  353. //查询都不包含此配方
  354. if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
  355. {
  356. RecipeQueueTray[i].Enqueue(data.RecipeCode);
  357. MessageNotify.GetInstance.ShowRunLog($"本地配方配料 ,不使用小料配料,配方{data.RecipeCode},加入配方{i}");
  358. }
  359. }
  360. else if (GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[i])
  361. {
  362. if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
  363. {
  364. RecipeQueueTray[i].Enqueue(data.RecipeCode);
  365. MessageNotify.GetInstance.ShowRunLog($"本地配方配料 ,等待plc允许配料,配方{data.RecipeCode},加入配方{i}");
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. else
  373. {
  374. for (int i = 0; i < 5; i++)
  375. {
  376. RecipeQueueTray[i].Clear();
  377. GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0;
  378. }
  379. GVL_SmallStation.GetInstance.WindSendDosingStatus = 0;
  380. GVL_SmallStation.GetInstance.WindSendDosing = false;
  381. }
  382. }
  383. /// <summary>
  384. /// 小料站配料
  385. /// </summary>
  386. private void RecipeInfoToHKPLC()
  387. {
  388. if (!GVL_SmallStation.GetInstance.NotUseSmallStation)
  389. {
  390. //如果使用小料站配料,更新查询5个工位的AGV状态。
  391. for (int i = 0; i < 5; i++)
  392. {
  393. switch (GVL_SmallStation.GetInstance.Tray_AGVLogic[i])
  394. {
  395. case 0:
  396. if (GVL_SmallStation.GetInstance.AGV_PutTray1Finish && (RecipeQueueTray[i].Count > 0) && GVL_SmallStation.GetInstance.AGVIsGetTray == false)
  397. {
  398. GVL_SmallStation.GetInstance.AGVIsGetTray = true;
  399. HKDevice.HK_PLC_S7.Write("DB4.DBX8." + i, true);
  400. GVL_SmallStation.GetInstance.AGV_PutTray1Finish = false;
  401. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 1;
  402. MessageNotify.GetInstance.ShowRunLog("AGV到位 发送到位信号给plc");
  403. }
  404. break;
  405. case 1:
  406. if (GVL_SmallStation.GetInstance.Station1HaveTray)
  407. {
  408. HKDevice.HK_PLC_S7.Write("DB4.DBX8." + i, false);
  409. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 2;
  410. MessageNotify.GetInstance.ShowRunLog("托盘1有货架");
  411. }
  412. break;
  413. case 2:
  414. if (GVL_SmallStation.GetInstance.AGV_GetTray1Finish && GVL_SmallStation.GetInstance.RecipeProcessStatus[i] == 0)
  415. {
  416. GVL_SmallStation.GetInstance.AGVIsGetTray = false;
  417. HKDevice.HK_PLC_S7.Write("DB4.DBX10." + i, true);
  418. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 3;
  419. MessageNotify.GetInstance.ShowRunLog("AGV取托盘1完成,发送给海科信号后1s后复位");
  420. }
  421. break;
  422. case 3:
  423. if (HKDevice.HK_PLC_S7.Read<bool>("DB4.DBX10." + i).Content)
  424. {
  425. Thread.Sleep(1000);
  426. HKDevice.HK_PLC_S7.Write("DB4.DBX10." + i, false);
  427. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 0;
  428. GVL_SmallStation.GetInstance.AGV_GetTray1Finish = false;
  429. MessageNotify.GetInstance.ShowRunLog("AGV取托盘1完成,信号复位");
  430. }
  431. break;
  432. default:
  433. break;
  434. }
  435. }
  436. }
  437. foreach (var recipe in RecipeQueueTray)
  438. {
  439. int recipeNum = recipe.Key;
  440. if (RecipeQueueTray[recipeNum].Count > 0)
  441. {
  442. int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueueTray[recipeNum].ElementAt(0));
  443. if (index >= 0 && index < RemoteRecipes.Count)
  444. {
  445. string code = RemoteRecipes.ElementAt(index).RecipeCode;
  446. int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
  447. string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
  448. string windSend = RemoteRecipes.ElementAt(index).ToString();
  449. if (trayCode == 1)
  450. {
  451. if (GVL_SmallStation.GetInstance.NotUseSmallStation)
  452. {
  453. if (GVL_SmallStation.GetInstance.AGV_PutTray1Finish)
  454. {
  455. Thread.Sleep(5000);
  456. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  457. if (/*SiemensDevice.IsConnected &&*/ !GVL_SmallStation.GetInstance.IsUseLocalRecipe)
  458. {
  459. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据反馈给西门子");
  460. }
  461. else
  462. {
  463. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据无法反馈给西门子,西门子设备未连接或处于本地配方");
  464. }
  465. GVL_SmallStation.GetInstance.WindSendDosing = false;
  466. App.Current.Dispatcher.Invoke(() =>
  467. {
  468. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  469. });
  470. RecipeQueueTray[recipeNum].TryDequeue(out code);
  471. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
  472. GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0;
  473. }
  474. }
  475. else
  476. {
  477. //粉料仓下发配方并配料。
  478. if (/*GVL_SmallStation.GetInstance.IsUseWindSend &&*/ GVL_SmallStation.GetInstance.WindSendDosing == false /*&& GVL_SmallStation.GetInstance.Tray_AGVLogic[recipeNum] == 2*/)
  479. {
  480. }
  481. else
  482. {
  483. if (Delay.GetInstance("delayTime").Start(true, 60))
  484. {
  485. Delay.GetInstance("delayTime").Start(false, 60);
  486. MessageNotify.GetInstance.ShowRunLog($"风送设备PLC未连接");
  487. }
  488. }
  489. }
  490. //上位机下发配方。并检测下发完成。
  491. if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 0)
  492. {
  493. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
  494. HKDevice.IssueRecipeToPlc(RemoteRecipes.ElementAt(index).RawMaterial, recipeNum);
  495. HKDevice.HK_PLC_S7.Write("DB4.DBX2." + recipeNum, true);
  496. GVL_SmallStation.GetInstance.DosingTime[recipeNum] = DateTime.Now;
  497. GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 1;
  498. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号{code},配方号{recipeNum + 1},下发完成");
  499. }
  500. //需要等待下位机检测确认正确接收到配方。
  501. bool recipeReceviceFinish = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX4." + recipeNum).Content;
  502. if (recipeReceviceFinish && GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 1)
  503. {
  504. HKDevice.HK_PLC_S7.Write("DB4.DBX2." + recipeNum, false);
  505. GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 2;
  506. GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = 0;
  507. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号{code},配方号{recipeNum + 1},配方接收完成");
  508. }
  509. //下面是配料流程。
  510. if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 2)
  511. {
  512. //下面是味魔方配料。
  513. for (byte i = 1; i <= Json<LocalPar>.Data.RawMaterialDeviceNum; i++)
  514. {
  515. int indexArr = -1;
  516. //获取配方每个配方的三个桶的位置。
  517. if (GVL_SmallStation.GetInstance.plcReadDataDB3.StockBinAllowIssue[i - 1])
  518. {
  519. switch (recipeNum)
  520. {
  521. case 0:
  522. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe1BarrelPosReserve.ToArray(), p => p == i);
  523. break;
  524. case 1:
  525. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe2BarrelPosReserve.ToArray(), p => p == i);
  526. break;
  527. case 2:
  528. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe3BarrelPosReserve.ToArray(), p => p == i);
  529. break;
  530. case 3:
  531. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe4BarrelPosReserve.ToArray(), p => p == i);
  532. break;
  533. case 4:
  534. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe5BarrelPosReserve.ToArray(), p => p == i);
  535. break;
  536. }
  537. if (indexArr >= 0 && GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].GetBitValue((byte)i) == false)
  538. {
  539. //查找每个料仓对应的重量。
  540. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  541. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight * 1000;//单位g转换kg
  542. //小于等于0代表这个料仓不需要配料。
  543. if (weight <= 0)
  544. {
  545. if (i >= 1 && i <= 8)
  546. {
  547. string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX12." + (i - 1), true).IsSuccess.ToString();
  548. MessageNotify.GetInstance.ShowRunLog(commInfo);
  549. }
  550. else if (i >= 9 && i <= 15)
  551. {
  552. string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX13." + (i - 9), true).IsSuccess.ToString();
  553. MessageNotify.GetInstance.ShowRunLog(commInfo1);
  554. }
  555. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].SetBitValue((byte)i, false);//配料完成设备写成false
  556. GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].SetBitValue((byte)i, true);//配料完成设备写成false
  557. }
  558. //写入重量并开始配料
  559. else
  560. {
  561. if (loc_index >= 0)
  562. {
  563. DeviceInquire.GetInstance.GetDevice((int)i)?.Start(weight);//根据料仓编号 启动并写入每个原料重量
  564. GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].SetBitValue((byte)i, true);//配料完成设备写成false
  565. }
  566. else
  567. {
  568. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号:{code},配方号{recipeNum + 1},{indexArr + 1}号桶,错误没有找到{(int)i}号仓的配方");
  569. }
  570. }
  571. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号:{code},配方号{recipeNum + 1},{indexArr + 1}号桶,{(int)i}号仓,正在配料");
  572. }
  573. else
  574. {
  575. //MessageNotify.GetInstance.ShowRunLog($"错误,有允许配料信号,但没有相应的位置 和桶号");
  576. }
  577. if ((DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3) && indexArr >= 0 && GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].GetBitValue((byte)i))
  578. {
  579. //配料完成处理。
  580. int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  581. if (res < 0)
  582. {
  583. }
  584. else
  585. {
  586. Thread.Sleep(GVL_SmallStation.GetInstance.Time);
  587. RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.NowWeightFeedback;
  588. bool info = DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  589. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,配料完成,下料完成重量:{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight}");
  590. //查找配料完成的味魔方的报警偏差限值。
  591. float AlarmRange = Math.Abs(RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight - RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).RawMaterialWeight * 1000);
  592. int iIndex = Array.FindIndex(Json<DevicePar>.Data.deviceParModels.ToArray(), p => p.MaterialName == DeviceInquire.GetInstance.GetDevice(i).DeviceName);
  593. if (iIndex >= 0)
  594. {
  595. //如果偏差过大则报警。
  596. if (Math.Abs(Json<DevicePar>.Data.deviceParModels.ElementAt(iIndex).ErrorRange) < AlarmRange)
  597. {
  598. HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", true);
  599. App.Current.Dispatcher.Invoke(() =>
  600. {
  601. MessageNotify.GetInstance.ShowDialog($"{i}号仓配料误差过大,设置出料重量{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).RawMaterialWeight * 1000}g,实际出料重量{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight}g,相差{AlarmRange}g,允许误差为{Math.Abs(Json<DevicePar>.Data.deviceParModels.ElementAt(iIndex).ErrorRange)}g,请联系人工处理", DialogType.Warning);
  602. HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", false);
  603. });
  604. }
  605. }
  606. //对海科PLC写入味魔方配料完成。
  607. if (i >= 1 && i <= 8)
  608. {
  609. string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX12." + (i - 1), true).IsSuccess.ToString();
  610. MessageNotify.GetInstance.ShowRunLog(commInfo);
  611. }
  612. else if (i >= 9 && i <= 15)
  613. {
  614. string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX13." + (i - 9), true).IsSuccess.ToString();
  615. MessageNotify.GetInstance.ShowRunLog(commInfo1);
  616. }
  617. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].SetBitValue((byte)i, false);//配料完成设备写成false
  618. MessageNotify.GetInstance.ShowRunLog($"配方{recipeNum},{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].ToBinString()}");
  619. }
  620. }
  621. }
  622. }
  623. //配方整体配料完成处理。
  624. bool DosingComple = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX6." + recipeNum).Content;
  625. if ((RTrig.GetInstance("配方配料完成").Start(DosingComple)) || (GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] > 0 && DosingComple))
  626. {
  627. //配方制作完成数量+1
  628. GVL_SmallStation.GetInstance.RecipeDosingCompleNum = GVL_SmallStation.GetInstance.RecipeDosingCompleNum + 1;
  629. GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = 0;
  630. if (GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] > 0)
  631. {
  632. for (int i = 1; i < 17; i++)
  633. {
  634. if (GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].GetBitValue((byte)i))
  635. {
  636. MessageNotify.GetInstance.ShowRunLog($"料仓配料完成,但存在料仓未配料:{i}号仓");
  637. }
  638. }
  639. }
  640. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  641. double a = DateTime.Now.Subtract(GVL_SmallStation.GetInstance.DosingTime[recipeNum]).TotalSeconds;
  642. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  643. {
  644. MessageNotify.GetInstance.ShowRunLog($"{item.RawMaterialName},下料重量:{item.Laying_Off_Weight}g");
  645. }
  646. GVL_SmallStation.GetInstance.WindSendDosing = false;
  647. //移除配方。
  648. App.Current.Dispatcher.Invoke(() =>
  649. {
  650. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  651. });
  652. RecipeQueueTray[recipeNum].TryDequeue(out code);
  653. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
  654. GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0;
  655. }
  656. }
  657. }
  658. }
  659. }
  660. }
  661. }
  662. /// <summary>
  663. /// 复位所有料仓。
  664. /// </summary>
  665. private void StockBinInit()
  666. {
  667. for (int i = 1; i <= Json<LocalPar>.Data.RawMaterialDeviceNum; i++)
  668. {
  669. if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)
  670. {
  671. DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  672. }
  673. }
  674. }
  675. /// <summary>
  676. /// 料仓的位置和原料名称的对应
  677. /// </summary>
  678. public void StockBinNameWithPos()
  679. {
  680. RawMaterialsNamePos.Clear();
  681. foreach (var material in RawMaterialsInfo)
  682. {
  683. if (!string.IsNullOrEmpty(material.RawMaterialName))
  684. {
  685. if (!RawMaterialsNamePos.ContainsKey(material.RawMaterialName))
  686. {
  687. RawMaterialsNamePos.Add(material.RawMaterialName, (short)material.RawMaterialLocation);
  688. }
  689. }
  690. }
  691. }
  692. /// <summary>
  693. /// PLC的DB3变量列表。初始化PLC读取DB块变量以及流程变量数据。
  694. /// </summary>
  695. public void PlcVarMonitor()
  696. {
  697. foreach (PropertyInfo item in typeof(PlcReadAddressDB3).GetProperties())
  698. {
  699. if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
  700. {
  701. string type = item.PropertyType.ToString();
  702. CommData.Add(new PlcInfos()
  703. {
  704. Count = CommData.Count + 1,
  705. Name = item.Name,
  706. Address = item.GetCustomAttribute<VarCommAttribute>().Address,
  707. Type = type.Substring(type.IndexOf(".") + 1),
  708. Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
  709. Value = item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3).ToString(),
  710. });
  711. }
  712. }
  713. foreach (PropertyInfo item in typeof(GVL_SmallStation).GetProperties())
  714. {
  715. if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
  716. {
  717. string type = item.PropertyType.ToString();
  718. ProcessVar.Add(new PlcInfos()
  719. {
  720. Count = ProcessVar.Count + 1,
  721. Name = item.Name,
  722. Type = type.Substring(type.IndexOf(".") + 1),
  723. Address = item.GetCustomAttribute<VarCommAttribute>().Address,
  724. Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
  725. Value = item.GetValue(GVL_SmallStation.GetInstance).ToString()
  726. });
  727. }
  728. }
  729. }
  730. /// <summary>
  731. /// 注册需要用到的委托,主要是用于手动控制的。
  732. /// </summary>
  733. public void RegisterInit()
  734. {
  735. //手动控制气缸 DB5.DBX0.0~DB5.DBX4.5
  736. ActionManage.GetInstance.Register(new Action<object>((o) =>
  737. {
  738. if (o != null)
  739. {
  740. if (o.ToString().Contains("升降气缸"))
  741. {
  742. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
  743. if (index >= 1 && index <= 15)
  744. {
  745. string address = "DB5.DBX" + (index / 8) + "." + (index % 8 - 1);
  746. if (index == 8)
  747. address = "DB5.DBX0.7";
  748. HKDevice.HK_PLC_S7.Write<bool>(address, true);
  749. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:{address},值:true");
  750. }
  751. }
  752. else if (o.ToString().Contains("阻挡气缸"))
  753. {
  754. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
  755. if (index >= 1 && index <= 15)
  756. {
  757. string address = "";
  758. if (index == 1)
  759. address = "DB5.DBX1.7";
  760. if (index == 2)
  761. address = "DB5.DBX2.0";
  762. if (index == 3)
  763. address = "DB5.DBX2.1";
  764. if (index == 4)
  765. address = "DB5.DBX2.2";
  766. if (index == 5)
  767. address = "DB5.DBX2.3";
  768. if (index == 6)
  769. address = "DB5.DBX2.4";
  770. if (index == 7)
  771. address = "DB5.DBX2.5";
  772. if (index == 8)
  773. address = "DB5.DBX2.6";
  774. if (index == 9)
  775. address = "DB5.DBX2.7";
  776. if (index == 10)
  777. address = "DB5.DBX3.0";
  778. if (index == 11)
  779. address = "DB5.DBX3.1";
  780. if (index == 12)
  781. address = "DB5.DBX3.2";
  782. if (index == 13)
  783. address = "DB5.DBX3.3";
  784. if (index == 14)
  785. address = "DB5.DBX3.4";
  786. if (index == 15)
  787. address = "DB5.DBX3.5";
  788. HKDevice.HK_PLC_S7.Write<bool>(address, true);
  789. }
  790. }
  791. else if (o.ToString().Contains("进料桶顶升气缸"))
  792. {
  793. HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", false);//默认顶升
  794. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.6,值:false");
  795. }
  796. else if (o.ToString().Contains("出料桶顶升气缸1"))
  797. {
  798. HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", true);
  799. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.7,值:true");
  800. }
  801. else if (o.ToString().Contains("出料桶顶升气缸2"))
  802. {
  803. HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", true);
  804. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.0,值:true");
  805. }
  806. else if (o.ToString().Contains("出料桶顶升气缸3"))
  807. {
  808. HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", true);
  809. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.1,值:true");
  810. }
  811. else if (o.ToString().Contains("托盘气缸1_1"))
  812. {
  813. HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", false);//默认伸出
  814. }
  815. else if (o.ToString().Contains("托盘气缸1_2"))
  816. {
  817. HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", false);
  818. }
  819. else if (o.ToString().Contains("托盘气缸2_1"))
  820. {
  821. HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", false);
  822. }
  823. else if (o.ToString().Contains("托盘气缸2_2"))
  824. {
  825. HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", false);
  826. }
  827. }
  828. }), "ManualOpen", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  829. ActionManage.GetInstance.Register(new Action<object>((o) =>
  830. {
  831. if (o != null)
  832. {
  833. if (o.ToString().Contains("升降气缸"))
  834. {
  835. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
  836. if (index >= 1 && index <= 15)
  837. {
  838. string address = "DB5.DBX" + (index / 8) + "." + (index % 8 - 1);
  839. if (index == 8)
  840. address = "DB5.DBX0.7";
  841. HKDevice.HK_PLC_S7.Write<bool>(address, false);
  842. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:{address},值:false");
  843. }
  844. }
  845. else if (o.ToString().Contains("阻挡气缸"))
  846. {
  847. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
  848. if (index >= 1 && index <= 15)
  849. {
  850. string address = "";
  851. if (index == 1)
  852. address = "DB5.DBX1.7";
  853. if (index == 2)
  854. address = "DB5.DBX2.0";
  855. if (index == 3)
  856. address = "DB5.DBX2.1";
  857. if (index == 4)
  858. address = "DB5.DBX2.2";
  859. if (index == 5)
  860. address = "DB5.DBX2.3";
  861. if (index == 6)
  862. address = "DB5.DBX2.4";
  863. if (index == 7)
  864. address = "DB5.DBX2.5";
  865. if (index == 8)
  866. address = "DB5.DBX2.6";
  867. if (index == 9)
  868. address = "DB5.DBX2.7";
  869. if (index == 10)
  870. address = "DB5.DBX3.0";
  871. if (index == 11)
  872. address = "DB5.DBX3.1";
  873. if (index == 12)
  874. address = "DB5.DBX3.2";
  875. if (index == 13)
  876. address = "DB5.DBX3.3";
  877. if (index == 14)
  878. address = "DB5.DBX3.4";
  879. if (index == 15)
  880. address = "DB5.DBX3.5";
  881. HKDevice.HK_PLC_S7.Write<bool>(address, false);
  882. }
  883. }
  884. else if (o.ToString().Contains("进料桶顶升气缸"))
  885. {
  886. HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", true);
  887. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.6,值:true");
  888. }
  889. else if (o.ToString().Contains("出料桶顶升气缸1"))
  890. {
  891. HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", false);
  892. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.7,值:false");
  893. }
  894. else if (o.ToString().Contains("出料桶顶升气缸2"))
  895. {
  896. HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", false);
  897. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.0,值:false");
  898. }
  899. else if (o.ToString().Contains("出料桶顶升气缸3"))
  900. {
  901. HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", false);
  902. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.1,值:false");
  903. }
  904. else if (o.ToString().Contains("托盘气缸1_1"))
  905. {
  906. HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", true);
  907. }
  908. else if (o.ToString().Contains("托盘气缸1_2"))
  909. {
  910. HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", true);
  911. }
  912. else if (o.ToString().Contains("托盘气缸2_1"))
  913. {
  914. HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", true);
  915. }
  916. else if (o.ToString().Contains("托盘气缸2_2"))
  917. {
  918. HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", true);
  919. }
  920. }
  921. }), "ManualClose", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  922. //手动控制电机轴 DB5.DBX4.6~DB5.DBX5.2
  923. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.6", true); }), "StartAxisLoadCommand", true);
  924. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.6", false); }), "StopAxisLoadCommand", true);
  925. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.7", true); }), "StartAxisMidCommand", true);
  926. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.7", false); }), "StopAxisMidCommand", true);
  927. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.0", true); }), "StartAxisUnLoadCommand", true);
  928. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.0", false); }), "StopAxisUnLoadCommand", true);
  929. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.1", true); }), "StartAxis1Command", true);
  930. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.1", false); }), "StopAxis1Command", true);
  931. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.2", true); }), "StartAxis2Command", true);
  932. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.2", false); }), "StopAxis2Command", true);
  933. //将本地配方发送到西门子配方里,执行配料
  934. ActionManage.GetInstance.Register(new Action<Object>((res) =>
  935. {
  936. if (res != null && res is RemoteRecipeData rm)
  937. {
  938. //Json<RemoteRecipeDataColl>.Data.Recipes.Add(rm);
  939. var newRecipe = new RemoteRecipeData();
  940. newRecipe.RecipeName = rm.RecipeName;
  941. newRecipe.RecipeCode = rm.RecipeCode;
  942. newRecipe.TrayCode = rm.TrayCode;
  943. foreach (var item in rm.RawMaterial)
  944. {
  945. newRecipe.RawMaterial.Add(new RemoteRecipeRawMaterial()
  946. {
  947. DeviceIp = item.DeviceIp,
  948. RawMaterialName = item.RawMaterialName,
  949. RawMaterialBarrelNum = item.RawMaterialBarrelNum,
  950. RawMaterialType = item.RawMaterialType,
  951. RawMaterialWeight = item.RawMaterialWeight,
  952. Laying_Off_Weight = item.Laying_Off_Weight,
  953. StockBinRemainingWeight = item.StockBinRemainingWeight,
  954. RawMaterialLocation = item.RawMaterialLocation,
  955. IsDosingComple = item.IsDosingComple
  956. });
  957. }
  958. Json<RemoteRecipeDataColl>.Data.Recipes.Add(newRecipe);
  959. }
  960. }), "LocalSimulationRecipeIssue", true);
  961. //手动控制系统模式
  962. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", true); }), "SystemStart", true);
  963. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", false); }), "SystemStop", true);
  964. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", true); }), "SystemPause", true);
  965. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", false); }), "SystemReset", true);
  966. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", false); }), "SystemAutoMode", true);
  967. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", true); }), "SystemDebugMode", true);
  968. //流程控制
  969. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.3", true); }), "ManualSystemReset", true);
  970. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.4", true); }), "CLearRecipeInfo", true);
  971. ActionManage.GetInstance.Register(new Action(() =>
  972. {
  973. Json<RemoteRecipeDataColl>.Data.Recipes.Clear();
  974. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
  975. GVL_SmallStation.GetInstance.WindSendDosingStatus = 0;
  976. GVL_SmallStation.GetInstance.WindSendDosing = false;
  977. GVL_SmallStation.GetInstance.Order_Cancel = false;
  978. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
  979. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  980. for (int i = 0; i < 5; i++)
  981. {
  982. RecipeQueueTray[i].Clear();
  983. GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0;
  984. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 0;
  985. }
  986. StockBinInit();
  987. //for (int i = 0; i < GVL_SmallStation.GetInstance.StockInDosingComple.Length; i++)
  988. //{
  989. // GVL_SmallStation.GetInstance.StockInDosingComple[i] = false;
  990. //}
  991. MessageNotify.GetInstance.ShowRunLog("系统流程复位,等待西门子重新下发订单");
  992. }), "BPASystemReset", true);
  993. //往海科PLC写值
  994. ActionManage.GetInstance.Register(new Action<Object>((o) =>
  995. {
  996. if (o != null && o is HKDeviceWrite data)
  997. {
  998. if (data.PlcVarType == PlcVarType.Bool)
  999. {
  1000. bool value = (bool)data.Value;
  1001. HKDevice.HK_PLC_S7.Write<bool>(data.Address, value);
  1002. }
  1003. else if (data.PlcVarType == PlcVarType.Byte)
  1004. {
  1005. byte value = (byte)data.Value;
  1006. HKDevice.HK_PLC_S7.Write<byte>(data.Address, value);
  1007. }
  1008. else if (data.PlcVarType == PlcVarType.Int)
  1009. {
  1010. short value = (short)data.Value;
  1011. HKDevice.HK_PLC_S7.Write<short>(data.Address, value);
  1012. }
  1013. else if (data.PlcVarType == PlcVarType.Dint)
  1014. {
  1015. int value = (int)data.Value;
  1016. HKDevice.HK_PLC_S7.Write<int>(data.Address, value);
  1017. }
  1018. else if (data.PlcVarType == PlcVarType.Real)
  1019. {
  1020. float value = (float)data.Value;
  1021. HKDevice.HK_PLC_S7.Write<float>(data.Address, value);
  1022. }
  1023. }
  1024. }), "PLCWrite", true);
  1025. //电机速度
  1026. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1027. {
  1028. if (o != null && o is short value)
  1029. {
  1030. HKDevice.HK_PLC_S7.Write("DB47.DBW8", value);
  1031. }
  1032. }), "AxisLoadSpeedSet", true);
  1033. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1034. {
  1035. if (o != null && o is short value)
  1036. {
  1037. HKDevice.HK_PLC_S7.Write("DB47.DBW10", value);
  1038. }
  1039. }), "AxisMidSpeedSet", true);
  1040. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1041. {
  1042. if (o != null && o is short value)
  1043. {
  1044. HKDevice.HK_PLC_S7.Write("DB47.DBW12", value);
  1045. }
  1046. }), "AxisUnLoadSpeedSet", true);
  1047. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1048. {
  1049. if (o != null && o is float value)
  1050. {
  1051. HKDevice.HK_PLC_S7.Write("DB47.DBD0", value);
  1052. }
  1053. }), "Axis1SpeedSet", true);
  1054. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1055. {
  1056. if (o != null && o is float value)
  1057. {
  1058. HKDevice.HK_PLC_S7.Write("DB47.DBD4", value);
  1059. }
  1060. }), "Axis2SpeedSet", true);
  1061. //机器人的操作
  1062. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1063. {
  1064. if (o != null && o is string address)
  1065. {
  1066. HKDevice.HK_PLC_S7.Write(address, true);
  1067. }
  1068. }), "RobotSendTrueCommand", true);
  1069. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1070. {
  1071. if (o != null && o is string address)
  1072. {
  1073. HKDevice.HK_PLC_S7.Write(address, false);
  1074. }
  1075. }), "RobotSendFalseCommand", true);
  1076. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1077. {
  1078. if (o != null && o is short Value)
  1079. {
  1080. HKDevice.HK_PLC_S7.Write("DB4.DBB1", (byte)Value);
  1081. }
  1082. }), "RobotSetProgramNum", true);
  1083. }
  1084. /// <summary>
  1085. /// 连接海科PLC,并开启重连线程。
  1086. /// </summary>
  1087. public void DeviceConnect()
  1088. {
  1089. try
  1090. {
  1091. if (Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
  1092. {
  1093. //HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
  1094. HKDevice.HK_PLC_S7.Connect(new BPA.Communication.Base.ConfigurationOptions() { cpuType = CpuType.S71200, IpAddress = HK_PLC_IP });
  1095. if (HKDevice.IsConnected)
  1096. MessageNotify.GetInstance.ShowRunLog("海科plc连接成功");
  1097. }
  1098. }
  1099. catch (Exception ex)
  1100. {
  1101. MessageNotify.GetInstance.ShowAlarmLog("海科plc连接失败,等待重新连接");
  1102. }
  1103. finally
  1104. {
  1105. HKDevice.Init();
  1106. MessageNotify.GetInstance.ShowRunLog("海科plc初始化完成");
  1107. }
  1108. TaskManage.GetInstance.StartLong(new Action(() =>
  1109. {
  1110. try
  1111. {
  1112. if (!HKDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
  1113. {
  1114. HKDevice.HK_PLC_S7.Connect(new BPA.Communication.Base.ConfigurationOptions() { cpuType = CpuType.S71200, IpAddress = HK_PLC_IP });
  1115. if (HKDevice.IsConnected)
  1116. MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接成功");
  1117. }
  1118. }
  1119. catch (Exception ex)
  1120. {
  1121. }
  1122. Thread.Sleep(50);
  1123. }), "设备连接", true);
  1124. }
  1125. private void DosingDevice(int Index, int DeviceID)
  1126. {
  1127. if (RTrig.GetInstance("Tray2StatusDevice" + DeviceID).Start(DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.RunStatus == 3))
  1128. {
  1129. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{RemoteRecipes.ElementAt(Index).RecipeName},{DeviceID}号仓,配料完成");
  1130. int res = Array.FindIndex(RemoteRecipes.ElementAt(Index).RawMaterial.ToArray(), p => p.RawMaterialLocation == DeviceID);
  1131. RemoteRecipes.ElementAt(Index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.CutWeightFeedback;
  1132. DeviceInquire.GetInstance.GetDevice(DeviceID).StatusReset();
  1133. if (DeviceID >= 1 && DeviceID <= 8)
  1134. {
  1135. HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (DeviceID - 1), true);
  1136. }
  1137. else if (DeviceID >= 9 && DeviceID <= 15)
  1138. {
  1139. HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (DeviceID - 9), true);
  1140. }
  1141. }
  1142. }
  1143. public void RawMaterialNameWithCode()
  1144. {
  1145. GVL_SmallStation.GetInstance.RawMaterialsNameCode.Clear();
  1146. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0001", "色拉油");
  1147. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0002", "一级菜油");
  1148. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0003", "菜籽油");
  1149. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0004", "青花椒油");
  1150. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0005", "卤牛肉丁");
  1151. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0006", "冻鸡肉丁");
  1152. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0007", "香菇丁");
  1153. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0008", "高水分糍粑海椒");
  1154. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0009", "低水分糍粑海椒");
  1155. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0010", "辣豆瓣");
  1156. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0011", "整豆豉");
  1157. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0012", "豆豉细粒");
  1158. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0013", "卤黄豆");
  1159. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0014", "野山椒粒");
  1160. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0015", "竹笋丁");
  1161. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0016", "香辣酱辣椒酱");
  1162. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0017", "芽菜粒");
  1163. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0018", "榨菜丁");
  1164. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0019", "盐菜");
  1165. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0020", "洋葱丁");
  1166. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0021", "番茄酱");
  1167. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0022", "甜豆瓣");
  1168. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0023", "甜面酱");
  1169. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0024", "芝麻酱");
  1170. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0025", "炸花生");
  1171. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0026", "盐渍青椒丁");
  1172. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0027", "备料剁红椒");
  1173. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0028", "萝卜丁");
  1174. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0029", "油芝麻");
  1175. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0030", "生姜");
  1176. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0031", "大蒜");
  1177. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0032", "榨菜酱");
  1178. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0033", "炸碗豆");
  1179. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0034", "大头菜丁");
  1180. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0035", "酱油");
  1181. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0036", "I+G");
  1182. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0037", "味精");
  1183. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0038", "白糖");
  1184. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0039", "食盐");
  1185. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0040", "花椒酱");
  1186. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0041", "调味膏2");
  1187. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0042", "调味膏5");
  1188. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0043", "十三香调味膏");
  1189. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0044", "酱香膏");
  1190. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0045", "芽菜香料粉");
  1191. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0046", "香料A");
  1192. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0047", "香料D");
  1193. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0048", "猪肉精膏");
  1194. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0049", "调味膏3");
  1195. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0050", "柠檬酸粉");
  1196. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0051", "辣椒红");
  1197. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0052", "辣椒油树脂");
  1198. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0053", "水态混和酸");
  1199. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0054", "加水稀释后防腐剂");
  1200. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0055", "异维C钠粉");
  1201. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0056", "琼脂粉");
  1202. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0057", "香葱油");
  1203. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0058", "水态甜味剂");
  1204. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0059", "孜然粉");
  1205. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0060", "孜然油");
  1206. }
  1207. }
  1208. }