bms_balance_ctl.py 843 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. from utils.globalvar import SD
  4. from widget.bms_balance import Win_Balance
  5. class BmsBalanceControll:
  6. def __init__(self):
  7. self._view = Win_Balance()
  8. self.init()
  9. def init(self):
  10. self._view.balance_control_signal.connect(self._cell_balance_ctl)
  11. def _cell_balance_ctl(self, cmu_id, cell_id, state):
  12. print(cmu_id, cell_id, state)
  13. try:
  14. data = []
  15. if len(data) < 8:
  16. data += (8 - len(data)) * [0]
  17. data[0] = 0x02
  18. data[1] = 0xC0
  19. data[2] = cmu_id
  20. data[3] = ((1 if (state > 0) else 0) << (cell_id - 1)) & 0xFF
  21. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  22. except:
  23. self._view.can_connect_error()