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

69 regels
2.6 KiB

  1. using BPASmartClient.Helper;
  2. using BPASmartClient.Modbus;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using BPASmartClient.S7Net;
  9. namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC
  10. {
  11. public class HKDeviceStatus
  12. {
  13. public SiemensHelper HK_PLC_S7 = new SiemensHelper();
  14. public bool IsConnected => HK_PLC_S7.IsConnected;
  15. public void Init()
  16. {
  17. if (IsConnected)
  18. {
  19. ThreadManage.GetInstance().StartLong(new Action(() =>
  20. {
  21. }),"信号收发处理");
  22. }
  23. }
  24. /// <summary>
  25. /// 下发配方数据
  26. /// </summary>
  27. public void StockBinPar(RecipeData recipe)
  28. {
  29. if (IsConnected)
  30. {
  31. if (recipe != null)
  32. {
  33. for (int barrel = 1; barrel < 6; barrel++)
  34. {
  35. for (int loc = 1; loc < 13; loc++)
  36. {
  37. int index = Array.FindIndex(recipe.RawMaterial.ToArray(), p => p.RawMaterialBarrelNum == barrel && p.RawMaterialLocation == loc);
  38. if (barrel >= 3)//PLC没有3号桶的重量位置,故4,5号桶地址向前偏移48个位置
  39. {
  40. if (index != -1)
  41. {
  42. HK_PLC_S7.Write<float>("MD" + 4120 + (loc - 1) * 4 + (barrel - 1 - 1) * 48, recipe.RawMaterial.ElementAt(index).RawMaterialWeight);
  43. }
  44. else//不存在的原料信息,重量写0
  45. {
  46. HK_PLC_S7.Write<float>("MD" + 4120 + (loc - 1) * 4 + (barrel - 1 - 1) * 48, 0);
  47. }
  48. }
  49. else
  50. {
  51. if (index != -1)
  52. {
  53. HK_PLC_S7.Write<float>("MD" + 4120 + (loc - 1) * 4 + (barrel - 1) * 48, recipe.RawMaterial.ElementAt(index).RawMaterialWeight);
  54. }
  55. else//不存在的原料信息,重量写0
  56. {
  57. HK_PLC_S7.Write<float>("MD" + 4120 + (loc - 1) * 4 + (barrel - 1) * 48, 0);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }