allen_bradley_connect.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import logging
  2. from pylogix import PLC
  3. from threading import Thread
  4. import time
  5. from datetime import datetime
  6. from structures.plant import *
  7. from inputs.common import Input
  8. localtz = datetime.now().astimezone().tzinfo
  9. logger = logging.getLogger(__name__)
  10. class AllenBradleyCPU(Input):
  11. def __init__(self, host):
  12. super().__init__(self.read_handler)
  13. self.comm = PLC()
  14. self.comm.IPAddress = host
  15. self.interval = 0.02
  16. self.tags = [
  17. "B14[31]", # ejector_move_down
  18. "B14[32]", # ejector_move_up
  19. "B14[34]", # carriage_move_out
  20. "B14[35]", # carriage_move_in
  21. "B14[37]", # side_clamps_open
  22. "B14[38]", # side_clamps_close
  23. "B14[42]", # table_move_down
  24. "B14[43]", # table_move_up
  25. "B14[45]", # gassing_platemove_out
  26. "B14[46]", # gassing_plate_move_in
  27. "B14[48]", # cope_eject_plate_move_out
  28. "B14[49]", # cope_eject_plate_move_in
  29. "B14[51]", # top_part_move_up
  30. "B14[52]", # top_part_move_down
  31. "B14[54]", # front_door_open
  32. "B14[55]", # front_door_close
  33. "B14[57]", # pneumatic_loose_part_1_move_out
  34. "B14[58]", # pneumatic_loose_part_1_move_in
  35. "B14[60]", # hydraulic_loose_part_2_move_out
  36. "B14[61]", # hydraulic_loose_part_2_move_in
  37. "B14[63]", # hydraulic_loose_part_3_move_out
  38. "B14[64]", # hydraulic_loose_part_3_move_in
  39. "B14[69]", # clamping_device_side_clamp_left_clamp
  40. "B14[70]", # clamping_device_side_clamp_left_loose
  41. "B14[72]", # clamping_device_side_clamp_right_clamp
  42. "B14[73]", # clamping_device_side_clamp_right_loose
  43. "B14[81]", # clamping_device_shoot_plate_clamp
  44. "B14[82]", # clamping_device_shoot_plate_loose
  45. "B14[83]", # sand_refill
  46. "B14[84]", # sand_gate_close
  47. "B14[85]", # sand_gate_open
  48. "B14[93]", # shoot
  49. "B14[103]", # clamping_device_gassing_plate_clamp
  50. "B16[12]", # central_amine_supply_refill
  51. "B16[13]", # gassing
  52. "B16[15]", # gas_generator_process_coldbox_betaset
  53. "B18[31]", # mixer_lid_move_up
  54. "B18[32]", # mixer_lid_move_down
  55. "B18[35]", # mixer_wing_motor_on
  56. "B18[37]", # mixer_move_up
  57. "B18[38]", # mixer_move_down
  58. "B18[40]", # sand_dosing_unit_inlet
  59. "B18[42]", # sand_dosing_unit_outlet
  60. "B18[44]", # binder_1_sucking
  61. "B18[45]", # binder_1_blowing
  62. "B18[47]", # binder_2_suction
  63. "B18[48]", # binder_2_blowing
  64. "B18[50]", # binder_3_sucking
  65. "B18[51]", # binder_3_blowing
  66. "B18[53]", # binder_4_sucking
  67. "B18[54]", # binder_4_blowing
  68. "B18[59]", # additive_1_dosing
  69. "B18[60]", # additive_2_dosing
  70. "B18[62]", # mixer_bowl_direction_eject_1_machine
  71. "B18[63]", # mixer_bowl_direction_eject_2_scrap
  72. "B18[65]", # cleaning_cylinder_move_up
  73. "B18[66]", # cleaning_cylinder_move_down
  74. "B18[68]", # mixer_sand_slide_move_to_machine
  75. "B18[69]", # mixer_sand_slide_move_to_scrap
  76. "B18[71]", # vertical_mixersand_slide_gateclose
  77. "B18[72]", # vertical_mixer_sand_slide_gate_open
  78. "B18[73]", # sand_sender
  79. ]
  80. def read_handler(self):
  81. timestamp = datetime.now(localtz)
  82. ret = self.comm.Read(self.tags)
  83. if ret[0].Status == "Success":
  84. values = [r.Value for r in ret]
  85. self._q.put(PlantState(timestamp, "AB", *values))
  86. else:
  87. logger.error("CPU read: " + ret[0].Status)