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

1666 lines
100 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.JXJFoodSmallStation.Model.GVL;
  4. using BPASmartClient.JXJFoodSmallStation.Model.HK_PLC;
  5. using BPASmartClient.JXJFoodSmallStation.Model.RawMaterial;
  6. using BPASmartClient.JXJFoodSmallStation.Model.Siemens;
  7. using BPASmartClient.JXJFoodSmallStation.Model.WindSend;
  8. using BPASmartClient.Modbus;
  9. using System;
  10. using System.Collections.Concurrent;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Configuration;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Text;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. namespace BPASmartClient.JXJFoodSmallStation.Model
  20. {
  21. public class ProcessControl
  22. {
  23. private volatile static ProcessControl _Instance;
  24. public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
  25. private ProcessControl() { }
  26. /// <summary>
  27. /// 配方数据
  28. /// </summary>
  29. public ObservableCollection<RemoteRecipeData> RemoteRecipes = new ObservableCollection<RemoteRecipeData>();
  30. /// <summary>
  31. /// 原料的名称和料仓的位置对应
  32. /// </summary>
  33. public Dictionary<string, short> RawMaterialsNamePos = new Dictionary<string, short>();
  34. public ObservableCollection<RawMaterialStockBin> RawMaterialsInfo => Json<DevicePar>.Data.rawMaterialStockBin;
  35. /// <summary>
  36. /// 配方队列
  37. /// </summary>
  38. public ConcurrentQueue<string> RecipeQueueTray1 = new ConcurrentQueue<string>();
  39. /// <summary>
  40. /// 物料集合
  41. /// </summary>
  42. public Dictionary<int, ConcurrentQueue<string>> RecipeQueueTray { get; set; } = new Dictionary<int, ConcurrentQueue<string>>();
  43. public ConcurrentQueue<string> RecipeQueueTray2 = new ConcurrentQueue<string>();
  44. public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
  45. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  46. public WindSendDeviceStatus WindSendDevice = new WindSendDeviceStatus();
  47. public ObservableCollection<PlcInfos> CommData { get; set; } = new ObservableCollection<PlcInfos>();
  48. public ObservableCollection<PlcInfos> ProcessVar { get; set; } = new ObservableCollection<PlcInfos>();
  49. XL_Finish_DB RecipeFinishInfo = new XL_Finish_DB();
  50. /// <summary>
  51. /// 风送PLC的DB块
  52. /// </summary>
  53. WindSend_Write WindSendData = new WindSend_Write();
  54. /// <summary>
  55. /// 接收原料数据
  56. /// </summary>
  57. public RecipeRawMaterial RawMaterial;
  58. public DateTime StockBinAlarmTime = DateTime.Now;
  59. public string? HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
  60. public string? Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
  61. public string? WindSend_PLC_IP = ConfigurationManager.AppSettings["WindSend_IP"];
  62. public void Init()
  63. {
  64. RecipeQueueTray.TryAdd(0, new ConcurrentQueue<string>());
  65. RecipeQueueTray.TryAdd(1, new ConcurrentQueue<string>());
  66. RecipeQueueTray.TryAdd(2, new ConcurrentQueue<string>());
  67. RecipeQueueTray.TryAdd(3, new ConcurrentQueue<string>());
  68. RecipeQueueTray.TryAdd(4, new ConcurrentQueue<string>());
  69. PlcVarMonitor();
  70. StockBinNameWithPos();
  71. RawMaterialNameWithCode();
  72. RegisterInit();
  73. DeviceConnect();
  74. //Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
  75. ThreadManage.GetInstance().StartLong(new Action(() =>
  76. {
  77. GVL_SmallStation.GetInstance.DisEnableStockAlarm = Json<DevicePar>.Data.deviceConnectPar.ShieldStockbinAlarm;
  78. if (HKDevice.IsConnected)
  79. {
  80. GVL_SmallStation.GetInstance.HeartBeatToPlc = !GVL_SmallStation.GetInstance.HeartBeatToPlc;
  81. HKDevice.HK_PLC_S7.Write("DB4.DBX0.0", GVL_SmallStation.GetInstance.HeartBeatToPlc);
  82. GVL_SmallStation.GetInstance.HeartBeatFromPlc = HKDevice.HK_PLC_S7.Read<bool>("DB45.DBX0.0");
  83. if (DeviceInquire.GetInstance.devices.Count < 15 && HKDevice.IsConnected && Json<RemoteRecipeDataColl>.Data.Recipes.Count > 0 && GVL_SmallStation.GetInstance.DisEnableStockBinAlarm == false && DateTime.Now.Subtract(StockBinAlarmTime).TotalSeconds >= 60 & !GVL_SmallStation.GetInstance.DisEnableStockAlarm)
  84. {
  85. HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", true);
  86. App.Current.Dispatcher.Invoke(() =>
  87. {
  88. MessageNotify.GetInstance.ShowDialog($"未读取到15个柔性味魔方料仓", DialogType.Error);
  89. StockBinAlarmTime = DateTime.Now;
  90. });
  91. HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", false);
  92. }
  93. }
  94. Thread.Sleep(200);
  95. }), "海科plc通信心跳", true);
  96. ThreadManage.GetInstance().StartLong(new Action(() =>
  97. {
  98. if (GVL_SmallStation.GetInstance.Order_Cancel)
  99. {
  100. CancelOrder();//订单取消,不执行配方流程
  101. }
  102. else
  103. {
  104. ReceviceData();//配方请求
  105. RecipeInfoToHKPLC();//配方配料
  106. }
  107. Thread.Sleep(10);
  108. }), "小料站流程控制", true);
  109. ThreadManage.GetInstance().StartLong(new Action(() =>
  110. {
  111. RealTimeData();
  112. foreach (var item in Json<DevicePar>.Data.windSendRawMaterial)
  113. {
  114. if (GVL_SmallStation.GetInstance.RawMaterialsNameCode.ContainsKey(item.RawMaterialName))
  115. {
  116. item.RawMaterialChineseName = GVL_SmallStation.GetInstance.RawMaterialsNameCode[item.RawMaterialName];
  117. }
  118. else
  119. {
  120. item.RawMaterialChineseName = "";
  121. }
  122. }
  123. Thread.Sleep(10);
  124. }), "西门子PLC和小料站PLC的实时数据交互流程", true);
  125. ThreadManage.GetInstance().StartLong(new Action(() =>
  126. {
  127. HKPlcRead();
  128. GetStatus();
  129. Thread.Sleep(10);
  130. }), "海科PLC实时数据", true);
  131. }
  132. /// <summary>
  133. /// 气缸的传感器值
  134. /// </summary>
  135. private void GetStatus()
  136. {
  137. for (int i = 0; i < 8; i++)
  138. {
  139. GVL_SmallStation.GetInstance.Cylinder_JackInfo[i] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX0." + i);
  140. }
  141. for (int i = 0; i < 7; i++)
  142. {
  143. GVL_SmallStation.GetInstance.Cylinder_JackInfo[i + 8] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX1." + i);
  144. }
  145. GVL_SmallStation.GetInstance.Cylinder_JackInfo[20] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX3.6");//进料桶气缸
  146. GVL_SmallStation.GetInstance.Cylinder_JackInfo[21] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX3.7");//出料筒气缸1
  147. GVL_SmallStation.GetInstance.Cylinder_JackInfo[22] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.0");//出料筒气缸2
  148. GVL_SmallStation.GetInstance.Cylinder_JackInfo[23] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.1");//出料筒气缸3
  149. GVL_SmallStation.GetInstance.Cylinder_JackInfo[24] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.2");//托盘1_1气缸
  150. GVL_SmallStation.GetInstance.Cylinder_JackInfo[25] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.3");//托盘1_2气缸
  151. GVL_SmallStation.GetInstance.Cylinder_JackInfo[26] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.4");//托盘2_1气缸
  152. GVL_SmallStation.GetInstance.Cylinder_JackInfo[27] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.5");//托盘2_2气缸
  153. }
  154. /// <summary>
  155. /// DB块的变量实时值
  156. /// </summary>
  157. private void HKPlcRead()
  158. {
  159. if (HKDevice.IsConnected)
  160. {
  161. foreach (PropertyInfo item in typeof(PlcReadAddressDB3).GetProperties())
  162. {
  163. int index = Array.FindIndex(CommData.ToArray(), p => p.Name == item.Name);
  164. if (index >= 0)
  165. {
  166. if (item.PropertyType.IsArray)
  167. {
  168. CommData.ElementAt(index).Value = "";
  169. Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null);
  170. foreach (var values in array)
  171. {
  172. string data = values.ToString();
  173. if (data.ToLower() == "false")
  174. data = "0";
  175. if (data.ToLower() == "true")
  176. data = "1";
  177. CommData.ElementAt(index).Value = CommData.ElementAt(index).Value + data + ",";
  178. }
  179. }
  180. else
  181. {
  182. CommData.ElementAt(index).Value = GVL_SmallStation.GetInstance.plcReadDataDB3.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null).ToString();
  183. }
  184. }
  185. }
  186. }
  187. if (WindSendDevice.IsConnected)
  188. {
  189. foreach (PropertyInfo item in typeof(WindSend_Write).GetProperties())
  190. {
  191. int index = Array.FindIndex(CommData.ToArray(), p => p.Name == item.Name);
  192. if (index >= 0)
  193. {
  194. if (item.PropertyType.IsArray)
  195. {
  196. CommData.ElementAt(index).Value = "";
  197. Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null);
  198. foreach (var values in array)
  199. {
  200. string data = values.ToString();
  201. if (data.ToLower() == "false")
  202. data = "0";
  203. if (data.ToLower() == "true")
  204. data = "1";
  205. CommData.ElementAt(index).Value = CommData.ElementAt(index).Value + data + ",";
  206. }
  207. }
  208. else
  209. {
  210. CommData.ElementAt(index).Value = GVL_SmallStation.GetInstance.WindSendDB95.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance.WindSendDB95, null).ToString();
  211. }
  212. }
  213. }
  214. foreach (PropertyInfo item in typeof(WindSend_Read).GetProperties())
  215. {
  216. int index = Array.FindIndex(CommData.ToArray(), p => p.Name == item.Name);
  217. if (index >= 0)
  218. {
  219. if (item.PropertyType.IsArray)
  220. {
  221. CommData.ElementAt(index).Value = "";
  222. Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null);
  223. foreach (var values in array)
  224. {
  225. string data = values.ToString();
  226. if (data.ToLower() == "false")
  227. data = "0";
  228. if (data.ToLower() == "true")
  229. data = "1";
  230. CommData.ElementAt(index).Value = CommData.ElementAt(index).Value + data + ",";
  231. }
  232. }
  233. else
  234. {
  235. CommData.ElementAt(index).Value = GVL_SmallStation.GetInstance.WindSendDB94.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance.WindSendDB94, null).ToString();
  236. }
  237. }
  238. }
  239. }
  240. foreach (PropertyInfo item in typeof(GVL_SmallStation).GetProperties())
  241. {
  242. int index = Array.FindIndex(ProcessVar.ToArray(), p => p.Name == item.Name);
  243. if (index >= 0)
  244. {
  245. if (item.PropertyType.IsArray)
  246. {
  247. ProcessVar.ElementAt(index).Value = "";
  248. Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance, null);
  249. foreach (var values in array)
  250. {
  251. string data = values.ToString();
  252. if (data.ToLower() == "false")
  253. data = "0";
  254. if (data.ToLower() == "true")
  255. data = "1";
  256. ProcessVar.ElementAt(index).Value = ProcessVar.ElementAt(index).Value + data + ",";
  257. }
  258. }
  259. else
  260. {
  261. ProcessVar.ElementAt(index).Value = GVL_SmallStation.GetInstance.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance, null).ToString();
  262. }
  263. }
  264. }
  265. }
  266. /// <summary>
  267. /// 小料站和西门子PLC之间的实时数据
  268. /// </summary>
  269. private void RealTimeData()
  270. {
  271. if (HKDevice.IsConnected)
  272. {
  273. //获取系统状态
  274. GVL_SmallStation.GetInstance.PlcSystemIsAutoRun = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.0");//系统启停
  275. GVL_SmallStation.GetInstance.PlcSystemMode = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.1");//系统模式
  276. GVL_SmallStation.GetInstance.PlcSystemIsPause = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.2");//系统暂停
  277. GVL_SmallStation.GetInstance.Station1HaveTray = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.0");//工站1 有货架
  278. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[0] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.0");
  279. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[1] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.1");
  280. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[2] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.2");
  281. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[3] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.3");
  282. GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[4] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.4");
  283. if (GVL_SmallStation.GetInstance.WindSendDosingComple)
  284. {
  285. //HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.7", true);
  286. HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX4.0", true);
  287. GVL_SmallStation.GetInstance.WindSendDosingComple = false;
  288. MessageNotify.GetInstance.ShowRunLog("风送配料完成信号,发给产线plc信号");
  289. }
  290. //if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.1"))
  291. //{
  292. // HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.7", false);
  293. //}
  294. /*if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.7"))//允许下配方1或者允许下配方2
  295. {
  296. GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe = true;
  297. }*/
  298. //for (int i = 0; i < 5; i++)
  299. //{
  300. // if (GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[i] && RecipeQueueTray[i].Count == 0)
  301. // {
  302. // GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe = true;
  303. // }
  304. //}
  305. //GVL_SmallStation.GetInstance.Station1Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.1");
  306. //GVL_SmallStation.GetInstance.Station2Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.2");
  307. //GVL_SmallStation.GetInstance.Station1Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.3");
  308. //GVL_SmallStation.GetInstance.Station2Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.4");
  309. //GVL_SmallStation.GetInstance.RobotStatus = HKDevice.HK_PLC_S7.Read<ushort>("DB3.DBW100");
  310. //GVL_SmallStation.GetInstance.RobotProgramNum = HKDevice.HK_PLC_S7.Read<byte>("DB3.DBB102");
  311. if (Json<RemoteRecipeDataColl>.Data.Recipes.Count <= 3)
  312. {
  313. GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe = true;
  314. }
  315. GVL_SmallStation.GetInstance.Station1Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.1");
  316. GVL_SmallStation.GetInstance.Station1Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.2");
  317. GVL_SmallStation.GetInstance.RobotStatus = HKDevice.HK_PLC_S7.Read<byte>("DB3.DBB0");
  318. GVL_SmallStation.GetInstance.RobotProgramNum = HKDevice.HK_PLC_S7.Read<byte>("DB3.DBB1");
  319. }
  320. if (SiemensDevice.IsConnected)
  321. {
  322. ushort TrayCylinder = 0;
  323. ushort TraySensor = 0;
  324. if (GVL_SmallStation.GetInstance.Station1Sensor)
  325. {
  326. TraySensor = TraySensor.SetBitValue(1, true);
  327. }
  328. else
  329. {
  330. TraySensor = TraySensor.SetBitValue(0, false);
  331. }
  332. if (!GVL_SmallStation.GetInstance.Station1Cylinder)
  333. {
  334. TrayCylinder = TrayCylinder.SetBitValue(1, true);
  335. }
  336. else
  337. {
  338. TrayCylinder = TrayCylinder.SetBitValue(0, false);
  339. }
  340. this.SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2231.DBX28.4", GVL_SmallStation.GetInstance.WindSendAllowAGVPutGet);
  341. this.SiemensDevice.Siemens_PLC_S7.Write<ushort>("DB2231.DBW190", TraySensor);//添加工位传感器的信号
  342. this.SiemensDevice.Siemens_PLC_S7.Write<ushort>("DB2231.DBW192", TrayCylinder);//添加工位气缸的信号
  343. ushort AGV_Put = (ushort)SiemensDevice.XL_Status.AgvFinishPut;
  344. if (AGV_Put.Get16bitValue(1))
  345. {
  346. GVL_SmallStation.GetInstance.AGV_PutTray1Finish = true;
  347. }
  348. else
  349. {
  350. GVL_SmallStation.GetInstance.AGV_PutTray1Finish = false;
  351. }
  352. ushort AGV_Get = (ushort)SiemensDevice.XL_Status.AgvFinishGet;
  353. if (AGV_Get.Get16bitValue(1))
  354. {
  355. GVL_SmallStation.GetInstance.AGV_GetTray1Finish = true;
  356. }
  357. else
  358. {
  359. GVL_SmallStation.GetInstance.AGV_GetTray1Finish = false;
  360. }
  361. }
  362. }
  363. public void CancelOrder()
  364. {
  365. if (GVL_SmallStation.GetInstance.Order_Cancel) //订单取消
  366. {
  367. if (!string.IsNullOrEmpty(GVL_SmallStation.GetInstance.Order_CancelRecipeCode))
  368. {
  369. string code = GVL_SmallStation.GetInstance.Order_CancelRecipeCode;
  370. int index = Array.FindIndex(Json<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == code);
  371. int[] cnt = new int[5] { -1, -1, -1, -1, -1 };
  372. int index1 = -1;
  373. for (int i = 0; i < 5; i++)
  374. {
  375. cnt[i] = Array.FindIndex(RecipeQueueTray[i].ToArray(), p => p == code);
  376. if (cnt[i] >= 0)
  377. {
  378. index1 = i;
  379. }
  380. }
  381. switch (GVL_SmallStation.GetInstance.OrderCancelStep)
  382. {
  383. case 0://前提条件判断
  384. if (index == -1)
  385. {
  386. GVL_SmallStation.GetInstance.OrderCancelStep = 30;
  387. MessageNotify.GetInstance.ShowRunLog($"配方中并未找到订单{code}");
  388. }
  389. else
  390. {
  391. if (index1 >= 0)
  392. {
  393. GVL_SmallStation.GetInstance.OrderCancelStep = 1;
  394. }
  395. else
  396. {
  397. GVL_SmallStation.GetInstance.OrderCancelStep = 20;
  398. }
  399. }
  400. break;
  401. //Case 1-9为
  402. case 1:
  403. if (GVL_SmallStation.GetInstance.RecipeProcessStatus[index] != 0)
  404. {
  405. GVL_SmallStation.GetInstance.RecipeProcessStatus[index] = 0;
  406. HKDevice.HK_PLC_S7.Write("DB4.DBX6." + index1, true);
  407. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,正在取消订单:{code}");
  408. GVL_SmallStation.GetInstance.OrderCancelStep = 2;
  409. }
  410. else
  411. {
  412. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
  413. GVL_SmallStation.GetInstance.OrderCancelStep = 3;
  414. }
  415. break;
  416. case 2:
  417. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX42." + index1))
  418. {
  419. if (GVL_SmallStation.GetInstance.Station1Cylinder == false)
  420. {
  421. GVL_SmallStation.GetInstance.OrderCancelStep = 3;
  422. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
  423. }
  424. }
  425. break;
  426. case 3:
  427. SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", true);
  428. GVL_SmallStation.GetInstance.OrderCancelStep = 4;
  429. break;
  430. case 4:
  431. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2201.DBX440.1") == false)
  432. {
  433. SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", false);
  434. GVL_SmallStation.GetInstance.OrderCancelStep = 9;
  435. MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
  436. }
  437. break;
  438. case 9:
  439. App.Current.Dispatcher.Invoke(() =>
  440. {
  441. Json<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);
  442. });
  443. RecipeQueueTray1.TryDequeue(out code);
  444. GVL_SmallStation.GetInstance.RecipeProcessStatus[index] = 0;
  445. GVL_SmallStation.GetInstance.Order_Cancel = false;
  446. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
  447. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  448. break;
  449. case 20:
  450. SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", true);
  451. GVL_SmallStation.GetInstance.OrderCancelStep = 21;
  452. break;
  453. case 21:
  454. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2201.DBX440.1") == false)
  455. {
  456. SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", false);
  457. GVL_SmallStation.GetInstance.OrderCancelStep = 29;
  458. MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
  459. }
  460. break;
  461. case 29:
  462. App.Current.Dispatcher.Invoke(() =>
  463. {
  464. Json<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);
  465. });
  466. GVL_SmallStation.GetInstance.Order_Cancel = false;
  467. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
  468. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
  469. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  470. break;
  471. //30-39为订单还未下发至上位机
  472. case 30:
  473. SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", true);
  474. GVL_SmallStation.GetInstance.OrderCancelStep = 31;
  475. break;
  476. case 31:
  477. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2201.DBX440.1") == false)
  478. {
  479. SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", false);
  480. GVL_SmallStation.GetInstance.OrderCancelStep = 39;
  481. MessageNotify.GetInstance.ShowRunLog($"西门子取消订单完成,订单号:{code}");
  482. }
  483. break;
  484. case 39:
  485. GVL_SmallStation.GetInstance.Order_Cancel = false;
  486. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
  487. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  488. break;
  489. }
  490. }
  491. }
  492. }
  493. /// <summary>
  494. /// 将配方添加到配方队列中
  495. /// </summary>
  496. private void ReceviceData()
  497. {
  498. if (!GVL_SmallStation.GetInstance.IsUseLocalRecipe)
  499. {
  500. RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  501. if (RemoteRecipes.Count > 0)
  502. {
  503. foreach (var data in RemoteRecipes)
  504. {
  505. if (data.TrayCode == 1)
  506. {
  507. if (SiemensDevice.XL_Status is XL_Status_DB status)
  508. {
  509. switch (GVL_SmallStation.GetInstance.SiemensSendRecipeStatus)
  510. {
  511. case 3:
  512. SiemensDevice.Siemens_PLC_S7.WriteString(2231, data.RecipeCode, 10);
  513. SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", true);
  514. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 4;
  515. MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},请求配料");
  516. break;
  517. case 4:
  518. if (SiemensDevice.XL_Status.Dosing_Confirm)
  519. {
  520. SiemensDevice.Siemens_PLC_S7.WriteString(2231, "", 10);//复位字符串
  521. SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", false);
  522. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 5;
  523. MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},西门子确认配料");
  524. }
  525. break;
  526. case 5:
  527. if (SiemensDevice.XL_Status.Dosing_Confirm == false)
  528. {
  529. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 6;
  530. MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},西门子确认配料信号复位完成");
  531. }
  532. break;
  533. case 6:
  534. for (int i = 0; i < 5; i++)
  535. {
  536. if (GVL_SmallStation.GetInstance.NotUseSmallStation)
  537. {
  538. if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
  539. {
  540. RecipeQueueTray[i].Enqueue(data.RecipeCode);
  541. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
  542. MessageNotify.GetInstance.ShowRunLog($"西门子配方配料 ,不使用小料配料,配方{data.RecipeCode},加入配方{i}");
  543. }
  544. }
  545. else if (GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[i])
  546. {
  547. if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
  548. {
  549. RecipeQueueTray[i].Enqueue(data.RecipeCode);
  550. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
  551. MessageNotify.GetInstance.ShowRunLog($"西门子配方配料 ,等待plc允许配料,配方{data.RecipeCode},加入配方{i}");
  552. }
  553. }
  554. }
  555. break;
  556. default:
  557. break;
  558. }
  559. }
  560. }
  561. }
  562. }
  563. else
  564. {
  565. for (int i = 0; i < 5; i++)
  566. {
  567. RecipeQueueTray[i].Clear();
  568. GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0;
  569. }
  570. GVL_SmallStation.GetInstance.WindSendDosingStatus = 0;
  571. GVL_SmallStation.GetInstance.WindSendDosing = false;
  572. }
  573. }
  574. else
  575. {
  576. RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  577. if (RemoteRecipes.Count > 0)
  578. {
  579. foreach (var data in RemoteRecipes)
  580. {
  581. if (data.TrayCode == 1)
  582. {
  583. for (int i = 0; i < 5; i++)
  584. {
  585. if (GVL_SmallStation.GetInstance.NotUseSmallStation)
  586. {
  587. if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
  588. {
  589. RecipeQueueTray[i].Enqueue(data.RecipeCode);
  590. MessageNotify.GetInstance.ShowRunLog($"本地配方配料 ,不使用小料配料,配方{data.RecipeCode},加入配方{i}");
  591. }
  592. }
  593. else if (GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[i])
  594. {
  595. if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
  596. {
  597. RecipeQueueTray[i].Enqueue(data.RecipeCode);
  598. MessageNotify.GetInstance.ShowRunLog($"本地配方配料 ,等待plc允许配料,配方{data.RecipeCode},加入配方{i}");
  599. }
  600. }
  601. }
  602. }
  603. }
  604. }
  605. else
  606. {
  607. for (int i = 0; i < 5; i++)
  608. {
  609. RecipeQueueTray[i].Clear();
  610. GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0;
  611. }
  612. GVL_SmallStation.GetInstance.WindSendDosingStatus = 0;
  613. GVL_SmallStation.GetInstance.WindSendDosing = false;
  614. }
  615. }
  616. }
  617. /// <summary>
  618. /// 小料站配料
  619. /// </summary>
  620. private void RecipeInfoToHKPLC()
  621. {
  622. if (!GVL_SmallStation.GetInstance.NotUseSmallStation)
  623. {
  624. for (int i = 0; i < 5; i++)
  625. {
  626. switch (GVL_SmallStation.GetInstance.Tray_AGVLogic[i])
  627. {
  628. case 0:
  629. if (GVL_SmallStation.GetInstance.AGV_PutTray1Finish && (RecipeQueueTray[i].Count > 0) && GVL_SmallStation.GetInstance.AGVIsGetTray == false)
  630. {
  631. GVL_SmallStation.GetInstance.AGVIsGetTray = true;
  632. HKDevice.HK_PLC_S7.Write("DB4.DBX8." + i, true);
  633. GVL_SmallStation.GetInstance.AGV_PutTray1Finish = false;
  634. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 1;
  635. MessageNotify.GetInstance.ShowRunLog("AGV到位 发送到位信号给plc");
  636. }
  637. break;
  638. case 1:
  639. if (GVL_SmallStation.GetInstance.Station1HaveTray)
  640. {
  641. HKDevice.HK_PLC_S7.Write("DB4.DBX8." + i, false);
  642. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 2;
  643. MessageNotify.GetInstance.ShowRunLog("托盘1有货架");
  644. }
  645. break;
  646. case 2:
  647. if (GVL_SmallStation.GetInstance.AGV_GetTray1Finish && GVL_SmallStation.GetInstance.RecipeProcessStatus[i] == 0)
  648. {
  649. GVL_SmallStation.GetInstance.AGVIsGetTray = false;
  650. HKDevice.HK_PLC_S7.Write("DB4.DBX10." + i, true);
  651. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 3;
  652. MessageNotify.GetInstance.ShowRunLog("AGV取托盘1完成,发送给海科信号后1s后复位");
  653. }
  654. break;
  655. case 3:
  656. if (HKDevice.HK_PLC_S7.Read<bool>("DB4.DBX10." + i) == true)
  657. {
  658. Thread.Sleep(1000);
  659. HKDevice.HK_PLC_S7.Write("DB4.DBX10." + i, false);
  660. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 0;
  661. GVL_SmallStation.GetInstance.AGV_GetTray1Finish = false;
  662. MessageNotify.GetInstance.ShowRunLog("AGV取托盘1完成,信号复位");
  663. }
  664. break;
  665. default:
  666. break;
  667. }
  668. }
  669. }
  670. foreach (var recipe in RecipeQueueTray)
  671. {
  672. int recipeNum = recipe.Key;
  673. if (RecipeQueueTray[recipeNum].Count > 0)
  674. {
  675. int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueueTray[recipeNum].ElementAt(0));
  676. if (index >= 0 && index < RemoteRecipes.Count)
  677. {
  678. string code = RemoteRecipes.ElementAt(index).RecipeCode;
  679. int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
  680. string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
  681. string windSend = RemoteRecipes.ElementAt(index).ToString();
  682. if (trayCode == 1)
  683. {
  684. if (GVL_SmallStation.GetInstance.NotUseSmallStation)
  685. {
  686. if (GVL_SmallStation.GetInstance.AGV_PutTray1Finish)
  687. {
  688. Thread.Sleep(5000);
  689. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  690. if (SiemensDevice.IsConnected && !GVL_SmallStation.GetInstance.IsUseLocalRecipe)
  691. {
  692. RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
  693. RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
  694. RecipeFinishInfo.Job_No = (short)trayCode;
  695. for (int i = 0; i < 20; i++)
  696. {
  697. RecipeFinishInfo.Material[i] = new UDT1();
  698. }
  699. for (int i = 0; i < 10; i++)
  700. {
  701. RecipeFinishInfo.Powder[i] = new UDT2();
  702. }
  703. for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
  704. {
  705. RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  706. RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  707. RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight * (float)0.001;
  708. }
  709. for (int i = 0; i < RemoteRecipes.ElementAt(index).WindSend.Count; i++)
  710. {
  711. RecipeFinishInfo.Powder[i].Powder_Weight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(i).DosingCompleWeight;
  712. }
  713. RecipeFinishInfo.Ask_For_Finish = true;
  714. RecipeFinishInfo.DosingTime = Convert.ToInt16(0);
  715. SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
  716. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据反馈给西门子");
  717. }
  718. else
  719. {
  720. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据无法反馈给西门子,西门子设备未连接或处于本地配方");
  721. }
  722. GVL_SmallStation.GetInstance.WindSendDosing = false;
  723. App.Current.Dispatcher.Invoke(() =>
  724. {
  725. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  726. });
  727. RecipeQueueTray[recipeNum].TryDequeue(out code);
  728. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
  729. GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0;
  730. }
  731. }
  732. else
  733. {
  734. //粉料仓下发配方
  735. if (GVL_SmallStation.GetInstance.IsUseWindSend && GVL_SmallStation.GetInstance.WindSendDosing == false /*&& GVL_SmallStation.GetInstance.Tray_AGVLogic[recipeNum] == 2*/)
  736. {
  737. if (WindSendDevice.IsConnected)
  738. {
  739. if (GVL_SmallStation.GetInstance.WindSendDosingStatus == 1)
  740. {
  741. WindSend_Write WindSendData111 = new WindSend_Write();
  742. WindSendDevice.Siemens_PLC_S7.WriteClass<WindSend_Write>(WindSendData111, 95);
  743. Thread.Sleep(200);
  744. WindSendData111.TargetRecipeCode = code;
  745. WindSendData111.IsAllowDosing = true;
  746. foreach (var item in RemoteRecipes.ElementAt(index).WindSend)
  747. {
  748. if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(0).RawMaterialName || item.Location == 1)
  749. {
  750. WindSendData111.RawMaterial1_SetWeight = item.RawMaterialWeight;
  751. MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
  752. }
  753. if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(1).RawMaterialName || item.Location == 2)
  754. {
  755. WindSendData111.RawMaterial2_SetWeight = item.RawMaterialWeight;
  756. MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
  757. }
  758. if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(2).RawMaterialName || item.Location == 3)
  759. {
  760. WindSendData111.RawMaterial3_SetWeight = item.RawMaterialWeight;
  761. MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
  762. }
  763. if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(3).RawMaterialName || item.Location == 4)
  764. {
  765. WindSendData111.RawMaterial4_SetWeight = item.RawMaterialWeight;
  766. MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
  767. }
  768. if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(4).RawMaterialName || item.Location == 5)
  769. {
  770. WindSendData111.RawMaterial5_SetWeight = item.RawMaterialWeight;
  771. MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
  772. }
  773. }
  774. GVL_SmallStation.GetInstance.WindSendDosing = true;
  775. GVL_SmallStation.GetInstance.WindSendDosingStatus = 2;
  776. WindSendDevice.Siemens_PLC_S7.WriteClass<WindSend_Write>(WindSendData111, 95);
  777. }
  778. }
  779. else
  780. {
  781. if (Delay.GetInstance("delayTime").Start(true,60))
  782. {
  783. Delay.GetInstance("delayTime").Start(false, 60);
  784. MessageNotify.GetInstance.ShowRunLog($"风送设备PLC未连接");
  785. }
  786. }
  787. }
  788. if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 0)
  789. {
  790. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
  791. HKDevice.IssueRecipeToPlc(RemoteRecipes.ElementAt(index).RawMaterial, recipeNum);
  792. HKDevice.HK_PLC_S7.Write("DB4.DBX2." + recipeNum, true);
  793. GVL_SmallStation.GetInstance.DosingTime[recipeNum] = DateTime.Now;
  794. GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 1;
  795. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号{code},配方号{recipeNum + 1},下发完成");
  796. }
  797. bool recipeReceviceFinish = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX4." + recipeNum);
  798. if (recipeReceviceFinish && GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 1)
  799. {
  800. HKDevice.HK_PLC_S7.Write("DB4.DBX2." + recipeNum, false);
  801. GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 2;
  802. GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = 0;
  803. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号{code},配方号{recipeNum + 1},配方接收完成");
  804. }
  805. if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 2)
  806. {
  807. for (byte i = 1; i < 16; i++)
  808. {
  809. int indexArr = -1;
  810. if (GVL_SmallStation.GetInstance.plcReadDataDB3.StockBinAllowIssue[i - 1])
  811. {
  812. switch (recipeNum)
  813. {
  814. case 0:
  815. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe1BarrelPosReserve.ToArray(), p => p == i);
  816. break;
  817. case 1:
  818. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe2BarrelPosReserve.ToArray(), p => p == i);
  819. break;
  820. case 2:
  821. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe3BarrelPosReserve.ToArray(), p => p == i);
  822. break;
  823. case 3:
  824. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe4BarrelPosReserve.ToArray(), p => p == i);
  825. break;
  826. case 4:
  827. indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe5BarrelPosReserve.ToArray(), p => p == i);
  828. break;
  829. }
  830. if (indexArr >= 0 && GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].Get16bitValue((byte)i) == false)
  831. {
  832. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  833. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight * 1000;//单位g转换kg
  834. if (weight <= 0)
  835. {
  836. if (i >= 1 && i <= 8)
  837. {
  838. string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX12." + (i - 1), true);
  839. MessageNotify.GetInstance.ShowRunLog(commInfo);
  840. }
  841. else if (i >= 9 && i <= 15)
  842. {
  843. string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX13." + (i - 9), true);
  844. MessageNotify.GetInstance.ShowRunLog(commInfo1);
  845. }
  846. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].SetBitValue((byte)i, false);//配料完成设备写成false
  847. GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].SetBitValue((byte)i, true);//配料完成设备写成false
  848. }
  849. else
  850. {
  851. if (loc_index >= 0)
  852. {
  853. DeviceInquire.GetInstance.GetDevice((int)i)?.Start(weight);//根据料仓编号 启动并写入每个原料重量
  854. GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].SetBitValue((byte)i, true);//配料完成设备写成false
  855. }
  856. else
  857. {
  858. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号:{code},配方号{recipeNum + 1},{indexArr + 1}号桶,错误没有找到{(int)i}号仓的配方");
  859. }
  860. }
  861. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号:{code},配方号{recipeNum + 1},{indexArr + 1}号桶,{(int)i}号仓,正在配料");
  862. }
  863. else
  864. {
  865. //MessageNotify.GetInstance.ShowRunLog($"错误,有允许配料信号,但没有相应的位置 和桶号");
  866. }
  867. if ((DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3) && indexArr >= 0 && GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].Get16bitValue((byte)i))
  868. {
  869. int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  870. if (res < 0)
  871. {
  872. }
  873. else
  874. {
  875. Thread.Sleep(GVL_SmallStation.GetInstance.Time);
  876. RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.NowWeightFeedback;
  877. bool info = DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  878. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,配料完成,下料完成重量:{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight}");
  879. float AlarmRange = Math.Abs(RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight - RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).RawMaterialWeight * 1000);
  880. int iIndex = Array.FindIndex(Json<DevicePar>.Data.deviceParModels.ToArray(), p => p.MaterialName == DeviceInquire.GetInstance.GetDevice(i).DeviceName);
  881. if (iIndex >= 0)
  882. {
  883. if (Math.Abs(Json<DevicePar>.Data.deviceParModels.ElementAt(iIndex).ErrorRange) < AlarmRange)
  884. {
  885. HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", true);
  886. App.Current.Dispatcher.Invoke(() =>
  887. {
  888. MessageNotify.GetInstance.ShowDialog($"{i}号仓配料误差过大,设置出料重量{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).RawMaterialWeight * 1000}g,实际出料重量{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight}g,相差{AlarmRange}g,允许误差为{Math.Abs(Json<DevicePar>.Data.deviceParModels.ElementAt(iIndex).ErrorRange)}g,请联系人工处理", DialogType.Warning);
  889. HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", false);
  890. });
  891. }
  892. }
  893. if (i >= 1 && i <= 8)
  894. {
  895. string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX12." + (i - 1), true);
  896. MessageNotify.GetInstance.ShowRunLog(commInfo);
  897. }
  898. else if (i >= 9 && i <= 15)
  899. {
  900. string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX13." + (i - 9), true);
  901. MessageNotify.GetInstance.ShowRunLog(commInfo1);
  902. }
  903. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].SetBitValue((byte)i, false);//配料完成设备写成false
  904. MessageNotify.GetInstance.ShowRunLog($"配方{recipeNum},{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].ToBinString()}");
  905. }
  906. }
  907. }
  908. }
  909. bool DosingComple = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX6." + recipeNum);
  910. if ((RTrig.GetInstance("配方配料完成").Start(DosingComple)) || (GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] > 0 && DosingComple))
  911. {
  912. GVL_SmallStation.GetInstance.RecipeDosingCompleNum = GVL_SmallStation.GetInstance.RecipeDosingCompleNum + 1;
  913. GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = 0;
  914. if (GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] > 0)
  915. {
  916. for (int i = 1; i < 17; i++)
  917. {
  918. if (GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].Get16bitValue((byte)i))
  919. {
  920. MessageNotify.GetInstance.ShowRunLog($"料仓配料完成,但存在料仓未配料:{i}号仓");
  921. }
  922. }
  923. }
  924. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  925. double a = DateTime.Now.Subtract(GVL_SmallStation.GetInstance.DosingTime[recipeNum]).TotalSeconds;
  926. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  927. {
  928. MessageNotify.GetInstance.ShowRunLog($"{item.RawMaterialName},下料重量:{item.Laying_Off_Weight}g");
  929. }
  930. if (SiemensDevice.IsConnected && !GVL_SmallStation.GetInstance.IsUseLocalRecipe)
  931. {
  932. RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
  933. RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
  934. RecipeFinishInfo.Job_No = (short)trayCode;
  935. for (int i = 0; i < 20; i++)
  936. {
  937. RecipeFinishInfo.Material[i] = new UDT1();
  938. }
  939. for (int i = 0; i < 10; i++)
  940. {
  941. RecipeFinishInfo.Powder[i] = new UDT2();
  942. }
  943. for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
  944. {
  945. RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  946. RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  947. RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight * (float)0.001;
  948. }
  949. for (int i = 0; i < RemoteRecipes.ElementAt(index).WindSend.Count; i++)
  950. {
  951. RecipeFinishInfo.Powder[i].Powder_Weight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(i).DosingCompleWeight;
  952. }
  953. RecipeFinishInfo.Ask_For_Finish = true;
  954. RecipeFinishInfo.DosingTime = Convert.ToInt16(a);
  955. SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
  956. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据反馈给西门子");
  957. MessageNotify.GetInstance.ShowRecipeLog(res.RecipeName);
  958. }
  959. else
  960. {
  961. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据无法反馈给西门子,西门子设备未连接或处于本地配方");
  962. MessageNotify.GetInstance.ShowRecipeLog(res.RecipeName);
  963. }
  964. GVL_SmallStation.GetInstance.WindSendDosing = false;
  965. App.Current.Dispatcher.Invoke(() =>
  966. {
  967. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  968. });
  969. RecipeQueueTray[recipeNum].TryDequeue(out code);
  970. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
  971. GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0;
  972. }
  973. }
  974. }
  975. }
  976. }
  977. }
  978. }
  979. }
  980. private void StockBinInit()
  981. {
  982. for (int i = 1; i < 16; i++)
  983. {
  984. if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)
  985. {
  986. DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  987. }
  988. }
  989. }
  990. /// <summary>
  991. /// 料仓的位置和原料名称的对应
  992. /// </summary>
  993. public void StockBinNameWithPos()
  994. {
  995. RawMaterialsNamePos.Clear();
  996. foreach (var material in RawMaterialsInfo)
  997. {
  998. if (!string.IsNullOrEmpty(material.RawMaterialName))
  999. {
  1000. if (!RawMaterialsNamePos.ContainsKey(material.RawMaterialName))
  1001. {
  1002. RawMaterialsNamePos.Add(material.RawMaterialName, (short)material.RawMaterialLocation);
  1003. }
  1004. }
  1005. }
  1006. }
  1007. /// <summary>
  1008. /// PLC的DB3变量列表
  1009. /// </summary>
  1010. public void PlcVarMonitor()
  1011. {
  1012. foreach (PropertyInfo item in typeof(PlcReadAddressDB3).GetProperties())
  1013. {
  1014. if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
  1015. {
  1016. string type = item.PropertyType.ToString();
  1017. CommData.Add(new PlcInfos()
  1018. {
  1019. Count = CommData.Count + 1,
  1020. Name = item.Name,
  1021. Address = item.GetCustomAttribute<VarCommAttribute>().Address,
  1022. Type = type.Substring(type.IndexOf(".") + 1),
  1023. Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
  1024. Value = item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3).ToString(),
  1025. });
  1026. }
  1027. }
  1028. foreach (PropertyInfo item in typeof(WindSend_Read).GetProperties())
  1029. {
  1030. if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
  1031. {
  1032. string type = item.PropertyType.ToString();
  1033. CommData.Add(new PlcInfos()
  1034. {
  1035. Count = CommData.Count + 1,
  1036. Name = item.Name,
  1037. Address = item.GetCustomAttribute<VarCommAttribute>().Address,
  1038. Type = type.Substring(type.IndexOf(".") + 1),
  1039. Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
  1040. Value = item.GetValue(GVL_SmallStation.GetInstance.WindSendDB94).ToString(),
  1041. });
  1042. }
  1043. }
  1044. foreach (PropertyInfo item in typeof(WindSend_Write).GetProperties())
  1045. {
  1046. if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
  1047. {
  1048. string type = item.PropertyType.ToString();
  1049. CommData.Add(new PlcInfos()
  1050. {
  1051. Count = CommData.Count + 1,
  1052. Name = item.Name,
  1053. Address = item.GetCustomAttribute<VarCommAttribute>().Address,
  1054. Type = type.Substring(type.IndexOf(".") + 1),
  1055. Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
  1056. Value = item.GetValue(GVL_SmallStation.GetInstance.WindSendDB95).ToString(),
  1057. });
  1058. }
  1059. }
  1060. foreach (PropertyInfo item in typeof(GVL_SmallStation).GetProperties())
  1061. {
  1062. if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
  1063. {
  1064. string type = item.PropertyType.ToString();
  1065. ProcessVar.Add(new PlcInfos()
  1066. {
  1067. Count = ProcessVar.Count + 1,
  1068. Name = item.Name,
  1069. Type = type.Substring(type.IndexOf(".") + 1),
  1070. Address = item.GetCustomAttribute<VarCommAttribute>().Address,
  1071. Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
  1072. Value = item.GetValue(GVL_SmallStation.GetInstance).ToString()
  1073. });
  1074. }
  1075. }
  1076. }
  1077. public void RegisterInit()
  1078. {
  1079. //手动控制气缸 DB5.DBX0.0~DB5.DBX4.5
  1080. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1081. {
  1082. if (o != null)
  1083. {
  1084. if (o.ToString().Contains("升降气缸"))
  1085. {
  1086. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
  1087. if (index >= 1 && index <= 15)
  1088. {
  1089. string address = "DB5.DBX" + (index / 8) + "." + (index % 8 - 1);
  1090. if (index == 8) address = "DB5.DBX0.7";
  1091. HKDevice.HK_PLC_S7.Write<bool>(address, true);
  1092. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:{address},值:true");
  1093. }
  1094. }
  1095. else if (o.ToString().Contains("阻挡气缸"))
  1096. {
  1097. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
  1098. if (index >= 1 && index <= 15)
  1099. {
  1100. string address = "";
  1101. if (index == 1) address = "DB5.DBX1.7";
  1102. if (index == 2) address = "DB5.DBX2.0";
  1103. if (index == 3) address = "DB5.DBX2.1";
  1104. if (index == 4) address = "DB5.DBX2.2";
  1105. if (index == 5) address = "DB5.DBX2.3";
  1106. if (index == 6) address = "DB5.DBX2.4";
  1107. if (index == 7) address = "DB5.DBX2.5";
  1108. if (index == 8) address = "DB5.DBX2.6";
  1109. if (index == 9) address = "DB5.DBX2.7";
  1110. if (index == 10) address = "DB5.DBX3.0";
  1111. if (index == 11) address = "DB5.DBX3.1";
  1112. if (index == 12) address = "DB5.DBX3.2";
  1113. if (index == 13) address = "DB5.DBX3.3";
  1114. if (index == 14) address = "DB5.DBX3.4";
  1115. if (index == 15) address = "DB5.DBX3.5";
  1116. HKDevice.HK_PLC_S7.Write<bool>(address, true);
  1117. }
  1118. }
  1119. else if (o.ToString().Contains("进料桶顶升气缸"))
  1120. {
  1121. HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", false);//默认顶升
  1122. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.6,值:false");
  1123. }
  1124. else if (o.ToString().Contains("出料桶顶升气缸1"))
  1125. {
  1126. HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", true);
  1127. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.7,值:true");
  1128. }
  1129. else if (o.ToString().Contains("出料桶顶升气缸2"))
  1130. {
  1131. HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", true);
  1132. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.0,值:true");
  1133. }
  1134. else if (o.ToString().Contains("出料桶顶升气缸3"))
  1135. {
  1136. HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", true);
  1137. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.1,值:true");
  1138. }
  1139. else if (o.ToString().Contains("托盘气缸1_1"))
  1140. {
  1141. HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", false);//默认伸出
  1142. }
  1143. else if (o.ToString().Contains("托盘气缸1_2"))
  1144. {
  1145. HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", false);
  1146. }
  1147. else if (o.ToString().Contains("托盘气缸2_1"))
  1148. {
  1149. HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", false);
  1150. }
  1151. else if (o.ToString().Contains("托盘气缸2_2"))
  1152. {
  1153. HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", false);
  1154. }
  1155. }
  1156. }), "ManualOpen", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  1157. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1158. {
  1159. if (o != null)
  1160. {
  1161. if (o.ToString().Contains("升降气缸"))
  1162. {
  1163. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
  1164. if (index >= 1 && index <= 15)
  1165. {
  1166. string address = "DB5.DBX" + (index / 8) + "." + (index % 8 - 1);
  1167. if (index == 8) address = "DB5.DBX0.7";
  1168. HKDevice.HK_PLC_S7.Write<bool>(address, false);
  1169. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:{address},值:false");
  1170. }
  1171. }
  1172. else if (o.ToString().Contains("阻挡气缸"))
  1173. {
  1174. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
  1175. if (index >= 1 && index <= 15)
  1176. {
  1177. string address = "";
  1178. if (index == 1) address = "DB5.DBX1.7";
  1179. if (index == 2) address = "DB5.DBX2.0";
  1180. if (index == 3) address = "DB5.DBX2.1";
  1181. if (index == 4) address = "DB5.DBX2.2";
  1182. if (index == 5) address = "DB5.DBX2.3";
  1183. if (index == 6) address = "DB5.DBX2.4";
  1184. if (index == 7) address = "DB5.DBX2.5";
  1185. if (index == 8) address = "DB5.DBX2.6";
  1186. if (index == 9) address = "DB5.DBX2.7";
  1187. if (index == 10) address = "DB5.DBX3.0";
  1188. if (index == 11) address = "DB5.DBX3.1";
  1189. if (index == 12) address = "DB5.DBX3.2";
  1190. if (index == 13) address = "DB5.DBX3.3";
  1191. if (index == 14) address = "DB5.DBX3.4";
  1192. if (index == 15) address = "DB5.DBX3.5";
  1193. HKDevice.HK_PLC_S7.Write<bool>(address, false);
  1194. }
  1195. }
  1196. else if (o.ToString().Contains("进料桶顶升气缸"))
  1197. {
  1198. HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", true);
  1199. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.6,值:true");
  1200. }
  1201. else if (o.ToString().Contains("出料桶顶升气缸1"))
  1202. {
  1203. HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", false);
  1204. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.7,值:false");
  1205. }
  1206. else if (o.ToString().Contains("出料桶顶升气缸2"))
  1207. {
  1208. HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", false);
  1209. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.0,值:false");
  1210. }
  1211. else if (o.ToString().Contains("出料桶顶升气缸3"))
  1212. {
  1213. HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", false);
  1214. MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.1,值:false");
  1215. }
  1216. else if (o.ToString().Contains("托盘气缸1_1"))
  1217. {
  1218. HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", true);
  1219. }
  1220. else if (o.ToString().Contains("托盘气缸1_2"))
  1221. {
  1222. HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", true);
  1223. }
  1224. else if (o.ToString().Contains("托盘气缸2_1"))
  1225. {
  1226. HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", true);
  1227. }
  1228. else if (o.ToString().Contains("托盘气缸2_2"))
  1229. {
  1230. HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", true);
  1231. }
  1232. }
  1233. }), "ManualClose", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  1234. //手动控制电机轴 DB5.DBX4.6~DB5.DBX5.2
  1235. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.6", true); }), "StartAxisLoadCommand", true);
  1236. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.6", false); }), "StopAxisLoadCommand", true);
  1237. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.7", true); }), "StartAxisMidCommand", true);
  1238. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.7", false); }), "StopAxisMidCommand", true);
  1239. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.0", true); }), "StartAxisUnLoadCommand", true);
  1240. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.0", false); }), "StopAxisUnLoadCommand", true);
  1241. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.1", true); }), "StartAxis1Command", true);
  1242. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.1", false); }), "StopAxis1Command", true);
  1243. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.2", true); }), "StartAxis2Command", true);
  1244. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.2", false); }), "StopAxis2Command", true);
  1245. //西门子配方处理
  1246. ActionManage.GetInstance.Register(new Action<object>((res) =>
  1247. {
  1248. ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
  1249. ObservableCollection<WindSendRawMaterial> WindSendData = new ObservableCollection<WindSendRawMaterial>();
  1250. if (SiemensDevice.IsConnected)
  1251. {
  1252. if (res != null && res is XL_Start_DB recipe)
  1253. {
  1254. if (!string.IsNullOrEmpty(recipe.RecipeCode))
  1255. {
  1256. RawMaterials.Clear();
  1257. for (int i = 0; i < GVL_SmallStation.Max_DosingSotckBinNum; i++)
  1258. {
  1259. if (!string.IsNullOrEmpty(recipe.Material[i].Material_Name))
  1260. {
  1261. if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name))
  1262. {
  1263. RawMaterials.Add(new RemoteRecipeRawMaterial()
  1264. {
  1265. RawMaterialName = recipe.Material[i].Material_Name,
  1266. RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum,
  1267. RawMaterialWeight = recipe.Material[i].Material_Weight,
  1268. RawMaterialLocation = (int)RawMaterialsNamePos[recipe.Material[i].Material_Name]
  1269. });
  1270. }
  1271. else
  1272. {
  1273. MessageNotify.GetInstance.ShowRunLog($"原料:{recipe.Material[i].Material_Name},不在配料表");
  1274. }
  1275. }
  1276. else
  1277. {
  1278. break;
  1279. }
  1280. }
  1281. for (int i = 0; i < GVL_SmallStation.Max_PowderSotckBinNum; i++)
  1282. {
  1283. if (!string.IsNullOrEmpty(recipe.Powder[i].Powder_Name))
  1284. {
  1285. WindSendData.Add(new WindSendRawMaterial()
  1286. {
  1287. RawMaterialName = recipe.Powder[i].Powder_Name,
  1288. RawMaterialWeight = recipe.Powder[i].Powder_Weight
  1289. });
  1290. }
  1291. else
  1292. {
  1293. break;
  1294. }
  1295. }
  1296. App.Current.Dispatcher.Invoke(() =>
  1297. {
  1298. Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  1299. {
  1300. RecipeName = recipe.RecipeName,
  1301. RecipeCode = recipe.RecipeCode,
  1302. RawMaterial = RawMaterials,
  1303. TrayCode = recipe.StockCode,
  1304. WindSend = WindSendData
  1305. });
  1306. });
  1307. }
  1308. }
  1309. }
  1310. }), "SiemensRecipeRecive", true);
  1311. //将本地配方发送到西门子配方里,执行配料
  1312. ActionManage.GetInstance.Register(new Action<Object>((res) =>
  1313. {
  1314. if (res != null && res is RemoteRecipeData recipe)
  1315. {
  1316. Json<RemoteRecipeDataColl>.Data.Recipes.Add(recipe);
  1317. }
  1318. }), "LocalSimulationRecipeIssue", true);
  1319. //手动控制系统模式
  1320. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", true); }), "SystemStart", true);
  1321. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", false); }), "SystemStop", true);
  1322. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", true); }), "SystemPause", true);
  1323. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", false); }), "SystemReset", true);
  1324. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", false); }), "SystemAutoMode", true);
  1325. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", true); }), "SystemDebugMode", true);
  1326. //流程控制
  1327. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.3", true); }), "ManualSystemReset", true);
  1328. ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.4", true); }), "CLearRecipeInfo", true);
  1329. ActionManage.GetInstance.Register(new Action(() =>
  1330. {
  1331. Json<RemoteRecipeDataColl>.Data.Recipes.Clear();
  1332. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
  1333. GVL_SmallStation.GetInstance.WindSendDosingStatus = 0;
  1334. GVL_SmallStation.GetInstance.WindSendDosing = false;
  1335. GVL_SmallStation.GetInstance.Order_Cancel = false;
  1336. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
  1337. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  1338. for (int i = 0; i < 5; i++)
  1339. {
  1340. RecipeQueueTray[i].Clear();
  1341. GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0;
  1342. GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 0;
  1343. }
  1344. StockBinInit();
  1345. WindSendReset();
  1346. //for (int i = 0; i < GVL_SmallStation.GetInstance.StockInDosingComple.Length; i++)
  1347. //{
  1348. // GVL_SmallStation.GetInstance.StockInDosingComple[i] = false;
  1349. //}
  1350. MessageNotify.GetInstance.ShowRunLog("系统流程复位,等待西门子重新下发订单");
  1351. }), "BPASystemReset", true);
  1352. //往海科PLC写值
  1353. ActionManage.GetInstance.Register(new Action<Object>((o) =>
  1354. {
  1355. if (o != null && o is HKDeviceWrite data)
  1356. {
  1357. if (data.PlcVarType == PlcVarType.Bool)
  1358. {
  1359. bool value = (bool)data.Value;
  1360. HKDevice.HK_PLC_S7.Write<bool>(data.Address, value);
  1361. }
  1362. else if (data.PlcVarType == PlcVarType.Byte)
  1363. {
  1364. byte value = (byte)data.Value;
  1365. HKDevice.HK_PLC_S7.Write<byte>(data.Address, value);
  1366. }
  1367. else if (data.PlcVarType == PlcVarType.Int)
  1368. {
  1369. short value = (short)data.Value;
  1370. HKDevice.HK_PLC_S7.Write<short>(data.Address, value);
  1371. }
  1372. else if (data.PlcVarType == PlcVarType.Dint)
  1373. {
  1374. int value = (int)data.Value;
  1375. HKDevice.HK_PLC_S7.Write<int>(data.Address, value);
  1376. }
  1377. else if (data.PlcVarType == PlcVarType.Real)
  1378. {
  1379. float value = (float)data.Value;
  1380. HKDevice.HK_PLC_S7.Write<float>(data.Address, value);
  1381. }
  1382. }
  1383. }), "PLCWrite", true);
  1384. //电机速度
  1385. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1386. {
  1387. if (o != null && o is short value)
  1388. {
  1389. HKDevice.HK_PLC_S7.Write("DB47.DBW8", value);
  1390. }
  1391. }), "AxisLoadSpeedSet", true);
  1392. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1393. {
  1394. if (o != null && o is short value)
  1395. {
  1396. HKDevice.HK_PLC_S7.Write("DB47.DBW10", value);
  1397. }
  1398. }), "AxisMidSpeedSet", true);
  1399. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1400. {
  1401. if (o != null && o is short value)
  1402. {
  1403. HKDevice.HK_PLC_S7.Write("DB47.DBW12", value);
  1404. }
  1405. }), "AxisUnLoadSpeedSet", true);
  1406. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1407. {
  1408. if (o != null && o is float value)
  1409. {
  1410. HKDevice.HK_PLC_S7.Write("DB47.DBD0", value);
  1411. }
  1412. }), "Axis1SpeedSet", true);
  1413. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1414. {
  1415. if (o != null && o is float value)
  1416. {
  1417. HKDevice.HK_PLC_S7.Write("DB47.DBD4", value);
  1418. }
  1419. }), "Axis2SpeedSet", true);
  1420. //机器人的操作
  1421. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1422. {
  1423. if (o != null && o is string address)
  1424. {
  1425. HKDevice.HK_PLC_S7.Write(address, true);
  1426. }
  1427. }), "RobotSendTrueCommand", true);
  1428. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1429. {
  1430. if (o != null && o is string address)
  1431. {
  1432. HKDevice.HK_PLC_S7.Write(address, false);
  1433. }
  1434. }), "RobotSendFalseCommand", true);
  1435. ActionManage.GetInstance.Register(new Action<object>((o) =>
  1436. {
  1437. if (o != null && o is short Value)
  1438. {
  1439. HKDevice.HK_PLC_S7.Write("DB4.DBB1", (byte)Value);
  1440. }
  1441. }), "RobotSetProgramNum", true);
  1442. }
  1443. public void DeviceConnect()
  1444. {
  1445. try
  1446. {
  1447. if (Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
  1448. {
  1449. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
  1450. if (HKDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("海科plc连接成功");
  1451. }
  1452. }
  1453. catch (Exception ex)
  1454. {
  1455. MessageNotify.GetInstance.ShowAlarmLog("海科plc连接失败,等待重新连接");
  1456. }
  1457. finally
  1458. {
  1459. HKDevice.Init();
  1460. MessageNotify.GetInstance.ShowRunLog("海科plc初始化完成");
  1461. }
  1462. try
  1463. {
  1464. if (Json<DevicePar>.Data.deviceConnectPar.SiemensConnect)
  1465. {
  1466. SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  1467. if (SiemensDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功");
  1468. }
  1469. }
  1470. catch (Exception ex)
  1471. {
  1472. MessageNotify.GetInstance.ShowAlarmLog("西门子plc连接失败,等待重新连接");
  1473. }
  1474. finally
  1475. {
  1476. SiemensDevice.Init();
  1477. MessageNotify.GetInstance.ShowRunLog("西门子plc初始化完成");
  1478. }
  1479. try
  1480. {
  1481. if (Json<DevicePar>.Data.deviceConnectPar.WindSendConnect)
  1482. {
  1483. WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200, WindSend_PLC_IP);
  1484. if (WindSendDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("风送plc连接成功");
  1485. }
  1486. }
  1487. catch (Exception ex)
  1488. {
  1489. MessageNotify.GetInstance.ShowAlarmLog("粉料plc连接失败,等待重新连接");
  1490. }
  1491. finally
  1492. {
  1493. WindSendDevice.Init();
  1494. MessageNotify.GetInstance.ShowRunLog("风送粉料plc初始化完成");
  1495. }
  1496. ThreadManage.GetInstance().StartLong(new Action(() =>
  1497. {
  1498. try
  1499. {
  1500. if (!HKDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
  1501. {
  1502. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
  1503. if (HKDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接成功");
  1504. }
  1505. }
  1506. catch (Exception ex)
  1507. {
  1508. }
  1509. try
  1510. {
  1511. if (!SiemensDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.SiemensConnect)
  1512. {
  1513. SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  1514. if (SiemensDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("西门子PLC重新连接成功");
  1515. }
  1516. }
  1517. catch (Exception ex)
  1518. {
  1519. }
  1520. try
  1521. {
  1522. if (!WindSendDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.WindSendConnect)
  1523. {
  1524. WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200, WindSend_PLC_IP);
  1525. if (WindSendDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("风送plc重新连接成功");
  1526. }
  1527. }
  1528. catch (Exception ex)
  1529. {
  1530. }
  1531. Thread.Sleep(50);
  1532. }), "设备连接", true);
  1533. }
  1534. private void DosingDevice(int Index, int DeviceID)
  1535. {
  1536. if (RTrig.GetInstance("Tray2StatusDevice" + DeviceID).Start(DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.RunStatus == 3))
  1537. {
  1538. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{RemoteRecipes.ElementAt(Index).RecipeName},{DeviceID}号仓,配料完成");
  1539. int res = Array.FindIndex(RemoteRecipes.ElementAt(Index).RawMaterial.ToArray(), p => p.RawMaterialLocation == DeviceID);
  1540. RemoteRecipes.ElementAt(Index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.CutWeightFeedback;
  1541. DeviceInquire.GetInstance.GetDevice(DeviceID).StatusReset();
  1542. if (DeviceID >= 1 && DeviceID <= 8)
  1543. {
  1544. HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (DeviceID - 1), true);
  1545. }
  1546. else if (DeviceID >= 9 && DeviceID <= 15)
  1547. {
  1548. HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (DeviceID - 9), true);
  1549. }
  1550. }
  1551. }
  1552. private void WindSendReset()
  1553. {
  1554. float weight = (float)0.0;
  1555. WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD0", weight);
  1556. WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD4", weight);
  1557. WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD8", weight);
  1558. WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD12", weight);
  1559. WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD16", weight);
  1560. WindSendDevice.Siemens_PLC_S7.Write("DB95.DBX38.1", false);
  1561. }
  1562. public void RawMaterialNameWithCode()
  1563. {
  1564. GVL_SmallStation.GetInstance.RawMaterialsNameCode.Clear();
  1565. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0001", "色拉油");
  1566. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0002", "一级菜油");
  1567. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0003", "菜籽油");
  1568. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0004", "青花椒油");
  1569. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0005", "卤牛肉丁");
  1570. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0006", "冻鸡肉丁");
  1571. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0007", "香菇丁");
  1572. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0008", "高水分糍粑海椒");
  1573. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0009", "低水分糍粑海椒");
  1574. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0010", "辣豆瓣");
  1575. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0011", "整豆豉");
  1576. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0012", "豆豉细粒");
  1577. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0013", "卤黄豆");
  1578. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0014", "野山椒粒");
  1579. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0015", "竹笋丁");
  1580. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0016", "香辣酱辣椒酱");
  1581. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0017", "芽菜粒");
  1582. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0018", "榨菜丁");
  1583. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0019", "盐菜");
  1584. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0020", "洋葱丁");
  1585. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0021", "番茄酱");
  1586. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0022", "甜豆瓣");
  1587. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0023", "甜面酱");
  1588. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0024", "芝麻酱");
  1589. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0025", "炸花生");
  1590. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0026", "盐渍青椒丁");
  1591. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0027", "备料剁红椒");
  1592. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0028", "萝卜丁");
  1593. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0029", "油芝麻");
  1594. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0030", "生姜");
  1595. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0031", "大蒜");
  1596. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0032", "榨菜酱");
  1597. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0033", "炸碗豆");
  1598. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0034", "大头菜丁");
  1599. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0035", "酱油");
  1600. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0036", "I+G");
  1601. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0037", "味精");
  1602. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0038", "白糖");
  1603. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0039", "食盐");
  1604. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0040", "花椒酱");
  1605. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0041", "调味膏2");
  1606. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0042", "调味膏5");
  1607. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0043", "十三香调味膏");
  1608. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0044", "酱香膏");
  1609. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0045", "芽菜香料粉");
  1610. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0046", "香料A");
  1611. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0047", "香料D");
  1612. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0048", "猪肉精膏");
  1613. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0049", "调味膏3");
  1614. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0050", "柠檬酸粉");
  1615. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0051", "辣椒红");
  1616. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0052", "辣椒油树脂");
  1617. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0053", "水态混和酸");
  1618. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0054", "加水稀释后防腐剂");
  1619. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0055", "异维C钠粉");
  1620. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0056", "琼脂粉");
  1621. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0057", "香葱油");
  1622. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0058", "水态甜味剂");
  1623. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0059", "孜然粉");
  1624. GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0060", "孜然油");
  1625. }
  1626. }
  1627. }