Skip to content

Instantly share code, notes, and snippets.

@atiti
Created November 20, 2020 14:14
Show Gist options
  • Save atiti/bf9ef7cbe609893087f69b3c372a0aa1 to your computer and use it in GitHub Desktop.
Save atiti/bf9ef7cbe609893087f69b3c372a0aa1 to your computer and use it in GitHub Desktop.
Quick python script to dump data from UM25C
#!/usr/bin/python3
import sys, signal, traceback, serial, time
def signal_handler(sig, frame):
global ser
print('Ctrl-C, quitting.')
if ser:
ser.close()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
ser = None
if len(sys.argv) < 2:
print("Usage:", sys.argv[0], "<serial port>")
sys.exit(1)
try:
ser = serial.Serial(sys.argv[1], 9600, timeout=3)
except:
print("Failed to open the serial port.")
traceback.print_exc()
sys.exit(1)
while 1:
ser.write(b'\xf0')
time.sleep(0.1)
b = ser.read(130)
if len(b) <= 0:
continue
if b[0] == 0x09 and b[1] == 0xc9:
voltage = float((b[2] << 8) + b[3]) / 1000.0
amperage = float((b[4] << 8) + b[5]) / 10000.0
temperature = float((b[10] << 8) + b[11])
print(time.time(), ",", voltage, ",", amperage, ",", temperature)
else:
print("Invalid device type")
break
ser.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment