# section: environment {{{1
#####################################################
import gf_config as gf
-#import serial
+import usb.core
+import usb.util
+import serial
+from serial.tools import list_ports
+import io
import fileinput
import matplotlib.pyplot as plt
-import numpy as pl
from datetime import datetime,date,time
-
# section: debugging {{{1
######################################################
speed[ids5[i]-67]=speed[ids5[i]-67]+[val5[i]/254]
return td,master,speed
+# section: serial_ports {{{1
+######################################################
+def serial_ports():
+# A list contains a tuple with the port number, description and hardware address
+ ports=list(list_ports.comports())
+ # return the port if 'USB' is in the description
+ result=[]
+ print("Available ports:")
+ for p in ports:
+ print(repr(p.device),repr(p.description),repr(p.serial_number))
+ if p.vid==0x0403 or p.vid==None:
+ try:
+ s = serial.Serial(p.device)
+ s.close()
+ result.append(p)
+ except (OSError, serial.SerialException):
+ pass
+ return result
+
# section: checkcrc {{{1
######################################################
def checkcrc(line):
# section: main {{{1
######################################################
-for line in fileinput.input():
- print("====================================================================")
+
+lsusb=serial_ports()
+ser=serial.Serial()
+ser.port=lsusb[0].device
+ser.baudrate=9600
+ser.parity=serial.PARITY_NONE
+ser.stopbits=serial.STOPBITS_ONE
+ser.bytesize=serial.EIGHTBITS
+ser.timeout=0
+ser.open()
+print("Connected to",repr(ser.portstr))
+
+dev=usb.core.find(idVendor=0x0403)
+if dev is None:
+ dev=usb.core.find(idVendor=0x0403)
+print(dev)
+#print("-----------------------------")
+#dev.set_configuration()
+#cfg=dev.get_active_configuration()
+#print(cfg)
+
+#io=io.TextIOWrapper(io.BufferedRWPair(ser,ser,1),
+# newline='\r',
+# line_buffering=True)
+#
+#line = []
+#while True:
+# line=sio.readline()
# print(line)
- process_telegram(line)
+#
+ser.close()
+
+#for line in fileinput.input():
+# print("====================================================================")
+## print(line)
+# process_telegram(line)
+#
# section: plot {{{1
######################################################