add more units

master
Eggert Jung 2 years ago
parent bb1736d6eb
commit 6e00cfdc15

@ -3,14 +3,14 @@ from math import inf
import sys import sys
import binascii import binascii
def crap_to_number(crap): def crap_to_number(num, unit, acdc):
number_str = "" number_str = ""
if(crap[0]&0x10): if(num[0]&0x10):
number_str+="-" number_str+="-"
crap[0] &= 0xEF num[0] &= 0xEF
for elem in crap: for elem in num:
if(elem & 0x10 != 0): if(elem & 0x10 != 0):
number_str+="." number_str+="."
switch={ switch={
@ -28,6 +28,35 @@ def crap_to_number(crap):
0x00:" " 0x00:" "
} }
number_str+=switch.get(elem&0xEF, "-") number_str+=switch.get(elem&0xEF, "-")
if (unit[0] & 0x1):
number_str+="µ"
if (unit[1] & 0x1):
number_str+="m"
if (unit[1] & 0x2):
number_str+="%"
if (unit[1] & 0x4):
number_str+="M"
if (unit[2] & 0x1):
number_str+="F"
if (unit[2] & 0x2):
number_str+="Ω"
if (unit[3] & 0x1):
number_str+="A"
if (unit[3] & 0x2):
number_str+="V"
if (unit[3] & 0x4):
number_str+="Hz"
if (unit[4] & 0x2):
number_str+="°C"
if (unit[4] & 0x1):
number_str+="°F"
if(acdc&0xb == 0x0a):
number_str+=" DC"
if(acdc&0xb == 0x09):
number_str+=" AC"
return number_str return number_str
@ -48,28 +77,43 @@ def read_peaktech( ser ):
if(good==1): if(good==1):
for i in range(0, 0xf): for i in range(0, 0xf):
bytearr[i] = (bytearr[i] & 0x0F) bytearr[i] = (bytearr[i] & 0x0F)
print(binascii.hexlify(bytearr)) #print(binascii.hexlify(bytearr))
num1 = (bytearr[1]<<4) | bytearr[2] acdc = bytearr[0]
num2 = (bytearr[3]<<4) | bytearr[4]
num3 = (bytearr[5]<<4) | bytearr[6] num = []
num4 = (bytearr[7]<<4) | bytearr[8] num.append((bytearr[1]<<4) | bytearr[2])
num.append((bytearr[3]<<4) | bytearr[4])
num.append((bytearr[5]<<4) | bytearr[6])
if line[0:2] == b'\x1C\x20': num.append((bytearr[7]<<4) | bytearr[8])
print("Ohm")
if line[0:2] == b'\x18\x20': unit = []
print("beep") unit.append(bytearr[9] )
if line[0:1] == b'\x1e': unit.append(bytearr[10])
print("V DC") unit.append(bytearr[11])
if line[0:1] == b'\x1d': unit.append(bytearr[12])
print("V AC") unit.append(bytearr[13])
if line[0:2] == b'\x1c\x2e':
print("Hz") #print(unit[0])
if line[0:2] == b'\x18\x2e': #print(unit[1])
print("Temp") #print(unit[2])
#print(unit[3])
return crap_to_number([num1, num2, num3, num4]) #print(unit[4])
#if line[0:2] == b'\x1C\x20':
# print("Ohm")
#if line[0:2] == b'\x18\x20':
# print("beep")
#if line[0:1] == b'\x1e':
# print("V DC")
#if line[0:1] == b'\x1d':
# print("V AC")
#if line[0:2] == b'\x1c\x2e':
# print("Hz")
#if line[0:2] == b'\x18\x2e':
# print("Temp")
return crap_to_number(num, unit, acdc)
#if (len(line) == 14) and (line[5] == 0x20): #if (len(line) == 14) and (line[5] == 0x20):
# try: # try:
# value = float( line[0:5].decode("ascii") ) # value = float( line[0:5].decode("ascii") )

Loading…
Cancel
Save