bms_download_ctl.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. from widget.bms_download import Win_Download
  4. from utils.globalvar import SD
  5. class BmsDownloadControll:
  6. def __init__(self):
  7. self._view = Win_Download()
  8. self.init()
  9. def init(self):
  10. self._view.bms_sn_signal.connect(self._bms_sn_set)
  11. self._view.bat_sn_signal.connect(self._bat_sn_set)
  12. def _bms_sn_set(self):
  13. bms_sn_str = self._view.edt_bms_sn.text()
  14. bms_sn_list = list(bms_sn_str)
  15. try:
  16. data = []
  17. if len(data) < 8:
  18. data += (8 - len(data)) * [0]
  19. data[0] = 0x00
  20. data[1] = 0xB2
  21. data[2] = ord(bms_sn_list[0])
  22. data[3] = ord(bms_sn_list[1])
  23. data[4] = ord(bms_sn_list[2])
  24. data[5] = ord(bms_sn_list[3])
  25. data[6] = ord(bms_sn_list[4])
  26. data[7] = ord(bms_sn_list[5])
  27. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  28. data[0] = 0x01
  29. data[1] = 0xB2
  30. data[2] = ord(bms_sn_list[6])
  31. data[3] = ord(bms_sn_list[7])
  32. data[4] = ord(bms_sn_list[8])
  33. data[5] = ord(bms_sn_list[9])
  34. data[6] = ord(bms_sn_list[10])
  35. data[7] = ord(bms_sn_list[11])
  36. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  37. data[0] = 0x02
  38. data[1] = 0xB2
  39. data[2] = ord(bms_sn_list[12])
  40. data[3] = ord(bms_sn_list[13])
  41. data[4] = ord(bms_sn_list[14])
  42. data[5] = ord(bms_sn_list[15])
  43. data[6] = 0xFF
  44. data[7] = 0xFF
  45. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  46. except IndexError:
  47. self._view.index_error()
  48. except:
  49. self._view.can_connect_error()
  50. def _bat_sn_set(self):
  51. bat_sn_str = self._view.edt_battery_sn.text()
  52. bat_sn_list = list(bat_sn_str)
  53. try:
  54. data = []
  55. if len(data) < 8:
  56. data += (8 - len(data)) * [0]
  57. data[0] = 0x03
  58. data[1] = 0xB2
  59. data[2] = ord(bat_sn_list[0])
  60. data[3] = ord(bat_sn_list[1])
  61. data[4] = ord(bat_sn_list[2])
  62. data[5] = ord(bat_sn_list[3])
  63. data[6] = ord(bat_sn_list[4])
  64. data[7] = ord(bat_sn_list[5])
  65. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  66. data[0] = 0x04
  67. data[1] = 0xB2
  68. data[2] = ord(bat_sn_list[6])
  69. data[3] = ord(bat_sn_list[7])
  70. data[4] = ord(bat_sn_list[8])
  71. data[5] = ord(bat_sn_list[9])
  72. data[6] = ord(bat_sn_list[10])
  73. data[7] = ord(bat_sn_list[11])
  74. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  75. data[0] = 0x05
  76. data[1] = 0xB2
  77. data[2] = ord(bat_sn_list[12])
  78. data[3] = ord(bat_sn_list[13])
  79. data[4] = ord(bat_sn_list[14])
  80. data[5] = ord(bat_sn_list[15])
  81. data[6] = 0xFF
  82. data[7] = 0xFF
  83. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  84. except IndexError:
  85. self._view.index_error()
  86. except:
  87. self._view.can_connect_error()