Describing the bug
The bug only appears to be present in the beta pybricks firmware (Pybricks MicroPython v1.20.0-23-g6c633a8dd on 2023-07-07; SPIKE Prime Hub with STM32F413VG).
When writing to a PUPDevice, the write(mode,data) method is used, with the mode the mode of the sensor to write data to. E.g. the Distance sensor uses mode 5 to set the values of LEDS around the two sensors with 4 segments representing the 4 bytes of the data. When I read another mode first, and write immediately to mode 5, I get an error.
Using the latest pybricks firmware (Pybricks MicroPython v3.2.3 on 2023-02-17; SPIKE Prime Hub with STM32F413VG) this works OK, and the program below does not result in an error.
To reproduce
Steps to reproduce the behavior:
Flash Spike Prime hub with beta firmware (Pybricks MicroPython v1.20.0-23-g6c633a8dd on 2023-07-07; SPIKE Prime Hub with STM32F413VG)
Connect the distance sensor to port A
Run the following program:
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
hub = PrimeHub()
from pybricks.iodevices import PUPDevice
p=PUPDevice(Port.A)
#correct
print("read mode 1=",p.read(1))
print("read mode 5=",p.read(5))
p.write(5,[1,1,1,1])
print("success")
# failure
print("read mode 1=",p.read(1))
p.write(5,[1,1,1,1])
The requested operation is not valid in the current state:
--> Check the documentation for required conditions.
--> Check the line in your script that matches
the line number given in the 'Traceback' above.
**Expected behavior**
The program should run without errors.
**Screenshots**
![image](https://github.com/pybricks/support/assets/51531682/2cbee501-cfde-43ff-9a60-3c82ccd4fa95)
Describing the bug The bug only appears to be present in the beta pybricks firmware (Pybricks MicroPython v1.20.0-23-g6c633a8dd on 2023-07-07; SPIKE Prime Hub with STM32F413VG).
When writing to a PUPDevice, the
write(mode,data)
method is used, with themode
the mode of the sensor to write data to. E.g. the Distance sensor uses mode 5 to set the values of LEDS around the two sensors with 4 segments representing the 4 bytes of the data. When I read another mode first, and write immediately to mode 5, I get an error. Using the latest pybricks firmware (Pybricks MicroPython v3.2.3 on 2023-02-17; SPIKE Prime Hub with STM32F413VG) this works OK, and the program below does not result in an error.To reproduce Steps to reproduce the behavior:
The requested operation is not valid in the current state: --> Check the documentation for required conditions. --> Check the line in your script that matches the line number given in the 'Traceback' above.