allen_bradley_connect.py 3.3 KB

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