Ver Fonte

Added pyserial command.py

  For some reason this works... without issues.

  I'd prefer pyusb but pyserial also works... and fairly well.

  I just need to make some kind of input routine so I can test
reactively sending and receiving values.
david há 3 anos atrás
pai
commit
22c326da18
1 ficheiros alterados com 39 adições e 0 exclusões
  1. 39 0
      command.py

+ 39 - 0
command.py

@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+from serial import Serial
+
+# Use port_listing to print out the avalible ports
+# from serial.tools.list_ports import main as port_listing
+# port_listing()
+
+from remotes import tv
+
+from pprint import pprint
+
+ser = Serial(timeout=1)
+ser.baudrate = 9600
+ser.port = '/dev/ttyACM0'
+
+def send_code(ky):
+    if ky in tv:
+        msg = "0x{0},{1},1\n".format(tv[ky], tv["_config"]["size"])
+        ser.write(msg.encode())
+        print("Sent {0}".format(msg.encode()))
+    else:
+        print("Invalid key")
+
+ser.open()
+print("Opened!")
+connect_t = 0
+while ser.is_open:
+    line = ser.readline().decode().strip("\n").strip("\r")
+    if line != "":
+        pprint(line)
+    if connect_t == 6:
+        send_code('power')
+    elif connect_t == 18:
+        send_code('power')
+    elif connect_t == 30:
+        ser.close()
+        print("Closed!")
+    connect_t += 1 # About 1 every second