1234567891011121314151617181920212223242526272829303132333435 |
- import time
- from serial import Serial
- import colorama
- from colorama import Fore, Style
- class Modbus:
- def __init__(self, tty: str, brate: int, address: str):
- self.serial = Serial(port=tty, baudrate=brate, timeout=0.05, parity='N', xonxoff=False)
- self.address = address
- def test_send(self, data: bytes):
- while True:
- self.serial.write(data)
- time.sleep(1)
- def send_recv(self, data, number):
- self.serial.write(data)
-
-
-
-
-
-
-
- def main():
- colorama.init()
- dev = Modbus('COM22', 115200, 1)
-
-
- tx_data = 'abc'
- dev.send_recv(bytes(tx_data, encoding="utf_8"), len(tx_data))
- if __name__ == '__main__':
- main()
|