irmajavi
New Member
Hello everyone, I would like to access to BMS of a Felicity Solar battery using python. Attached is the protocol definition.
If anyone can help me with the code. This is what I got so far:
import serial
import time
serial_port = "/dev/ttyUSB0"
serial_baud = 9600
full_command = bytes.fromhex("01 03 f8 0b 00 01 c4 a8")
response_line = None
print(full_command)
print(f"port {serial_port}, baudrate {serial_baud}")
try:
with serial.serial_for_url(serial_port, serial_baud) as s:
print("Executing command via serialio...")
s.timeout = 1
s.write_timeout = 1
s.flushInput()
s.flushOutput()
s.write(full_command)
#s.write(full_command+'\r')
time.sleep(0.1) # give serial port time to receive the data
response_line = s.read_until(b"\r")
print("serial response was: %s", response_line)
return response_line
except Exception as e:
print(f"Serial read error: {e}")
print("Command execution failed")
The only response I get is b' '.
Any suggestions?
If anyone can help me with the code. This is what I got so far:
import serial
import time
serial_port = "/dev/ttyUSB0"
serial_baud = 9600
full_command = bytes.fromhex("01 03 f8 0b 00 01 c4 a8")
response_line = None
print(full_command)
print(f"port {serial_port}, baudrate {serial_baud}")
try:
with serial.serial_for_url(serial_port, serial_baud) as s:
print("Executing command via serialio...")
s.timeout = 1
s.write_timeout = 1
s.flushInput()
s.flushOutput()
s.write(full_command)
#s.write(full_command+'\r')
time.sleep(0.1) # give serial port time to receive the data
response_line = s.read_until(b"\r")
print("serial response was: %s", response_line)
return response_line
except Exception as e:
print(f"Serial read error: {e}")
print("Command execution failed")
The only response I get is b' '.
Any suggestions?