def log(options):
# configure the serial connections (the parameters differs on the device you are connecting to)
ser = serial.Serial(
port=options.device,
baudrate=9600,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.SEVENBITS
)
prog = Progress()
with open(options.outfile, 'w') as the_file:
the_file.write('timestamp;value\n')
while True:
# \r\n is for device terminators set to CR LF
ser.write((':FETCh?\r\n'))
# wait one second before reading output.
time.sleep(options.interval)
out = ''
while ser.inWaiting() > 0:
out += ser.read(1)
if out != '':
out = out.rstrip()
res = "%s;%s\n" % (time.time(), float(out))
the_file.write(res)
the_file.flush()
prog.show()
评论列表
文章目录