So I'm continuously measuring temperature data with a National Instruments data acquisition system, and I've been able to plot the real time temperature measurements and store that into a dataframe that I can then save.
What I'm trying to do is set the "samplerate" range to be something really high (its at 301 right now) and then stop it when I no longer want to acquire temperature data. Sometimes I need to collect only 100 samples, sometimes over 10k.
When I use this code to break out the loop it prints into the console what I ask, but I cant actually type anything into the console. The console is completely unresponsive to keyboard interrupts.
Is there anyway that I can break out of this loop early without out using the keyboard?
import nidaqmx
import matplotlib.pyplot as plt
import pandas as pd
plt.ion()
Samples = []
time = []
freezerTemp = []
rightSideTemp = []
def print_menu():
print('Press "3" and hit "Enter" to exit ')
print('3. Exit')
with nidaqmx.Task() as task:
FreezerT = task.ai_channels.add_ai_thrmcpl_chan("cDAQ1Mod1/ai0")
RightSideT = task.ai_channels.add_ai_thrmcpl_chan("cDAQ1Mod1/ai3")
#This controls the sample/second. i.e. if 2 then 2 samples/second.
samplerate = task.timing.samp_clk_rate = 1
while True:
print_menu()
for samplerate in range(301):
data = task.read()
Samples.append(samplerate)
freezerTemp.append(data[0])
rightSideTemp.append(data[1])
time.append(samplerate/1)
plt.xlabel('Samples')
plt.ylabel('Temperature (C)')
plt.scatter(samplerate,freezerTemp[samplerate],c='r')
plt.scatter(samplerate,rightSideTemp[samplerate],c='b')
plt.pause(0.05)
plt.show()
choice = input('Enter a number: ')
if choice == '3':
break
df = pd.DataFrame({'Samples': Samples,
'Time(sec)': time,
'Freezer Temperature': freezerTemp,
'Right Side': rightSideTemp})
print(df)