allen_bradley_connect.py 3.2 KB

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