hey
i have this simple script to write 1 to QX6.7
❯ cat read_modbus.py
import minimalmodbus
import time
# Configure instrument
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 2) # slave ID 2
instrument.serial.baudrate = 19200
instrument.serial.bytesize = 8
instrument.serial.parity = 'N'
instrument.serial.stopbits = 1
instrument.serial.timeout = 0.5
instrument.serial.write_timeout = 0.5
instrument.close_port_after_each_call = True # helps if ESP resets occasionally
instrument.debug = False # True for raw Modbus bytes debugging
RETRIES = 3 # retry count for each operation
DELAY = 0.05 # delay between reads/writes in seconds
def safe_write_bit(address, value):
for attempt in range(RETRIES):
try:
instrument.write_bit(address, value)
return True
except (minimalmodbus.NoResponseError, minimalmodbus.InvalidResponseError):
time.sleep(DELAY)
return False
def safe_read_bit(address):
for attempt in range(RETRIES):
try:
return instrument.read_bit(address, 1)
except (minimalmodbus.NoResponseError, minimalmodbus.InvalidResponseError):
time.sleep(DELAY)
return None # failed after retries
try:
print("Turning ON Manual Override...")
if not safe_write_bit(55, 1): # QX6.7
print("Failed to write Manual Bit after retries")
else:
print("Manual Bit set, monitoring states for 5 seconds...")
start = time.time()
while time.time() - start < 5:
manual_bit = safe_read_bit(55)
relay_state = safe_read_bit(0)
print(f"Manual Bit: {manual_bit} | Relay: {relay_state}")
if manual_bit == 0:
print("!!! The ESP32 just reset the Manual Bit to 0.")
break
time.sleep(DELAY)
except Exception as e:
print(f"Unexpected error: {e}")
and i have this
![[203128%2F9714938%2Fmceclip0]](https://d28lcup14p4e72.cloudfront.net/203128%2F9714938%2Fmceclip0.png)
MANUAL_ENABLE is the bool at QX6.7, and RELAY_CTRL_1 is the led
when running the script the led does turn on for a few seconds but then it reset back to zero
any way to force it without rewriting 1?