pcs_work.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @文件 :ccuWork.py
  5. @时间 :2021/12/09 08:31:48
  6. @作者 :None
  7. @版本 :1.0
  8. @说明 :二级BMS工作线程
  9. '''
  10. from utils.globalvar import SD
  11. from utils.qt import QObject, Signal
  12. import utils.modbus.defines as cst
  13. from utils.delay import m_delay
  14. class PcsCanReceived(QObject):
  15. show_90_signal = Signal(object)
  16. show_91_signal = Signal(object)
  17. show_92_signal = Signal(object)
  18. show_93_signal = Signal(object)
  19. def __init__(self):
  20. super(PcsCanReceived, self).__init__()
  21. # 接收数据
  22. def received(self):
  23. while SD.CAN_ON_OFF:
  24. restNum = SD.CAN_CONTROL.get_undeal_number()
  25. if restNum <= 0:
  26. continue
  27. revRet = SD.CAN_CONTROL.receive(restNum)
  28. for i in revRet:
  29. if int(i.RemoteFlag) != 0:
  30. continue
  31. if i.ID == 0x18903F00:
  32. self.show_90_signal.emit(i.Data)
  33. elif i.ID == 0x18913F00:
  34. self.show_91_signal.emit(i.Data)
  35. elif i.ID == 0x18923F00:
  36. self.show_92_signal.emit(i.Data)
  37. elif i.ID == 0x18933F00:
  38. self.show_93_signal.emit(i.Data)
  39. else:
  40. continue
  41. class PcsComWork(QObject):
  42. show_00_com_signal = Signal(int)
  43. show_01_com_signal = Signal(int)
  44. show_02_com_signal = Signal(int)
  45. show_03_com_signal = Signal(int)
  46. show_04_com_signal = Signal(int)
  47. show_05_com_signal = Signal(int)
  48. show_06_com_signal = Signal(int)
  49. show_07_com_signal = Signal(int)
  50. show_08_com_signal = Signal(int)
  51. show_09_com_signal = Signal(int)
  52. show_0A_com_signal = Signal(int)
  53. show_0B_com_signal = Signal(int)
  54. show_0C_com_signal = Signal(int)
  55. show_0D_com_signal = Signal(int)
  56. show_0E_com_signal = Signal(int)
  57. show_0F_com_signal = Signal(int)
  58. def __init__(self):
  59. super(PcsComWork, self).__init__()
  60. # 接收数据
  61. def work(self):
  62. while SD.CAN_ON_OFF:
  63. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0100, 1)
  64. self.show_00_com_signal.emit(ret[1] << 8 | ret[0])
  65. m_delay(10)
  66. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0101, 1)
  67. self.show_01_com_signal.emit(ret[1] << 8 | ret[0])
  68. m_delay(10)
  69. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0102, 1)
  70. self.show_02_com_signal.emit(ret[1] << 8 | ret[0])
  71. m_delay(10)
  72. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0103, 1)
  73. self.show_03_com_signal.emit(ret[1] << 8 | ret[0])
  74. m_delay(10)
  75. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0104, 1)
  76. self.show_04_com_signal.emit(ret[1] << 8 | ret[0])
  77. m_delay(10)
  78. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0105, 1)
  79. self.show_05_com_signal.emit(ret[1] << 8 | ret[0])
  80. m_delay(10)
  81. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0106, 1)
  82. self.show_06_com_signal.emit(ret[1] << 8 | ret[0])
  83. m_delay(10)
  84. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0107, 1)
  85. self.show_07_com_signal.emit(ret[1] << 8 | ret[0])
  86. m_delay(10)
  87. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0108, 1)
  88. self.show_08_com_signal.emit(ret[1] << 8 | ret[0])
  89. m_delay(10)
  90. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x0109, 1)
  91. self.show_09_com_signal.emit(ret[1] << 8 | ret[0])
  92. m_delay(10)
  93. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x010A, 1)
  94. self.show_0A_com_signal.emit(ret[1] << 8 | ret[0])
  95. m_delay(10)
  96. ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x010B, 5)
  97. self.show_0B_com_signal.emit(ret[1] << 8 | ret[0])
  98. self.show_0C_com_signal.emit(ret[3] << 8 | ret[2])
  99. self.show_0D_com_signal.emit(ret[5] << 8 | ret[4])
  100. self.show_0E_com_signal.emit(ret[7] << 8 | ret[6])
  101. self.show_0F_com_signal.emit(ret[9] << 8 | ret[8])
  102. m_delay(10)
  103. # ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x010C, 1)
  104. # self.show_0C_com_signal.emit(ret[1] << 8 | ret[0])
  105. # m_delay(10)
  106. # ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x010D, 1)
  107. # self.show_0D_com_signal.emit(ret[1] << 8 | ret[0])
  108. # m_delay(10)
  109. # ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x010E, 1)
  110. # self.show_0E_com_signal.emit(ret[1] << 8 | ret[0])
  111. # m_delay(10)
  112. # ret = SD.COM_CONTROL.send(1, cst.READ_HOLDING_REGISTERS, 0x010F, 1)
  113. # self.show_0F_com_signal.emit(ret[1] << 8 | ret[0])
  114. # m_delay(10)