if os.isatty(fd): old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~termios.ICANON & ~termios.ECHO new[6] [termios.VMIN] = 1 new[6] [termios.VTIME] = 0 try: termios.tcsetattr(fd, termios.TCSANOW, new) termios.tcsendbreak(fd,0) ch = os.read(fd,7) finally: termios.tcsetattr(fd, termios.TCSAFLUSH, old) else: ch = os.read(fd,7) return(ch) v = u1272.u1272('/dev/ttyUSB1',19200) i = u1272.u1272('/dev/ttyUSB2',19200) while True: print "%f,%f"%(v.read(),i.read()) k = getchar() if k == 'x': break
#!/usr/bin/env python import urllib2, json, time from getchar import getchar import time, u1272, sys, os voltmeter = u1272.u1272('/dev/ttyUSB1', 19200) ammeter = u1272.u1272('/dev/ttyUSB2', 19200) fname = time.strftime("%y%m%d-caldata.csv", time.localtime(time.time())) fdata = open(fname, "a") fdata.write("\n") running = True while running: pvilast = 0.0 count = 0 while True: # loop until value stops changing pvv = voltmeter.read() pvi = ammeter.read() if abs(pvilast - pvi) < 0.01: count += 1 if count > 2: print break pvilast = pvi time.sleep(0.25) sys.stdout.write(".")