123456789101112131415161718192021222324252627 |
- from modbus import Modbus, MBError, NoResponseError
- import colorama
- from colorama import Fore
- import time
- import os
- class SBS(Modbus):
- def __init__(self, tty: str, brate: int, address: int):
- super().__init__(tty, brate, address)
- def read_pack(self, addr: int, cnt: int):
- return self.read_holding_registers(addr, cnt)
-
- def main():
- colorama.init(autoreset=True)
- dev = SBS('COM3', 115200, 34)
- dev.MB_DEBUG = False
- while True:
- data = dev.read_pack(0x300, 30)
- print("Output :", Fore.GREEN + ' '.join(str(el) for el in data))
- time.sleep(0.25)
- if __name__ == '__main__':
- main()
|