add single read function
This commit is contained in:
13
peaktech.py
13
peaktech.py
@@ -61,16 +61,16 @@ def crap_to_number(num, unit, acdc):
|
||||
|
||||
|
||||
def read_peaktech( ser ):
|
||||
|
||||
line = ser.read_until( b'\xf1' )
|
||||
#print(binascii.hexlify(line))
|
||||
|
||||
good=1
|
||||
if(len(line) == 15):
|
||||
for i in range(0, 0xf):
|
||||
if i+1 != ((line[i]&0xF0)>>4):
|
||||
good=0
|
||||
else:
|
||||
good=0
|
||||
line = ser.read_until( b'\xf1' )
|
||||
|
||||
bytearr = bytearray(line)
|
||||
|
||||
@@ -161,6 +161,15 @@ def read_peaktech( ser ):
|
||||
|
||||
# print( f"{value}{prefix}{unit}" )
|
||||
|
||||
def read():
|
||||
ser = Serial("/dev/ttyUSB0", 2400)
|
||||
res = read_peaktech(ser)
|
||||
try:
|
||||
res = int(res)
|
||||
except:
|
||||
res = 0
|
||||
return res
|
||||
|
||||
if __name__ == "__main__":
|
||||
port = "/dev/ttyUSB0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user