make single converion per function call
This commit is contained in:
26
peaktech.py
26
peaktech.py
@@ -19,14 +19,10 @@ def crap_to_number(crap):
|
||||
0xeb:"0"
|
||||
}
|
||||
number_str+=switch.get(elem, "-")
|
||||
print(number_str)
|
||||
return number_str
|
||||
|
||||
|
||||
def read_peaktech( port ):
|
||||
try:
|
||||
with Serial( port , 2400) as ser:
|
||||
print(ser.name)
|
||||
while True:
|
||||
def read_peaktech( ser ):
|
||||
line = ser.read_until( b'\xf1' )
|
||||
#print(binascii.hexlify(line))
|
||||
|
||||
@@ -50,7 +46,6 @@ def read_peaktech( port ):
|
||||
num3 = (bytearr[5]<<4) | bytearr[6]
|
||||
num4 = (bytearr[7]<<4) | bytearr[8]
|
||||
|
||||
crap_to_number([num1, num2, num3, num4])
|
||||
|
||||
if line[0:2] == b'\x1C\x20':
|
||||
print("Ohm")
|
||||
@@ -65,6 +60,7 @@ def read_peaktech( port ):
|
||||
if line[0:2] == b'\x18\x2e':
|
||||
print("Temp")
|
||||
|
||||
return crap_to_number([num1, num2, num3, num4])
|
||||
#if (len(line) == 14) and (line[5] == 0x20):
|
||||
# try:
|
||||
# value = float( line[0:5].decode("ascii") )
|
||||
@@ -111,10 +107,6 @@ def read_peaktech( port ):
|
||||
# unit = ""
|
||||
|
||||
# print( f"{value}{prefix}{unit}" )
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except Exception as ex:
|
||||
print( "Exception:", ex )
|
||||
|
||||
if __name__ == "__main__":
|
||||
port = "/dev/ttyUSB0"
|
||||
@@ -122,4 +114,14 @@ if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
port = sys.argv[1]
|
||||
|
||||
read_peaktech( port )
|
||||
try:
|
||||
with Serial( port , 2400) as ser:
|
||||
print(ser.name)
|
||||
while True:
|
||||
print(read_peaktech(ser))
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except Exception as ex:
|
||||
print( "Exception:", ex )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user