I am also getting the error “InvalidOperatingModeException: Could not determine operating mode” when I try to open the device.
I am entering API mode by writing “ATAP1\r” to serial.
I am also getting the error “InvalidOperatingModeException: Could not determine operating mode” when I try to open the device.
I am entering API mode by writing “ATAP1\r” to serial.
You need to enter command mode first by sending the command mode sequence.
First, I send the command mode sequence “+++” and wait for “OK” which I don’t seem to be receiving and thus never enter the if statement that is suppose to send the command.
def command_mode(command):
for _ in range(10): # Limit retry count
time.sleep(0.1)
ser.write(“+”.encode(“ascii”))
time.sleep(0.1)
ser.write(“+”.encode(“ascii”))
time.sleep(0.1)
ser.write(“+”.encode(“ascii”))
print(“+++”)
receive = ser.read(ser.in_waiting)
print(str(receive).find(“OK”))
if str(receive).find(“OK”) != -1:
ser.write((command + “\r”).encode(“ascii”))
break
Don’t wait between each + you send. That is probably why you are not entering command mode.