import time,serial,math, numpy as np,matplotlib.pyplot as plt
print '*** Meritev pulzarja ***'
rxime='/dev/ttyUSB0'
rx=serial.Serial(rxime,230400,timeout=3.0)
rx.setRTS(False)	#sprosti /BOOTLOADER
rx.setDTR(False)	#sprosti /RESET
i=0
print time.ctime()
fr=raw_input('frekvenca vzorcenja')
fp=raw_input('frekvenca pulzarja')
N=raw_input('Stevilo povprecenj')
deltat=1.0/float(fp) #perioda pulzarja
T=deltat*float(fr)#perioda opazovanja
print T
print N
N=int(N)#stevilo povprecenj
m=0##stevec povprecenj
k=0.0 #kazalec v polju
A=np.zeros(T, dtype=float)

time.sleep(5)
rx.flushInput()
time.sleep(0.01)
l=rx.read(1)

while m<N: 
		
		string=rx.read(1)
		stevilo=ord(string)
		#string=string +m

		A[int(k)]=A[int(k)]+stevilo
		k=k+1.0
		if k<T:
			continue
		k=k-T
		m=m+1
		#time.sleep(0.01)
		#m=rx.read(1)
		#string=string +m*/
print time.ctime()
rx.close()
#f1=open('pulzar3.txt', 'w+')
3f1.write(string)
plt.plot(A)
plt.show()
#f1.close()
