Add diagnostics/os_diagnostics.py

This commit is contained in:
2026-03-06 16:34:42 +00:00
parent eb13361f4f
commit 644d338957

View File

@@ -0,0 +1,18 @@
from pybricks.pupdevices import Motor
from pybricks.parameters import Port
from uerrno import EAGAIN, EBUSY, ECANCELED, EINVAL, EIO, ENODEV, EOPNOTSUPP, EPERM, ETIMEDOUT
try:
# Try to initialize a motor on an empty port (Port.A)
input("Make sure Port A doesn't have anything plugged in, then press Enter.")
my_motor = Motor(Port.A)
print("OS detected a motor when there was nothing. You may have allowed missing motors. This is useful for debugging, but not recommended for production as it can cause issues with device control.")
except OSError as ex:
# If an OSError was raised, check the specific error code
if ex.errno == ENODEV:
print("There is no motor on this port. ENODEV can be ")
elif ex.errno == EIO:
print("An I/O error occurred (EIO). Try unplugging/replugging the device.")
else:
print(f"Another error occurred with code: {ex.errno}")