From e5ff1a26d97a4503a241eb7a261275b68fb82430 Mon Sep 17 00:00:00 2001
From: Berk Silemek <berk.silemek@gmail.com>
Date: Mon, 14 Nov 2022 14:35:06 +0000
Subject: [PATCH] The script for Keithley interface to pull resistance data and
 converting to temperature values for the thermistor that was used.

---
 Software/Keithley/Keithley_Interface_25Hz.py | 76 ++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Software/Keithley/Keithley_Interface_25Hz.py

diff --git a/Software/Keithley/Keithley_Interface_25Hz.py b/Software/Keithley/Keithley_Interface_25Hz.py
new file mode 100644
index 0000000..7b57e5e
--- /dev/null
+++ b/Software/Keithley/Keithley_Interface_25Hz.py
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+
+#
+import time
+import serial
+import matplotlib
+matplotlib.use('TkAgg')
+import numpy
+import matplotlib.pyplot as plt
+from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
+from matplotlib.figure import Figure
+import Tkinter as tk
+import ttk
+import sys
+import math
+from datetime import datetime
+
+hl, = plt.plot([], [])
+plt.ylabel('Temperature')
+plt.xlabel('Sample Point')
+plt.grid()
+plt.rcParams.update({'font.size': 24})
+plt.rcParams.update({'font.weight' : 'bold'})
+plt.rcParams['lines.linewidth'] = 2
+file_object  = open("log.txt", "a")
+dt_obj = datetime.strptime('18.12.2016 17:05:42,76',
+			  '%d.%m.%Y %H:%M:%S,%f')
+serialDev = serial.Serial(port = '/dev/ttyUSB0',baudrate=19200,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS)
+serialDev.write("display:enable 0"+'\r\n') 
+#serialDev.write("sens:RES:NPLC RST"+'\r\n')
+R0   = float(10000)
+T0   = float(298.15)
+beta = float(3380)
+temp = float(0.0)
+rate = float(0.04)
+counter = 1 
+plotData = float(0.04)
+now = datetime.today()
+def update_line(hl, new_data, x_data):
+		hl.set_xdata(np.append(hl.get_xdata(), x_data))
+		hl.set_ydata(np.append(hl.get_ydata(), new_data))
+		hl.axes.relim()
+		hl.axes.autoscale_view()
+		plt.pause(0.0001)
+		
+def rThermistor(rt):
+    temperature = 1/((1/T0) + ((1/beta) * (math.log(rt/R0))))-(273.15);
+    return temperature
+x_data = 0 
+            
+while 1 :
+	serialDev.write("sens:data:fresh?" + '\r\n')
+	out = ''
+	time.sleep(rate)
+	while serialDev.inWaiting() > 0:
+		out += serialDev.read(1)
+		if out[-1] == '\n':
+                        #print(out)
+			now = datetime.today()
+			if(out[-5:-1] == "E+03"):
+				rt = float(out[:-5])*1000
+				plotData = rThermistor(rt)
+				file_object.write(now.strftime('%d.%m.%Y %H:%M:%S.%f') +' '  + str(plotData) + ' ' +  out)
+				x_data = x_data +1
+			elif (out[-5:-1] == "E+04"):
+				rt = float(out[:-5])*10000
+				plotData = rThermistor(rt)
+				file_object.write(now.strftime('%d.%m.%Y %H:%M:%S.%f') + ' ' + str(plotData) + ' ' +  out)
+				x_data = x_data +1
+			else:
+				print 'False E+03' 
+			#update_line(hl, plotData, x_data)
+			  
+		
+	    
+	    
-- 
GitLab