main.py 619 B

1234567891011121314151617181920
  1. #!/usr/bin/python3
  2. # -*- coding: UTF-8 -*-
  3. import os, sys, serial.tools.list_ports, time
  4. for item in serial.tools.list_ports.comports():
  5. if not item.pid or not item.location :
  6. continue
  7. if item.vid == 0x19d1 and item.pid == 0x0001 and "x.6" in item.location :
  8. print(dir(item))
  9. print(item.name)
  10. with serial.Serial(item.name, 115200, timeout=1) as ser:
  11. while 1:
  12. data = ser.read(128)
  13. if data :
  14. print( str(time.time()) + ">> " + str(data))
  15. else :
  16. ser.write("Hi from PC".encode())