Code: Alles auswählen
#!/usr/bin/python
from comctrl import *
import time
import matplotlib.pyplot as plt
import numpy
from drawnow import *
import random
from datetime import datetime
from datetime import timedelta
plt.ion()
start_time = datetime.now()
# returns the elapsed milliseconds since the start of the program
def millis():
dt = datetime.now() - start_time
ms = (dt.days * 24 * 60 * 60 + dt.seconds) * 1000 + dt.microseconds / 1000.0
return ms
def makeFig():
plt.plot(tempX,tempY,'g-')
plt.title("PFC Speed Plot")
plt.xlabel("Time (sec)")
plt.ylabel("Speed (rpm)")
plt.grid(True)
#plt.xlim([0,180])
#now = time.time()
#print(int(round(time.time() * 1000)))
samples = 0
cnt = 0
tempY = []
tempX = []
com = ComMiniVad ( port='auto' )
old_milli_time = 0
if ( com.initCommunication() == 1 ):
com.setSpeed(5500)
com.startPump()
com.connectToCU()
try:
while ( True ):
#print (millis())
data = com.getLatestDataPackage()
tempY.append(data.meanSpeed)
tempX.append(millis()/1000)
cnt = cnt +1
#print(data.meanSpeed," ",millis())
samples = samples + 1
if(cnt > 3000):
tempY.pop(0)
tempX.pop(0)
if(samples > 10):
samples = 0
drawnow(makeFig)
#print "meanSpeed: % 5u" % data.meanSpeed
#time.sleep ( 0.1 )
except:
pass
plt.close()
com.stopPump()
com.terminateCommunication()