Files
pybricks-api/examples/micropython/oserror.py
T
Laurens Valk d00bf35c66 all: ruff check --fix.
Mainly fixes and sorts imports.
2026-08-25 12:22:28 +02:00

19 lines
539 B
Python

from pybricks.parameters import Port
from pybricks.pupdevices import Motor
from uerrno import ENODEV
try:
# Try to initialize a motor.
my_motor = Motor(Port.A)
# If all goes well, you'll see this message.
print("Detected a motor.")
except OSError as ex:
# If an OSError was raised, we can check what
# kind of error this was, like ENODEV.
if ex.errno == ENODEV:
# ENODEV is short for "Error, no device."
print("There is no motor this port.")
else:
print("Another error occurred.")