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