import StringIO
import csv

def read_last_line():
    f.seek(-2, 2)            
    while f.read(1) != "\n": 
        f.seek(-2, 1)        
    last = f.readline()      
    return last

file = '//file.cqct.unsw.edu.au/publicshares/z3435374/avs/LogTC_14-03-20.dat'
f = open(file, "rb")

LockIn1 = qt.instruments.create('LockIn1', 'x_SR830', address='GPIB::1', reset=False) #xx_a
LockIn2 = qt.instruments.create('LockIn1', 'x_SR830', address='GPIB::1', reset=False) #xx_b

data = qt.Data(name='trace')
data.add_coordinate('T_mix [mK]')
data.add_value('V_xx_a [V]')
data.add_value('V_xx_b [V]')
data.add_value('T_Pt [mK]')

plot_T_mix = qt.Plot2D(data, name='T mixing chamber', coorddim=0, valdim=1, maxtraces=1)
plot_T_Pt = qt.Plot2D(data, name='T Pt', coorddim=3, valdim=1, maxtraces=1) 
     
qt.mstart()
while 1:
    V_xx_a= LockIn1.get_X()
    V_xx_b= LockIn2.get_X()
    last_line = read_last_line()
    ll = StringIO.StringIO(last_line)
    reader = csv.reader(ll, delimiter='\t')
    # row[14] is the PT sensor
    # row[13] is mixing chamber sensor
    for row in reader:
        T_Pt=float(row[14])
        T_mix=float(row[13])
    data.add_data_point(T_mix, V_xx_a, V_xx_b, T_Pt)
    plot_T_mix.update()
    plot_T_Pt.update()
    qt.msleep(45)
    
qt.mend()










ll = StringIO.StringIO(last_line)
reader = csv.reader(ll, delimiter='\t')

# row[14] is the PT sensor
# row[13] is mixing chamber sensor
for row in reader:
	T_1=row[14]
	T_2=row[13]

print T_1
print T_2