终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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