Blame view

instruments/T7Pro.py 5.01 KB
90e45ebe9   mer0m   Add files via upload
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  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
  '%(temp, temp1, temp2, temp3, temp4)
          elif self.vtype == 'RES':
              string =  '%f\t%f\t%f\t%f\t%f
  '%(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("
  Set 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