sbs.py 678 B

123456789101112131415161718192021222324252627
  1. from modbus import Modbus, MBError, NoResponseError
  2. import colorama
  3. from colorama import Fore
  4. import time
  5. import os
  6. class SBS(Modbus):
  7. def __init__(self, tty: str, brate: int, address: int):
  8. super().__init__(tty, brate, address)
  9. def read_pack(self, addr: int, cnt: int):
  10. return self.read_holding_registers(addr, cnt)
  11. def main():
  12. colorama.init(autoreset=True)
  13. dev = SBS('COM3', 115200, 34)
  14. dev.MB_DEBUG = False
  15. while True:
  16. data = dev.read_pack(0x300, 30)
  17. print("Output :", Fore.GREEN + ' '.join(str(el) for el in data))
  18. time.sleep(0.25)
  19. if __name__ == '__main__':
  20. main()