终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

1313 Zeilen
75 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.JXJFoodSmallStation.Model.HK_PLC;
  4. using BPASmartClient.JXJFoodSmallStation.Model.Siemens;
  5. using BPASmartClient.JXJFoodSmallStation.Model.WindSend;
  6. using BPASmartClient.Modbus;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Configuration;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace BPASmartClient.JXJFoodSmallStation.Model
  17. {
  18. public class ProcessControl
  19. {
  20. private volatile static ProcessControl _Instance;
  21. public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
  22. private ProcessControl() { }
  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. /// <summary>
  32. /// 配方队列
  33. /// </summary>
  34. public ConcurrentQueue<string> RecipeQueue = new ConcurrentQueue<string>();
  35. public ConcurrentQueue<string> RecipeQueueTray2 = new ConcurrentQueue<string>();
  36. public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
  37. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  38. public WindSendDeviceStatus WindSendDevice = new WindSendDeviceStatus();
  39. XL_Finish_DB RecipeFinishInfo = new XL_Finish_DB();
  40. /// <summary>
  41. /// 风送PLC的DB块
  42. /// </summary>
  43. WindSend_Write WindSendData = new WindSend_Write();
  44. /// <summary>
  45. /// 接收原料数据
  46. /// </summary>
  47. public RecipeRawMaterial RawMaterial;
  48. public void Init()
  49. {
  50. testData();
  51. //Json<RemoteRecipeDataColl>.Data.Recipes = Json<LocalRecipeDataColl>.Data.Recipes;
  52. for (int i = 0; i < 16; i++)
  53. {
  54. if (DeviceInquire.GetInstance.GetDevice(i).DeviceName != null)
  55. {
  56. if (!RawMaterialsNamePos.ContainsKey(DeviceInquire.GetInstance.GetDevice(i).DeviceName))
  57. {
  58. RawMaterialsNamePos.Add(DeviceInquire.GetInstance.GetDevice(i).DeviceName, (short)DeviceInquire.GetInstance.GetDevice(i).deviceStatus.DeviceNum);
  59. }
  60. }
  61. }
  62. ActionManage.GetInstance.CancelRegister("SiemensRecipeRecive");
  63. ActionManage.GetInstance.Register(new Action<object>((res) =>
  64. {
  65. ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
  66. ObservableCollection<WindSendRawMaterial> WindSendData = new ObservableCollection<WindSendRawMaterial>();
  67. if (SiemensDevice.IsConnected)
  68. {
  69. if (res != null && res is XL_Start_DB recipe)
  70. {
  71. if (!string.IsNullOrEmpty(recipe.RecipeCode)) {
  72. RawMaterials.Clear();
  73. for (int i = 0; i < GVL_SmallStation.Max_DosingSotckBinNum; i++)
  74. {
  75. if (!string.IsNullOrEmpty(recipe.Material[i].Material_Name))
  76. {
  77. if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name))
  78. {
  79. RawMaterials.Add(new RemoteRecipeRawMaterial()
  80. {
  81. RawMaterialName = recipe.Material[i].Material_Name,
  82. RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum,
  83. RawMaterialWeight = recipe.Material[i].Material_Weight,
  84. RawMaterialLocation = (int)RawMaterialsNamePos[recipe.Material[i].Material_Name]
  85. });
  86. }
  87. else
  88. {
  89. //MessageNotify.GetInstance.AlarmLog("配方名称与本地不符合");
  90. }
  91. }
  92. else
  93. {
  94. break;
  95. }
  96. }
  97. for (int i = 0; i < GVL_SmallStation.Max_PowderSotckBinNum; i++)
  98. {
  99. if (!string.IsNullOrEmpty(recipe.Powder[i].Powder_Name))
  100. {
  101. WindSendData.Add(new WindSendRawMaterial()
  102. {
  103. RawMaterialName = recipe.Powder[i].Powder_Name,
  104. RawMaterialWeight = recipe.Powder[i].Powder_Weight
  105. });
  106. }
  107. else
  108. {
  109. break;
  110. }
  111. }
  112. App.Current.Dispatcher.Invoke(() => {
  113. Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  114. {
  115. RecipeName = recipe.RecipeName,
  116. RecipeCode = recipe.RecipeCode,
  117. RawMaterial = RawMaterials,
  118. TrayCode = recipe.StockCode,
  119. WindSend = WindSendData
  120. });
  121. });
  122. }
  123. }
  124. }
  125. }), "SiemensRecipeRecive", true);
  126. ActionManage.GetInstance.CancelRegister("SiemensRecipeFinish");
  127. ActionManage.GetInstance.Register(new Action<object>((res) =>
  128. {
  129. if (SiemensDevice.IsConnected)
  130. {
  131. if (res != null && res is RemoteRecipeData recipe)
  132. {
  133. RecipeFinishInfo.Order_No = recipe.RecipeCode;
  134. RecipeFinishInfo.Product_Code = recipe.RecipeName;
  135. RecipeFinishInfo.Job_No = (short)recipe.TrayCode;
  136. for (int i = 0; i < recipe.RawMaterial.Count; i++)
  137. {
  138. RecipeFinishInfo.Material[i] = new UDT1();
  139. RecipeFinishInfo.Material[i].Material_Name = recipe.RawMaterial.ElementAt(i).RawMaterialName;
  140. RecipeFinishInfo.Material[i].Material_BarrelNum = recipe.RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  141. RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = recipe.RawMaterial.ElementAt(i).Laying_Off_Weight;
  142. }
  143. for (int i = 0; i < recipe.WindSend.Count; i++)
  144. {
  145. RecipeFinishInfo.Powder[i] = new UDT2();
  146. RecipeFinishInfo.Powder[i].Powder_Name = recipe.RawMaterial.ElementAt(i).RawMaterialName;
  147. RecipeFinishInfo.Powder[i].Powder_Weight = recipe.RawMaterial.ElementAt(i).Laying_Off_Weight;
  148. }
  149. if (GVL_SmallStation.SiemensSendRecipeStatus == 6)
  150. {
  151. GVL_SmallStation.SiemensSendRecipeStatus = 7;
  152. RecipeFinishInfo.Ask_For_Finish = true;
  153. SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
  154. }
  155. }
  156. }
  157. }), "SiemensRecipeFinish", true);
  158. ActionManage.GetInstance.CancelRegister("LocalSimulationRecipeIssue");
  159. ActionManage.GetInstance.Register(new Action<Object>((res) =>
  160. {
  161. if (res != null && res is RemoteRecipeData recipe)
  162. {
  163. Json<RemoteRecipeDataColl>.Data.Recipes.Add(recipe);
  164. }
  165. }), "LocalSimulationRecipeIssue", true);
  166. string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
  167. string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
  168. string WindSend_PLC_IP = ConfigurationManager.AppSettings["WindSend_IP"];
  169. try
  170. {
  171. if (Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
  172. {
  173. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
  174. }
  175. if (Json<DevicePar>.Data.deviceConnectPar.SiemensConnect)
  176. {
  177. SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  178. }
  179. if (Json<DevicePar>.Data.deviceConnectPar.WindSendConnect)
  180. {
  181. WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200, WindSend_PLC_IP);
  182. }
  183. if (HKDevice.IsConnected)
  184. {
  185. HKDevice.Init();
  186. MessageNotify.GetInstance.ShowRunLog("海科plc连接成功,并初始化完成");
  187. }
  188. if (SiemensDevice.IsConnected)
  189. {
  190. SiemensDevice.Init();
  191. MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功,并初始化完成");
  192. }
  193. if (WindSendDevice.IsConnected)
  194. {
  195. WindSendDevice.Init();
  196. MessageNotify.GetInstance.ShowRunLog("风送plc连接成功,并初始化完成");
  197. }
  198. }
  199. catch (Exception ex)
  200. {
  201. }
  202. ThreadManage.GetInstance().StartLong(new Action(() =>
  203. {
  204. if (!HKDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
  205. {
  206. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
  207. MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接");
  208. if (HKDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接成功");
  209. }
  210. if (!SiemensDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.SiemensConnect)
  211. {
  212. SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  213. MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接");
  214. if (SiemensDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接成功");
  215. }
  216. if (!WindSendDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.WindSendConnect)
  217. {
  218. WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200, WindSend_PLC_IP);
  219. MessageNotify.GetInstance.ShowRunLog("风送plc重新连接成功");
  220. }
  221. Thread.Sleep(50);
  222. }), "设备连接", true);
  223. RecipeQueue.Clear();
  224. //手动控制系统模式
  225. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", true); }), "SystemStart", true);
  226. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", false); }), "SystemStop", true);
  227. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", true); }), "SystemPause", true);
  228. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", false); }), "SystemReset", true);
  229. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", false); }), "SystemAutoMode", true);
  230. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", true); }), "SystemDebugMode", true);
  231. //流程控制
  232. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.3", true); }), "ManualSystemReset", true);
  233. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.4", true); }), "CLearRecipeInfo", true);
  234. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX0.7", true); }), "AGVPutTrayFinish", true);
  235. //手动控制电机轴
  236. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.6", true); }), "StartAxisLoadCommand", true);
  237. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.6", false); }), "StopAxisLoadCommand", true);
  238. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.7", true); }), "StartAxisMidCommand", true);
  239. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.7", false); }), "StopAxisMidCommand", true);
  240. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.0", true); }), "StartAxisUnLoadCommand", true);
  241. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.0", false); }), "StopAxisUnLoadCommand", true);
  242. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.1", true); }), "StartAxis1Command", true);
  243. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.1", false); }), "StopAxis1Command", true);
  244. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.2", true); }), "StartAxis2Command", true);
  245. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.2", false); }), "StopAxis2Command", true);
  246. //电机速度
  247. ActionManage.GetInstance.Register(new Action<object>((o) =>
  248. {
  249. if (o != null && o is short value)
  250. {
  251. HKDevice.HK_PLC_S7.Write("DB47.DBD8", value);
  252. }
  253. }), "AxisLoadSpeedSet", true);
  254. ActionManage.GetInstance.Register(new Action<object>((o) =>
  255. {
  256. if (o != null && o is short value)
  257. {
  258. HKDevice.HK_PLC_S7.Write("DB47.DBD10", value);
  259. }
  260. }), "AxisMidSpeedSet", true);
  261. ActionManage.GetInstance.Register(new Action<object>((o) =>
  262. {
  263. if (o != null && o is short value)
  264. {
  265. HKDevice.HK_PLC_S7.Write("DB47.DBD12", value);
  266. }
  267. }), "AxisUnLoadSpeedSet", true);
  268. ActionManage.GetInstance.Register(new Action<object>((o) =>
  269. {
  270. if (o != null && o is float value)
  271. {
  272. HKDevice.HK_PLC_S7.Write("DB47.DBD0", value);
  273. }
  274. }), "Axis1SpeedSet", true);
  275. ActionManage.GetInstance.Register(new Action<object>((o) =>
  276. {
  277. if (o != null && o is float value)
  278. {
  279. HKDevice.HK_PLC_S7.Write("DB47.DBD4", value);
  280. }
  281. }), "Axis2SpeedSet", true);
  282. RecipeQueue.Clear();
  283. //Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
  284. ThreadManage.GetInstance().StartLong(new Action(() =>
  285. {
  286. if (HKDevice.IsConnected)
  287. {
  288. GVL_SmallStation.GetInstance.HeartBeatToPlc = !GVL_SmallStation.GetInstance.HeartBeatToPlc;
  289. HKDevice.HK_PLC_S7.Write("DB4.DBX0.0", GVL_SmallStation.GetInstance.HeartBeatToPlc);
  290. GVL_SmallStation.GetInstance.HeartBeatFromPlc = HKDevice.HK_PLC_S7.Read<bool>("DB45.DBX0.0");
  291. //获取系统状态
  292. GVL_SmallStation.SystemStatus = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.0");//系统启停
  293. GVL_SmallStation.SystemMode = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.1");//系统模式
  294. GVL_SmallStation.SystemRunStatus = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.2");//系统暂停
  295. }
  296. Thread.Sleep(200);
  297. }), "通信心跳", true);
  298. ThreadManage.GetInstance().StartLong(new Action(() =>
  299. {
  300. DeviceStatusDispose();
  301. ReceviceData();
  302. RecipeInfoToHKPLC();
  303. Thread.Sleep(10);
  304. }), "西门子配发下发流程处理", true);
  305. ThreadManage.GetInstance().StartLong(new Action(() =>
  306. {
  307. if (HKDevice.IsConnected)
  308. {
  309. ManualOpen();
  310. ManualClose();
  311. }
  312. Thread.Sleep(10);
  313. }), "手动操作", true);
  314. }
  315. private void GetStatus()
  316. {
  317. for (int i = 0; i < 8; i++)
  318. {
  319. GVL_SmallStation.GetInstance.Cylinder_JackInfo[i] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX0." + i);
  320. }
  321. for (int i = 0; i < 7; i++)
  322. {
  323. GVL_SmallStation.GetInstance.Cylinder_JackInfo[i + 8] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX0." + i);
  324. }
  325. }
  326. private void ManualOpen()
  327. {
  328. ActionManage.GetInstance.Register(new Action<object>((o) =>
  329. {
  330. if (o != null)
  331. {
  332. if (o.ToString().Contains("升降气缸"))
  333. {
  334. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  335. switch (index)
  336. {
  337. case 1:
  338. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.0", true);
  339. break;
  340. case 2:
  341. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.1", true);
  342. break;
  343. case 3:
  344. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.2", true);
  345. break;
  346. case 4:
  347. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.3", true);
  348. break;
  349. case 5:
  350. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.4", true);
  351. break;
  352. case 6:
  353. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.5", true);
  354. break;
  355. case 7:
  356. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.6", true);
  357. break;
  358. case 8:
  359. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.7", true);
  360. break;
  361. case 9:
  362. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.0", true);
  363. break;
  364. case 10:
  365. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.1", true);
  366. break;
  367. case 11:
  368. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.2", true);
  369. break;
  370. case 12:
  371. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.3", true);
  372. break;
  373. case 13:
  374. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.4", true);
  375. break;
  376. case 14:
  377. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.5", true);
  378. break;
  379. case 15:
  380. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.6", true);
  381. break;
  382. default:
  383. break;
  384. }
  385. }
  386. else if (o.ToString().Contains("阻挡气缸"))
  387. {
  388. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  389. switch (index)
  390. {
  391. case 1:
  392. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.7", true);
  393. break;
  394. case 2:
  395. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.0", true);
  396. break;
  397. case 3:
  398. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.1", true);
  399. break;
  400. case 4:
  401. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.2", true);
  402. break;
  403. case 5:
  404. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.3", true);
  405. break;
  406. case 6:
  407. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.4", true);
  408. break;
  409. case 7:
  410. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.5", true);
  411. break;
  412. case 8:
  413. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.6", true);
  414. break;
  415. case 9:
  416. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.7", true);
  417. break;
  418. case 10:
  419. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.0", true);
  420. break;
  421. case 11:
  422. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.1", true);
  423. break;
  424. case 12:
  425. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.2", true);
  426. break;
  427. case 13:
  428. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.3", true);
  429. break;
  430. case 14:
  431. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.4", true);
  432. break;
  433. case 15:
  434. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.5", true);
  435. break;
  436. default:
  437. break;
  438. }
  439. }
  440. else if (o.ToString().Contains("进料桶顶升气缸"))
  441. {
  442. HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", false);//默认顶升
  443. }
  444. else if (o.ToString().Contains("出料桶顶升气缸1"))
  445. {
  446. HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", true);
  447. }
  448. else if (o.ToString().Contains("出料桶顶升气缸2"))
  449. {
  450. HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", true);
  451. }
  452. else if (o.ToString().Contains("出料桶顶升气缸3"))
  453. {
  454. HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", true);
  455. }
  456. else if (o.ToString().Contains("托盘气缸1_1"))
  457. {
  458. HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", false);//默认伸出
  459. }
  460. else if (o.ToString().Contains("托盘气缸1_2"))
  461. {
  462. HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", false);
  463. }
  464. else if (o.ToString().Contains("托盘气缸2_1"))
  465. {
  466. HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", false);
  467. }
  468. else if (o.ToString().Contains("托盘气缸2_2"))
  469. {
  470. HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", false);
  471. }
  472. }
  473. }), "ManualOpen", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  474. }
  475. private void ManualClose()
  476. {
  477. ActionManage.GetInstance.Register(new Action<object>((o) =>
  478. {
  479. if (o != null)
  480. {
  481. if (o.ToString().Contains("升降气缸"))
  482. {
  483. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  484. switch (index)
  485. {
  486. case 1:
  487. HKDevice.HK_PLC_S7.Write("DB5.DBX0.0", false);
  488. break;
  489. case 2:
  490. HKDevice.HK_PLC_S7.Write("DB5.DBX0.1", false);
  491. break;
  492. case 3:
  493. HKDevice.HK_PLC_S7.Write("DB5.DBX0.2", false);
  494. break;
  495. case 4:
  496. HKDevice.HK_PLC_S7.Write("DB5.DBX0.3", false);
  497. break;
  498. case 5:
  499. HKDevice.HK_PLC_S7.Write("DB5.DBX0.4", false);
  500. break;
  501. case 6:
  502. HKDevice.HK_PLC_S7.Write("DB5.DBX0.5", false);
  503. break;
  504. case 7:
  505. HKDevice.HK_PLC_S7.Write("DB5.DBX0.6", false);
  506. break;
  507. case 8:
  508. HKDevice.HK_PLC_S7.Write("DB5.DBX0.7", false);
  509. break;
  510. case 9:
  511. HKDevice.HK_PLC_S7.Write("DB5.DBX1.0", false);
  512. break;
  513. case 10:
  514. HKDevice.HK_PLC_S7.Write("DB5.DBX1.1", false);
  515. break;
  516. case 11:
  517. HKDevice.HK_PLC_S7.Write("DB5.DBX1.2", false);
  518. break;
  519. case 12:
  520. HKDevice.HK_PLC_S7.Write("DB5.DBX1.3", false);
  521. break;
  522. case 13:
  523. HKDevice.HK_PLC_S7.Write("DB5.DBX1.4", false);
  524. break;
  525. case 14:
  526. HKDevice.HK_PLC_S7.Write("DB5.DBX1.5", false);
  527. break;
  528. case 15:
  529. HKDevice.HK_PLC_S7.Write("DB5.DBX1.6", false);
  530. break;
  531. default:
  532. break;
  533. }
  534. }
  535. else if (o.ToString().Contains("阻挡气缸"))
  536. {
  537. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  538. switch (index)
  539. {
  540. case 1:
  541. HKDevice.HK_PLC_S7.Write("DB5.DBX1.7", false);
  542. break;
  543. case 2:
  544. HKDevice.HK_PLC_S7.Write("DB5.DBX2.0", false);
  545. break;
  546. case 3:
  547. HKDevice.HK_PLC_S7.Write("DB5.DBX2.1", false);
  548. break;
  549. case 4:
  550. HKDevice.HK_PLC_S7.Write("DB5.DBX2.2", false);
  551. break;
  552. case 5:
  553. HKDevice.HK_PLC_S7.Write("DB5.DBX2.3", false);
  554. break;
  555. case 6:
  556. HKDevice.HK_PLC_S7.Write("DB5.DBX2.4", false);
  557. break;
  558. case 7:
  559. HKDevice.HK_PLC_S7.Write("DB5.DBX2.5", false);
  560. break;
  561. case 8:
  562. HKDevice.HK_PLC_S7.Write("DB5.DBX2.6", false);
  563. break;
  564. case 9:
  565. HKDevice.HK_PLC_S7.Write("DB5.DBX2.7", false);
  566. break;
  567. case 10:
  568. HKDevice.HK_PLC_S7.Write("DB5.DBX3.0", false);
  569. break;
  570. case 11:
  571. HKDevice.HK_PLC_S7.Write("DB5.DBX3.1", false);
  572. break;
  573. case 12:
  574. HKDevice.HK_PLC_S7.Write("DB5.DBX3.2", false);
  575. break;
  576. case 13:
  577. HKDevice.HK_PLC_S7.Write("DB5.DBX3.3", false);
  578. break;
  579. case 14:
  580. HKDevice.HK_PLC_S7.Write("DB5.DBX3.4", false);
  581. break;
  582. case 15:
  583. HKDevice.HK_PLC_S7.Write("DB5.DBX3.5", false);
  584. break;
  585. default:
  586. break;
  587. }
  588. }
  589. else if (o.ToString().Contains("进料桶顶升气缸"))
  590. {
  591. HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", true);
  592. }
  593. else if (o.ToString().Contains("出料桶顶升气缸1"))
  594. {
  595. HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", false);
  596. }
  597. else if (o.ToString().Contains("出料桶顶升气缸2"))
  598. {
  599. HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", false);
  600. }
  601. else if (o.ToString().Contains("出料桶顶升气缸3"))
  602. {
  603. HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", false);
  604. }
  605. else if (o.ToString().Contains("托盘气缸1_1"))
  606. {
  607. HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", true);
  608. }
  609. else if (o.ToString().Contains("托盘气缸1_2"))
  610. {
  611. HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", true);
  612. }
  613. else if (o.ToString().Contains("托盘气缸2_1"))
  614. {
  615. HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", true);
  616. }
  617. else if (o.ToString().Contains("托盘气缸2_2"))
  618. {
  619. HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", true);
  620. }
  621. }
  622. }), "ManualClose", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  623. }
  624. /// <summary>
  625. ///
  626. /// </summary>
  627. private void DeviceStatusDispose()
  628. {
  629. if (HKDevice.IsConnected)
  630. {
  631. GVL_SmallStation.Station1HaveTray = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX0.7");//工站1 有货架
  632. GVL_SmallStation.Station2HaveTray = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.0");//工站1 有货架
  633. if (RTrig.GetInstance("WindSendDosingCompleToHKPLC").Start(GVL_SmallStation.WindSendDosingComple))
  634. {
  635. GVL_SmallStation.WindSendDosingComple = false;
  636. HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.7", true);
  637. MessageNotify.GetInstance.ShowRunLog("风送配料完成信号,发给产线plc信号");
  638. }
  639. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.1"))
  640. {
  641. HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.7", false);
  642. }
  643. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.7"))//允许下配方1或者允许下配方2
  644. {
  645. GVL_SmallStation.IsAllowSiemensSendRecipe = true;
  646. //MessageNotify.GetInstance.ShowRunLog("Plc允许下发配方");
  647. }
  648. GVL_SmallStation.Station1Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.1");
  649. GVL_SmallStation.Station2Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.2");
  650. GVL_SmallStation.Station1Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.3");
  651. GVL_SmallStation.Station2Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.4");
  652. if (!GVL_SmallStation.TrayLogicFinish)
  653. {
  654. if (GVL_SmallStation.AGV_PutTray1Finish)
  655. {
  656. HKDevice.HK_PLC_S7.Write("DB4.DBX0.7", true);
  657. GVL_SmallStation.AGV_PutTray1Finish = false;
  658. MessageNotify.GetInstance.ShowRunLog("AGV到位 发送到位信号给plc");
  659. }
  660. if (GVL_SmallStation.Station1HaveTray)
  661. {
  662. HKDevice.HK_PLC_S7.Write("DB4.DBX0.7", false);
  663. GVL_SmallStation.TrayLogicFinish = true;
  664. MessageNotify.GetInstance.ShowRunLog("托盘1有货架");
  665. }
  666. else
  667. {
  668. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.5") == true)
  669. {
  670. if (GVL_SmallStation.CylinderReset)
  671. {
  672. HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.5", true);
  673. }
  674. MessageNotify.GetInstance.ShowRunLog("气缸收紧错位");
  675. }
  676. else
  677. {
  678. HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.5", false);
  679. }
  680. }
  681. }
  682. else
  683. {
  684. if (GVL_SmallStation.AGV_GetTray1Finish)
  685. {
  686. HKDevice.HK_PLC_S7.Write("DB4.DBX1.1", true);
  687. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.7") == true)
  688. {
  689. HKDevice.HK_PLC_S7.Write("DB4.DBX1.1", false);
  690. GVL_SmallStation.TrayLogicFinish = false;
  691. GVL_SmallStation.AGV_GetTray1Finish = false;
  692. }
  693. }
  694. }
  695. }
  696. if (SiemensDevice.IsConnected)
  697. {
  698. ushort TrayCylinder = 0;
  699. ushort TraySensor = 0;
  700. if (GVL_SmallStation.Station1Sensor)
  701. {
  702. TraySensor = TraySensor.SetBitValue(1, true);
  703. }
  704. else
  705. {
  706. TraySensor = TraySensor.SetBitValue(0, false);
  707. }
  708. if (!GVL_SmallStation.Station1Cylinder)
  709. {
  710. TrayCylinder = TrayCylinder.SetBitValue(1, true);
  711. }
  712. else
  713. {
  714. TrayCylinder = TrayCylinder.SetBitValue(0, false);
  715. }
  716. this.SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2231.DBX28.4", GVL_SmallStation.WindSendAllowAGVPutGet);
  717. this.SiemensDevice.Siemens_PLC_S7.Write<ushort>("DB2231.DBW190", TraySensor);//添加工位传感器的信号
  718. this.SiemensDevice.Siemens_PLC_S7.Write<ushort>("DB2231.DBW192", TrayCylinder);//添加工位气缸的信号
  719. if (RTrig.GetInstance("AGV_PutTray1Finish1111").Start(SiemensDevice.XL_Status.AgvFinishPut == 1))
  720. {
  721. GVL_SmallStation.AGV_PutTray1Finish = true;
  722. }
  723. if (RTrig.GetInstance("AGV_GetTray1Finish111").Start(SiemensDevice.XL_Status.AgvFinishGet == 1))
  724. {
  725. GVL_SmallStation.AGV_GetTray1Finish = true;
  726. }
  727. }
  728. }
  729. /// <summary>
  730. /// 将配方添加到配方队列中
  731. /// </summary>
  732. private void ReceviceData()
  733. {
  734. if (!GVL_SmallStation.GetInstance.IsUseLocalRecipe)
  735. {
  736. RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  737. if (RemoteRecipes.Count > 0)
  738. {
  739. foreach (var data in RemoteRecipes)
  740. {
  741. if (data.TrayCode == 1)
  742. {
  743. if (!(RecipeQueue.Contains(data.RecipeCode)))
  744. {
  745. if (SiemensDevice.XL_Status is XL_Status_DB status)
  746. {
  747. if (GVL_SmallStation.SiemensSendRecipeStatus == 3)
  748. {
  749. GVL_SmallStation.SiemensSendRecipeStatus = 4;
  750. SiemensDevice.Siemens_PLC_S7.WriteString(2231, data.RecipeCode, 10);
  751. SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", true);
  752. MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},请求配料");
  753. }
  754. if (GVL_SmallStation.SiemensSendRecipeStatus == 4)
  755. {
  756. if (SiemensDevice.XL_Status.Dosing_Confirm)
  757. {
  758. GVL_SmallStation.SiemensSendRecipeStatus = 5;
  759. SiemensDevice.Siemens_PLC_S7.WriteString(2231, "", 10);
  760. SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", false);
  761. MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},配料信号复位");
  762. }
  763. }
  764. if (GVL_SmallStation.SiemensSendRecipeStatus == 5)
  765. {
  766. MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},西门子确认配料");
  767. if (SiemensDevice.XL_Status.Dosing_Confirm == false)
  768. {
  769. RecipeQueue.Enqueue(data.RecipeCode);
  770. GVL_SmallStation.SiemensSendRecipeStatus = 6;
  771. MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},加入队列");
  772. }
  773. }
  774. }
  775. }
  776. }
  777. else if (data.TrayCode == 2)
  778. {
  779. if (!(RecipeQueueTray2.Contains(data.RecipeCode)))
  780. {
  781. if (SiemensDevice.XL_Status is XL_Status_DB status)
  782. {
  783. if (GVL_SmallStation.SiemensSendRecipeStatus == 3)
  784. {
  785. GVL_SmallStation.SiemensSendRecipeStatus = 4;
  786. SiemensDevice.Siemens_PLC_S7.WriteString(2231, data.RecipeCode, 10);
  787. SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", true);
  788. }
  789. if (GVL_SmallStation.SiemensSendRecipeStatus == 4)
  790. {
  791. if (SiemensDevice.XL_Status.Dosing_Confirm)
  792. {
  793. GVL_SmallStation.SiemensSendRecipeStatus = 5;
  794. SiemensDevice.Siemens_PLC_S7.WriteString(2231, "", 10);
  795. SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", false);
  796. }
  797. }
  798. if (GVL_SmallStation.SiemensSendRecipeStatus == 5)
  799. {
  800. if (SiemensDevice.XL_Status.Dosing_Confirm == false)
  801. {
  802. GVL_SmallStation.SiemensSendRecipeStatus = 0;
  803. RecipeQueueTray2.Enqueue(data.RecipeCode);
  804. }
  805. }
  806. }
  807. }
  808. }
  809. }
  810. }
  811. else
  812. {
  813. RecipeQueue.Clear();
  814. RecipeQueueTray2.Clear();
  815. GVL_SmallStation.GetInstance.RecipeStatusID = 0;
  816. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
  817. }
  818. }
  819. else
  820. {
  821. RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  822. if (RemoteRecipes.Count > 0)
  823. {
  824. foreach (var data in RemoteRecipes)
  825. {
  826. if (data.TrayCode == 1)
  827. {
  828. if (!(RecipeQueue.Contains(data.RecipeCode)))
  829. {
  830. RecipeQueue.Enqueue(data.RecipeCode);
  831. }
  832. }
  833. else if (data.TrayCode == 2)
  834. {
  835. if (!(RecipeQueueTray2.Contains(data.RecipeCode)))
  836. {
  837. RecipeQueueTray2.Enqueue(data.RecipeCode);
  838. }
  839. }
  840. }
  841. }
  842. else
  843. {
  844. RecipeQueue.Clear();
  845. RecipeQueueTray2.Clear();
  846. GVL_SmallStation.GetInstance.DosingTray1 = false;
  847. GVL_SmallStation.GetInstance.DosingTray1Loc = 0;
  848. GVL_SmallStation.GetInstance.DosingTray2 = false;
  849. GVL_SmallStation.GetInstance.DosingTray2Loc = 0;
  850. GVL_SmallStation.GetInstance.RecipeStatusID = 0;
  851. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
  852. }
  853. }
  854. }
  855. /// <summary>
  856. /// 执行配方队列中的第一个配方
  857. /// </summary>
  858. private void RecipeInfoToHKPLC()
  859. {
  860. if (RecipeQueue.Count > 0 && GVL_SmallStation.TrayLogicFinish)
  861. {
  862. int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueue.ElementAt(0));
  863. if (index >= 0 && index < RemoteRecipes.Count)
  864. {
  865. string code = RemoteRecipes.ElementAt(index).RecipeCode;
  866. int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
  867. string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
  868. string windSend = RemoteRecipes.ElementAt(index).ToString();
  869. if (trayCode == 1)
  870. {
  871. if (GVL_SmallStation.GetInstance.RecipeStatusID == 0)
  872. {
  873. if (GVL_SmallStation.GetInstance.IsUseWindSend)
  874. {
  875. WindSendData.TargetRecipeCode = code;
  876. WindSendData.IsAllowDosing = true;
  877. foreach (var item in RemoteRecipes.ElementAt(index).WindSend)
  878. {
  879. if (item.RawMaterialName == "0037")
  880. {
  881. WindSendData.RawMaterial1_SetWeight = item.RawMaterialWeight;
  882. }
  883. if (item.RawMaterialName == "0038")
  884. {
  885. WindSendData.RawMaterial2_SetWeight = item.RawMaterialWeight;
  886. }
  887. if (item.RawMaterialName == "")
  888. {
  889. WindSendData.RawMaterial3_SetWeight = item.RawMaterialWeight;
  890. }
  891. if (item.RawMaterialName == "")
  892. {
  893. WindSendData.RawMaterial4_SetWeight = item.RawMaterialWeight;
  894. }
  895. if (item.RawMaterialName == "0036")
  896. {
  897. WindSendData.RawMaterial5_SetWeight = item.RawMaterialWeight;
  898. }
  899. }
  900. WindSendDevice.Siemens_PLC_S7.WriteClass<WindSend_Write>(WindSendData, 95);
  901. }
  902. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  903. {
  904. HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation);
  905. }
  906. HKDevice.HK_PLC_S7.Write("DB4.DBX1.3", true);
  907. GVL_SmallStation.GetInstance.RecipeStatusID = 1;
  908. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},下发完成");
  909. GVL_SmallStation.GetInstance.time1 = DateTime.Now;
  910. }
  911. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.3") && GVL_SmallStation.GetInstance.RecipeStatusID == 1)
  912. {
  913. HKDevice.HK_PLC_S7.Write("DB4.DBX1.3", false);
  914. GVL_SmallStation.GetInstance.RecipeStatusID = 2;
  915. MessageNotify.GetInstance.ShowRunLog($"托盘1,{ recipeName}plc端 配方接收完成");
  916. }
  917. if (GVL_SmallStation.GetInstance.RecipeStatusID == 2)
  918. {
  919. if (GVL_SmallStation.GetInstance.DosingTray1 == false && GVL_SmallStation.GetInstance.DosingTray1Loc == 0)
  920. {
  921. if (RTrig.GetInstance("DB3.DBX50.0").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.0")))
  922. {
  923. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD10");
  924. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},1号桶,{res}料仓,允许配料");
  925. if (res > 0 && res is float loc)
  926. {
  927. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  928. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight * 1000;//单位g转换kg
  929. if (loc_index >= 0)
  930. {
  931. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//根据料仓编号 启动并写入每个原料重量
  932. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  933. }
  934. GVL_SmallStation.GetInstance.DosingTray1 = true;
  935. GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
  936. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成");
  937. }
  938. }
  939. else if (RTrig.GetInstance("DB3.DBX50.1").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.1")))
  940. {
  941. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD14");
  942. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},2号桶,{res}料仓,允许配料");
  943. if (res > 0 && res is float loc)
  944. {
  945. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  946. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight * 1000;
  947. if (loc_index >= 0)
  948. {
  949. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
  950. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  951. }
  952. GVL_SmallStation.GetInstance.DosingTray1 = true;
  953. GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
  954. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成");
  955. }
  956. }
  957. else if (RTrig.GetInstance("DB3.DBX50.2").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.2")))
  958. {
  959. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD18");
  960. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},3号桶,{res}料仓,允许配料");
  961. if (res > 0 && res is float loc)
  962. {
  963. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  964. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight*1000;
  965. if (loc_index >= 0)
  966. {
  967. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
  968. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  969. }
  970. GVL_SmallStation.GetInstance.DosingTray1 = true;
  971. GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
  972. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成");
  973. }
  974. }
  975. else if (RTrig.GetInstance("DB3.DBX50.3").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.3")))
  976. {
  977. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD22");
  978. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},4号桶,{res}料仓,允许配料");
  979. if (res > 0 && res is float loc)
  980. {
  981. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  982. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight*1000;
  983. if (loc_index >= 0)
  984. {
  985. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
  986. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  987. }
  988. GVL_SmallStation.GetInstance.DosingTray1 = true;
  989. GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
  990. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成");
  991. }
  992. }
  993. }
  994. if (GVL_SmallStation.GetInstance.DosingTray1 && GVL_SmallStation.GetInstance.DosingTray1Loc > 0 && GVL_SmallStation.GetInstance.DosingTray1Loc < 16)
  995. {
  996. int i = GVL_SmallStation.GetInstance.DosingTray1Loc;
  997. if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)
  998. {
  999. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,配料完成");
  1000. int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  1001. RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.NowWeightFeedback;
  1002. bool info = DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  1003. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,下料完成重量:{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight}");
  1004. if (info)
  1005. {
  1006. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送成功");
  1007. }
  1008. else
  1009. {
  1010. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送失败");
  1011. }
  1012. if (i >= 1 && i <= 8)
  1013. {
  1014. string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true, 4);
  1015. MessageNotify.GetInstance.ShowRunLog(commInfo);
  1016. }
  1017. else if (i >= 9 && i <= 15)
  1018. {
  1019. string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true, 4);
  1020. MessageNotify.GetInstance.ShowRunLog(commInfo1);
  1021. }
  1022. GVL_SmallStation.GetInstance.DosingTray1 = false;
  1023. GVL_SmallStation.GetInstance.DosingTray1Loc = 0;
  1024. }
  1025. }
  1026. if ((RTrig.GetInstance("配方配料完成").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.1"))))
  1027. {
  1028. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  1029. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成");
  1030. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  1031. {
  1032. MessageNotify.GetInstance.ShowRunLog($"{item.RawMaterialName},下料重量:{item.Laying_Off_Weight}g");
  1033. }
  1034. if (SiemensDevice.IsConnected)
  1035. {
  1036. RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
  1037. RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
  1038. RecipeFinishInfo.Job_No = (short)trayCode;
  1039. for (int i = 0; i < 20; i++)
  1040. {
  1041. RecipeFinishInfo.Material[i] = new UDT1();
  1042. }
  1043. for (int i = 0; i < 10; i++)
  1044. {
  1045. RecipeFinishInfo.Powder[i] = new UDT2();
  1046. }
  1047. for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
  1048. {
  1049. RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1050. RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1051. RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight * (float)0.001;
  1052. }
  1053. for (int i = 0; i < RemoteRecipes.ElementAt(index).WindSend.Count; i++)
  1054. {
  1055. RecipeFinishInfo.Powder[i].Powder_Weight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(i).DosingCompleWeight;
  1056. }
  1057. if (GVL_SmallStation.SiemensSendRecipeStatus == 6)
  1058. {
  1059. double a = DateTime.Now.Subtract(GVL_SmallStation.GetInstance.time1).TotalSeconds;
  1060. GVL_SmallStation.SiemensSendRecipeStatus = 7;
  1061. RecipeFinishInfo.Ask_For_Finish = true;
  1062. RecipeFinishInfo.DosingTime = Convert.ToInt16(a);
  1063. SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
  1064. }
  1065. }
  1066. App.Current.Dispatcher.Invoke(() =>
  1067. {
  1068. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  1069. });
  1070. RecipeQueue.TryDequeue(out code);
  1071. HKDevice.HK_PLC_S7.Write("DB3.DBX1.1", false);
  1072. GVL_SmallStation.GetInstance.RecipeStatusID = 0;
  1073. }
  1074. }
  1075. }
  1076. }
  1077. }
  1078. if (RecipeQueueTray2.Count > 0 && GVL_SmallStation.Station2HaveTray)
  1079. {
  1080. int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueueTray2.ElementAt(0));
  1081. if (index >= 0 && index < RemoteRecipes.Count)
  1082. {
  1083. string code = RemoteRecipes.ElementAt(index).RecipeCode;
  1084. int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
  1085. string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
  1086. if (trayCode == 2)
  1087. {
  1088. if (GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 0)
  1089. {
  1090. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},初始化");
  1091. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  1092. {
  1093. HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation, 2);
  1094. }
  1095. HKDevice.HK_PLC_S7.Write("DB4.DBX1.4", true);
  1096. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 1;
  1097. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},下发完成");
  1098. }
  1099. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.4") && GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 1)
  1100. {
  1101. HKDevice.HK_PLC_S7.Write("DB3.DBX1.4", false);
  1102. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 2;
  1103. MessageNotify.GetInstance.ShowRunLog($"配方:{recipeName},plc端 配方接收完成");
  1104. }
  1105. if (GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 2)
  1106. {
  1107. if (RTrig.GetInstance("DB3.DBX50.4").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.4")))
  1108. {
  1109. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD26");
  1110. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{res}料仓,允许配料");
  1111. if (res > 0 && res is float loc)
  1112. {
  1113. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  1114. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  1115. if (loc_index >= 0)
  1116. {
  1117. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//根据料仓编号 启动并写入每个原料重量
  1118. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  1119. }
  1120. GVL_SmallStation.GetInstance.DosingTray2 = true;
  1121. GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
  1122. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成");
  1123. }
  1124. }
  1125. else if (RTrig.GetInstance("DB3.DBX50.5").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.5")))
  1126. {
  1127. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD30");
  1128. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},2号桶,{res}料仓,允许配料");
  1129. if (res > 0 && res is float loc)
  1130. {
  1131. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  1132. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  1133. if (loc_index >= 0)
  1134. {
  1135. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
  1136. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  1137. }
  1138. GVL_SmallStation.GetInstance.DosingTray2 = true;
  1139. GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
  1140. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成");
  1141. }
  1142. }
  1143. else if (RTrig.GetInstance("DB3.DBX50.6").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.6")))
  1144. {
  1145. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD34");
  1146. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},3号桶,{res}料仓,允许配料");
  1147. if (res > 0 && res is float loc)
  1148. {
  1149. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  1150. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  1151. if (loc_index >= 0)
  1152. {
  1153. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
  1154. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  1155. }
  1156. GVL_SmallStation.GetInstance.DosingTray2 = true;
  1157. GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
  1158. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成");
  1159. }
  1160. }
  1161. else if (RTrig.GetInstance("DB3.DBX50.7").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.7")))
  1162. {
  1163. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD38");
  1164. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},4号桶,{res}料仓,允许配料");
  1165. if (res > 0 && res is float loc)
  1166. {
  1167. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  1168. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  1169. if (loc_index >= 0)
  1170. {
  1171. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
  1172. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  1173. }
  1174. GVL_SmallStation.GetInstance.DosingTray2 = true;
  1175. GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
  1176. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成");
  1177. }
  1178. }
  1179. if (GVL_SmallStation.GetInstance.DosingTray2 == true && GVL_SmallStation.GetInstance.DosingTray1 == false && GVL_SmallStation.GetInstance.DosingTray2Loc > 0 && GVL_SmallStation.GetInstance.DosingTray2Loc < 16)
  1180. {
  1181. int i = GVL_SmallStation.GetInstance.DosingTray2Loc;
  1182. if (RTrig.GetInstance("Tray2StatusDevice" + i).Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3))
  1183. {
  1184. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{recipeName},{i}号仓,配料完成");
  1185. int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  1186. RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.NowWeightFeedback;
  1187. bool info = DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  1188. if (info)
  1189. {
  1190. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送成功");
  1191. }
  1192. else
  1193. {
  1194. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送失败");
  1195. }
  1196. if (i >= 1 && i <= 8)
  1197. {
  1198. string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true, 4);
  1199. MessageNotify.GetInstance.ShowRunLog(commInfo);
  1200. }
  1201. else if (i >= 9 && i <= 15)
  1202. {
  1203. string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true, 4);
  1204. MessageNotify.GetInstance.ShowRunLog(commInfo1);
  1205. }
  1206. GVL_SmallStation.GetInstance.DosingTray2 = false;
  1207. GVL_SmallStation.GetInstance.DosingTray2Loc = 0;
  1208. }
  1209. }
  1210. if (RTrig.GetInstance("DB3.DBX1.2").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.2")))
  1211. {
  1212. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  1213. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方{res.RecipeName},配料完成");
  1214. RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
  1215. RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
  1216. for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
  1217. {
  1218. RecipeFinishInfo.Material[i] = new UDT1();
  1219. RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1220. RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1221. RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight;
  1222. }
  1223. if (SiemensDevice.IsConnected)
  1224. {
  1225. RecipeFinishInfo.Ask_For_Finish = true;
  1226. SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
  1227. }
  1228. App.Current.Dispatcher.Invoke(() =>
  1229. {
  1230. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  1231. });
  1232. RecipeQueueTray2.TryDequeue(out code);
  1233. HKDevice.HK_PLC_S7.Write("DB3.DBX1.2", false);
  1234. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
  1235. }
  1236. }
  1237. }
  1238. }
  1239. }
  1240. }
  1241. private void StockBinInit()
  1242. {
  1243. for (int i = 1; i < 16; i++)
  1244. {
  1245. if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)
  1246. {
  1247. DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  1248. }
  1249. }
  1250. }
  1251. private void DosingDevice(int Index,int DeviceID)
  1252. {
  1253. if (RTrig.GetInstance("Tray2StatusDevice" + DeviceID).Start(DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.RunStatus == 3))
  1254. {
  1255. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{RemoteRecipes.ElementAt(Index).RecipeName},{DeviceID}号仓,配料完成");
  1256. int res = Array.FindIndex(RemoteRecipes.ElementAt(Index).RawMaterial.ToArray(), p => p.RawMaterialLocation == DeviceID);
  1257. RemoteRecipes.ElementAt(Index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.CutWeightFeedback;
  1258. DeviceInquire.GetInstance.GetDevice(DeviceID).StatusReset();
  1259. if (DeviceID >= 1 && DeviceID <= 8)
  1260. {
  1261. HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (DeviceID - 1), true);
  1262. }
  1263. else if (DeviceID >= 9 && DeviceID <= 15)
  1264. {
  1265. HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (DeviceID - 9), true);
  1266. }
  1267. }
  1268. }
  1269. private void testData()
  1270. {
  1271. RawMaterialsNamePos.Add("0051", 3);
  1272. RawMaterialsNamePos.Add("0052", 4);
  1273. RawMaterialsNamePos.Add("0054", 5);
  1274. RawMaterialsNamePos.Add("0057", 6);
  1275. RawMaterialsNamePos.Add("0050", 8);
  1276. RawMaterialsNamePos.Add("0048", 13);
  1277. RawMaterialsNamePos.Add("0036", 13);//I+G
  1278. RawMaterialsNamePos.Add("0037", 13);//味精
  1279. RawMaterialsNamePos.Add("0038", 13);//白糖
  1280. }
  1281. public short SetBitValue(short data, byte offset, bool val)
  1282. {
  1283. if (offset > 16 || offset < 1)
  1284. {
  1285. return data;
  1286. }
  1287. short num = (short)(1 << offset - 1);
  1288. return (short)(val ? (data | num) : (data & ~num));
  1289. }
  1290. }
  1291. }