-
Notifications
You must be signed in to change notification settings - Fork 21
Description
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as dates
from matplotlib.dates import DayLocator
from decimal import Decimal
import elitech
import datetime
from datetime import datetime
import sys
import serial
import csv
if len(sys.argv)>1: #we have command line arguments
with open(sys.argv[1], mode='r', encoding="UTF-8", newline='') as f:
reader = csv.reader(f, delimiter='\t')
data = [row for row in reader]
date = [datetime.strptime(l[1], '%Y-%m-%d %H:%M:%S') for l in data]
vals = [float(l[2]) for l in data]
else:
port = "/dev/ttyUSB0"
try:
device = elitech.Device(port)
except serial.serialutil.SerialException:
print("Device not found")
exit(8)
device.init()
get data
data = device.get_data() #get a list of tuples with number,date and temp
date=[l[1] for l in data]
vals=[l[2] for l in data]
ax=plt.axes()
ax.xaxis.set_major_formatter(dates.DateFormatter('%H:%M %d.%m.%Y'))
ax.xaxis.set_minor_locator(DayLocator())
p1 = plt.plot_date(date,vals,linestyle='solid',fmt='o')
plt.ylabel('Temp')
plt.title('Temperature')
plt.xticks(rotation=45,ha='right')
plt.grid(axis='x',which='minor')
plt.show()