add more units
This commit is contained in:
88
peaktech.py
88
peaktech.py
@@ -3,14 +3,14 @@ from math import inf
|
||||
import sys
|
||||
import binascii
|
||||
|
||||
def crap_to_number(crap):
|
||||
def crap_to_number(num, unit, acdc):
|
||||
number_str = ""
|
||||
|
||||
if(crap[0]&0x10):
|
||||
if(num[0]&0x10):
|
||||
number_str+="-"
|
||||
crap[0] &= 0xEF
|
||||
num[0] &= 0xEF
|
||||
|
||||
for elem in crap:
|
||||
for elem in num:
|
||||
if(elem & 0x10 != 0):
|
||||
number_str+="."
|
||||
switch={
|
||||
@@ -28,6 +28,35 @@ def crap_to_number(crap):
|
||||
0x00:" "
|
||||
}
|
||||
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
|
||||
|
||||
|
||||
@@ -48,28 +77,43 @@ def read_peaktech( ser ):
|
||||
if(good==1):
|
||||
for i in range(0, 0xf):
|
||||
bytearr[i] = (bytearr[i] & 0x0F)
|
||||
print(binascii.hexlify(bytearr))
|
||||
#print(binascii.hexlify(bytearr))
|
||||
|
||||
num1 = (bytearr[1]<<4) | bytearr[2]
|
||||
num2 = (bytearr[3]<<4) | bytearr[4]
|
||||
num3 = (bytearr[5]<<4) | bytearr[6]
|
||||
num4 = (bytearr[7]<<4) | bytearr[8]
|
||||
acdc = bytearr[0]
|
||||
|
||||
num = []
|
||||
num.append((bytearr[1]<<4) | bytearr[2])
|
||||
num.append((bytearr[3]<<4) | bytearr[4])
|
||||
num.append((bytearr[5]<<4) | bytearr[6])
|
||||
num.append((bytearr[7]<<4) | bytearr[8])
|
||||
|
||||
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")
|
||||
unit = []
|
||||
unit.append(bytearr[9] )
|
||||
unit.append(bytearr[10])
|
||||
unit.append(bytearr[11])
|
||||
unit.append(bytearr[12])
|
||||
unit.append(bytearr[13])
|
||||
|
||||
return crap_to_number([num1, num2, num3, num4])
|
||||
#print(unit[0])
|
||||
#print(unit[1])
|
||||
#print(unit[2])
|
||||
#print(unit[3])
|
||||
#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):
|
||||
# try:
|
||||
# value = float( line[0:5].decode("ascii") )
|
||||
|
||||
Reference in New Issue
Block a user