TelenkovDmitry 1 gadu atpakaļ
vecāks
revīzija
75d5f0b480
2 mainītis faili ar 41 papildinājumiem un 0 dzēšanām
  1. 6 0
      books/python/misc.py
  2. 35 0
      hw_libs/modbus.py

+ 6 - 0
books/python/misc.py

@@ -0,0 +1,6 @@
+a = bytes(range(30, 40))
+print(type(2.0 + 3))
+
+
+
+

+ 35 - 0
hw_libs/modbus.py

@@ -0,0 +1,35 @@
+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)
+        
+        # while True:
+        #     self.serial.write(data)
+        #     recv = self.serial.read_all()
+        #     print(recv)
+        #     print(recv.decode('utf_8'))
+        #     time.sleep(1)
+
+def main():
+    colorama.init()
+    dev = Modbus('COM22', 115200, 1)
+    # dev.test_send(bytes('hello world\r\n', encoding="utf_8"))
+    # tx_data = 'hello world\r\n'
+    tx_data = 'abc'
+    dev.send_recv(bytes(tx_data, encoding="utf_8"), len(tx_data))
+
+if __name__ == '__main__':
+    main()