11 toolstr="/home/muto/owtools/src/owtools USB1 DC "
\r
14 f=open("DEVLIST.txt","r")
\r
15 for l in f.readlines():
\r
18 devdict[ls[0]]=l.replace("\n","")
\r
19 devwholist.append(ls[0])
\r
25 s=s+"%02X" %(id[7-i])
\r
32 bl.append(int(s[i2:i2+2],16))
\r
36 def calculateValues(code, V, vn):
\r
38 return V[vn] / 16.0;
\r
42 return V[vn]*0.2 + 700;
\r
44 return math.exp(V[vn] / 160.0);
\r
46 return V[vn]*62.5 + 55000;
\r
48 return V[vn] / 256.0;
\r
51 return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0);
\r
55 return V[vn] / 100.0;
\r
57 return V[vn] / 65535.0*5.1;
\r
59 return V[vn] / 65535.0*2.55;
\r
61 return V[vn] / 65535.0*1.1;
\r
63 return V[vn] / 10.0;
\r
67 return (V[vn] - 32767.0) / 100.0;
\r
69 return math.exp((V[vn]-32767.0)/1000.0);
\r
77 return ["Temperatur","C"]
\r
79 return ["Druck","hPa"]
\r
81 return ["Beleuchtungsstaerke","lux"]
\r
83 return ["Luftfeuchte","%%"]
\r
85 return ["Konstante",""]
\r
87 return ["Spannung","V"]
\r
89 return ["Strom","mA"]
\r
91 return ["VOC","ppm"]
\r
93 return ["Counter",""]
\r
97 def owCom(dev,send,rcount):
\r
98 cmd=toolstr+id2string(dev)
\r
100 # cmd=cmd+"%02X" %(dev[7-i])
\r
103 cmd=cmd+"%02X" % (b)
\r
104 for i in range(rcount):
\r
106 #print(cmd.split(' '));
\r
107 p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
\r
109 s=p.stdout.read().decode("utf-8")
\r
113 for i in range(int(len(l[2])/2)):
\r
115 bl.append(int(l[2][i2:i2+2],16))
\r
118 def owComStr(dev,sendstr):
\r
119 cmd=toolstr+id2string(dev)
\r
120 #for i in range(8):
\r
121 # cmd=cmd+"%02X" %(dev[7-i])
\r
122 cmd=cmd+" "+sendstr
\r
123 p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
\r
125 s=p.stdout.read().decode("utf-8")
\r
131 for i in range(int(len(l)/2)):
\r
133 bl.append(int(l[i2:i2+2],16))
\r
137 def getValues(dev,voc):
\r
139 #print(id2string(dev[0]),voc)
\r
140 if dev[0][0]==0x26:
\r
144 sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
\r
147 VDD=(sb[5]+sb[6]*256)
\r
149 VAD=(sb[5]+sb[6]*256)
\r
150 Temp=(sb[3]+sb[4]*256)
\r
153 curr=sb[7]+sb[8]*256
\r
156 vals=[Temp,VDD,VAD,curr]
\r
157 formellist=[6,8,7,8]
\r
158 if dev[1][0]!=0xFF:
\r
161 if (dev[1][i*2+1])!=0:
\r
162 formellist.append(dev[1][i*2+1])
\r
166 for i in range(len(formellist)):
\r
167 cvals.append(calculateValues(formellist[i],vals,i))
\r
168 if (cvals[2]<=110):
\r
176 #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
\r
178 R0=(sb[2]+sb[3]*256)/100.0
\r
179 VS=(sb[4]+sb[5]*256)/10000.0
\r
180 Corr=(sb[7]+sb[8]*256)/1000.0
\r
189 cvals.append(cmode)
\r
195 if dev[0][0]==0x28:
\r
196 sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")
\r
197 Temp=sbl[1][1]+sbl[1][2]*256
\r
198 if (sbl[1][2] & 0x80):
\r
199 Temp=-(Temp&0x7FFF)
\r
200 if dev[1][0]!=0xFF:
\r
201 return [calculateValues(dev[1][1],[Temp],0)]
\r
203 return [calculateValues(1,[Temp],0)]
\r
210 p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
\r
223 bl.append(int(d[i2:i2+2],16))
\r
226 config=owCom(bl,[0x85],18)
\r
228 if (config[1]==0xFF):
\r
230 config=[0,1,6,6,8,4,7,7,8,0]
\r
232 config=[0,1,1,0,0,0,0,0,0,0]
\r
233 dev.append(config[1:])
\r
239 cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" "
\r
244 config=[0,0,0,0,0,0,0,0,0,0]
\r
248 cs=cs+getName(c)[0]+" "
\r
250 #if bls in devdict:
\r
251 # if "VOC" in devdict[bls]:
\r
253 #l=getValues([bl,config[1:]],voc)
\r
255 # cs=cs+" %0.2f " %(v)
\r
259 if config[1]==0x08:
\r
261 #print("Test_configs")
\r
264 #print("c",dv[1][9:16])
\r
265 #print("d",bl[0:7])
\r
266 if dv[1][9:16]==bl[0:7]:
\r
267 print("Double Device")
\r
275 devlist.append(dev)
\r
276 #voc_marker.append(vm)
\r
277 #print("devlist",devlist)
\r
285 lt = time.localtime()
\r
286 vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt)
\r
287 n = datetime.datetime.now()
\r
288 unix_timestamp = time.mktime(n.timetuple())# works if Python >= 3.3
\r
291 bezeichnung="not in List"
\r
293 bezeichnung=devdict[ds].split(",")[0].split(" ")[1]+" "
\r
301 vnames.append(name[0])
\r
303 if "VOC" in bezeichnung:
\r
305 vnames.append("R0")
\r
306 vnames.append("VS")
\r
307 vnames.append("Corr")
\r
308 vnames.append("cmode")
\r
309 vnames.append("RS")
\r
310 vnames.append("RSR0")
\r
311 vnames.append("VOC1")
\r
312 vnames.append("VOC2")
\r
314 l=getValues([d[0],d[1]],voc)
\r
315 s=vline+"%i" %(unix_timestamp)
\r
316 for i in range(len(l)):
\r
317 print("%s %s: %0.2f " %(bezeichnung,vnames[i],l[i]))
\r
318 s=s+"\t%0.4f" % (l[i])
\r
319 fname="log_%s.ow1" %(ds)
\r
321 if os.path.exists(fname):
\r
325 sh="time\tunixtime"
\r
326 for i in range(len(l)):
\r
327 sh=sh+"\t%s" % (vnames[i])
\r
329 f.write(s.replace(".",",").replace("#",".")+"\n")
\r
331 #execfile("separate1.py")
\r
332 os.system("python separate1.py")
\r
333 print("--------------------")
\r
334 n = datetime.datetime.now()
\r
335 unix_timestamp1 = time.mktime(n.timetuple())# works if Python >= 3.3
\r
336 d=unix_timestamp1-unix_timestamp
\r
338 print("--------------------")
\r