T7Pro.py 3.98 KB
from abstract_instrument import abstract_instrument
from labjack import ljm
import numpy

#==============================================================================

ALL_VAL_TYPE = "TEMP, RES"

#==============================================================================

class T7Pro(abstract_instrument):
	def __init__(self, adress="192.168.0.26", vtype="TEMP"):
		self.adress = adress
		self.vtype = vtype
		self.names = ["TEMPERATURE_AIR_K",
			 "CURRENT_SOURCE_200UA_CAL_VALUE",
			 "AIN0",# "AIN1",
			 "AIN2",# "AIN3",
			 "AIN4",# "AIN5",
			 "AIN6",# "AIN7"
			 ]

	def model(self):
		return 'T7Pro'

	def connect(self):
		try:
			print('Connecting to device @%s...' %(self.adress))
			self.handle = ljm.openS("T7", "ETHERNET", self.adress)
			self.configureAINs()
			print('  --> Ok')

			print(self.model())

			if self.vtype == "TEMP":
				1
			elif self.vtype == "RES":
				1
			else:
				print("Wrong -v argument")
				raise

		except Exception as er:
			print("Unexpected error during connection: " + str(er))
			raise

	def getValue(self):
		results = self.read(self.names)
		temp = results[0]
		res1 = results[2]/results[1]
		res2 = results[3]/results[1]
		res3 = results[4]/results[1]
		res4 = results[5]/results[1]

		if self.vtype == 'TEMP':
			# Temperature calculation
			temp1 = self.res2tempSensor(628, res1)
			temp2 = self.res2tempSensor(16947, res2)
			temp3 = self.res2tempSensor(625, res3)
			temp4 = self.res2tempSensor(100, res4)
			string = '%f\t%f\t%f\t%f\t%f\n'%(temp, temp1, temp2, temp3, temp4)
		elif self.vtype == 'RES':
			string =  '%f\t%f\t%f\t%f\t%f\n'%(temp, res1, res2, res3, res4)
		else:
			string = ''

		return string

	def read(self, names):
		return ljm.eReadNames(self.handle, len(names), names)

	def disconnect(self):
		ljm.close(self.handle)

	def send(self, command):
		pass

	def configureAINs(self):
	# Setup and call eWriteNames to configure AINs on the LabJack.
		names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX",
		 #"AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX",
		 "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX",
		 #"AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX",
		 "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX",
		 #"AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX",
		 "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX",
		 #"AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX"
		 ]
		l_names = len(names)
		aValues = [1, 1, 12,
				   #199, 0.01, 0,
				   3, 1, 12,
				   #199, 0.01, 0,
				   5, 1, 12,
				   #199, 0.01, 0,
				   7, 0.1, 12,
				   #199, 0.01, 0
				   ]
		ljm.eWriteNames(self.handle, l_names, names, aValues)
#		print("\nSet configuration:")
#		for i in range(len(names)):
#			print("	%s : %f" % (names[i], aValues[i]))

	def res2tempSensor(self, sensor, res):
		if sensor==627:
			K = [0.399341181655472610,
				 10.8420092277810909,
				 -26.4597939187660813,
				 245.9828566655493379,
				 -668.069876596331596,
				 1001.69882618263364,
				 -267.272089680656791]
		if sensor==625:
			K = [0.333548856582638109,
				 11.7361551595386118,
				 -31.32988932320903987,
				 262.878643524833024,
				 -704.163538021035492,
				 1056.6040485650301,
				 -307.057196729816496]
		if sensor==628:
			K = [0.463200932294057566,
				 13.5049710820894688,
				 -30.5191222755238414,
				 231.098593852017075,
				 -550.122691885568202,
				 806.038547554984689,
				 -198.510489917360246]
		if sensor==16945:
			K = [3.2497, 5.1777, 2.499]
		if sensor==16943:
			K = [3.4738, 5.1198, 2.3681]
		if sensor==16944:
			K = [3.3674, 5.2874, 2.5165]
		if sensor==16941:
			K = [2.9486, 4.5862, 2.266]
		if sensor==16947:
			K = [3.4597, 5.2422, 2.4169]
		if sensor==100:
			K = [0.003850]
		return self.res2temp(K, res)

	def res2temp(K, res):
		temp = 0
		tmp = 1000./res
		if len(K)==7:
			for i in range(len(K)):
				temp += K[i]*tmp**i
		if len(K)==3:
			for i in range(len(K)):
				temp += K[i]*numpy.log10(tmp)**(2-i)
			temp = 10**temp
		if len(K)==1:
			temp = (res/100.-1)/K[0]+273.15
		return temp