Created
March 4, 2025 18:36
-
-
Save RAD750/19982bf995cfd38f9ac14acdbfc6d9b5 to your computer and use it in GitHub Desktop.
TF03K TTL232 Serial decoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import sys | |
ser = serial.Serial( | |
port='/dev/ttyUSB0',\ | |
baudrate=19200,\ | |
parity=serial.PARITY_NONE,\ | |
stopbits=serial.STOPBITS_ONE,\ | |
bytesize=serial.EIGHTBITS,\ | |
timeout=2) | |
print("connected to: " + ser.portstr) | |
count=1 | |
comm = ser.read(16) | |
bat_perc = int(comm[1]) | |
print("Percentage: " + str(bat_perc)) | |
bat_v = int(comm[2]<<8 | comm[3])/100 | |
print("Battery: " + str(bat_v)) | |
bat_cap = int(comm[4]<<24 | comm[5]<<16 | comm[6] <<8 |comm[7])/1000 | |
print("Capacity: " + str(bat_cap)) | |
bat_curr = (int(comm[8]<<24 | comm[9]<<16 | comm[10] <<8 | comm[11]) - 4294967295) / 1000 | |
print("Current: " + str(bat_curr)) | |
rem_time = int(comm[12]<<16 | comm[13]<<8 | comm[14]) | |
print("Remtime: " + str(rem_time)) | |
ser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment