graf
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
#main.py - the main program file of the TeraHz project
|
||||||
|
#This code is licensed under 3-clause BSD licensed
|
||||||
|
import serial as ser
|
||||||
|
|
||||||
|
#global config
|
||||||
|
# TODO: move this to another file
|
||||||
|
uartpath = '/dev/ttyUSB0'
|
||||||
|
uartbaud = 115200
|
||||||
|
uarttout = 5
|
||||||
|
|
||||||
|
print('TeraHz project')
|
||||||
|
print('Accessing the serial port')
|
||||||
|
|
||||||
|
sp = 'blank'
|
||||||
|
|
||||||
|
try:
|
||||||
|
sp = ser.Serial(uartpath, uartbaud, timeout=uarttout)
|
||||||
|
except Exception as e:
|
||||||
|
print('Connection to serial port at {} failed!'.format(uartpath))
|
||||||
|
raise e
|
||||||
|
exit()
|
||||||
+18
-9
@@ -4,7 +4,8 @@ import serial as ser
|
|||||||
from parse import *
|
from parse import *
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import time
|
||||||
#global variables
|
#global variables
|
||||||
uartpath = '/dev/ttyUSB0'
|
uartpath = '/dev/ttyUSB0'
|
||||||
uartbaud = 115200
|
uartbaud = 115200
|
||||||
@@ -13,19 +14,27 @@ uarttout = 5
|
|||||||
wl = [410, 435, 460, 485, 510, 535, 560, 585, 610, 645, 680, 705, 730, 760, 810, 860, 900, 940]
|
wl = [410, 435, 460, 485, 510, 535, 560, 585, 610, 645, 680, 705, 730, 760, 810, 860, 900, 940]
|
||||||
responseorder = [i for i in 'RSTUVWGHIJKLABCDEF'] # works, do NOT touch!
|
responseorder = [i for i in 'RSTUVWGHIJKLABCDEF'] # works, do NOT touch!
|
||||||
realorder = [i for i in 'ABCDEFGHRISJTUVWKL']
|
realorder = [i for i in 'ABCDEFGHRISJTUVWKL']
|
||||||
|
plt.ion()
|
||||||
|
|
||||||
print('getcdata')
|
print('getcdata')
|
||||||
print('This utility is part of the TeraHz project')
|
print('This utility is part of the TeraHz project')
|
||||||
|
|
||||||
wavelens = pd.Series(realorder)
|
wavelens = pd.Series(realorder)
|
||||||
|
data=pd.DataFrame([], [])
|
||||||
|
|
||||||
wavetable = pd.DataFrame(columns=realorder)
|
wavetable = pd.DataFrame(columns=realorder)
|
||||||
|
graph=plt.figure()
|
||||||
|
plot=graph.add_subplot(111)
|
||||||
with ser.Serial(uartpath, uartbaud, timeout=uarttout) as sensor:
|
with ser.Serial(uartpath, uartbaud, timeout=uarttout) as sensor:
|
||||||
sensor.write(b'ATCDATA\n')
|
while True:
|
||||||
rawresp = sensor.readline().decode()
|
sensor.write(b'ATCDATA\n')
|
||||||
# parses, calculates and saves the data
|
rawresp = sensor.readline().decode()
|
||||||
response = pd.Series([float(i)/35.0 for i in rawresp[:-3].split(',')], index=responseorder)
|
# parses, calculates and saves the data
|
||||||
data = pd.DataFrame(response, index=realorder, columns = ['uW/cm^2']) # puts data into a DataFrame
|
response = pd.Series([float(i)/35.0 for i in rawresp[:-3].split(',')], index=responseorder)
|
||||||
data.insert(0, 'wavelenght', wl) #inserts a legend
|
data = pd.DataFrame(response, index=realorder, columns = ['uW/cm^2']) # puts data into a DataFrame
|
||||||
print(data)
|
data.insert(0, 'wavelenght', wl) #inserts a legend
|
||||||
|
print(data)
|
||||||
|
plot.cla()
|
||||||
|
line=plot.plot(data['wavelenght'], data['uW/cm^2'])
|
||||||
|
graph.canvas.draw()
|
||||||
|
time.sleep(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user