Update diagnostics/os_diagnostics.py
This commit is contained in:
@@ -1,18 +1,28 @@
|
|||||||
from pybricks.pupdevices import Motor
|
|
||||||
from pybricks.parameters import Port
|
from pybricks.parameters import Port
|
||||||
from uerrno import EAGAIN, EBUSY, ECANCELED, EINVAL, EIO, ENODEV, EOPNOTSUPP, EPERM, ETIMEDOUT
|
from uerrno import EAGAIN, EBUSY, ECANCELED, EINVAL, EIO, ENODEV, EOPNOTSUPP, EPERM, ETIMEDOUT
|
||||||
|
class OSDiagnostics:
|
||||||
try:
|
def __init__(self, hub, motorclass):
|
||||||
# Try to initialize a motor on an empty port (Port.A)
|
self.motorclass = motorclass
|
||||||
input("Make sure Port A doesn't have anything plugged in, then press Enter.")
|
self.successfultests = 0
|
||||||
my_motor = Motor(Port.A)
|
self.failedtests = {}
|
||||||
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.")
|
def testenodev:
|
||||||
except OSError as ex:
|
try:
|
||||||
# If an OSError was raised, check the specific error code
|
# Try to initialize a motor on an empty port (Port.A)
|
||||||
if ex.errno == ENODEV:
|
print("Starting Test 6/9: ENODEV - Device Not Found Error")
|
||||||
print("There is no motor on this port. ENODEV can be ")
|
input("Make sure Port A doesn't have anything plugged in, then press Enter.")
|
||||||
elif ex.errno == EIO:
|
my_motor = self.motorclass(Port.A)
|
||||||
print("An I/O error occurred (EIO). Try unplugging/replugging the device.")
|
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.")
|
||||||
else:
|
except OSError as ex:
|
||||||
print(f"Another error occurred with code: {ex.errno}")
|
# 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 thrown and caught.\nCompleted Test 6/9: ENODEV - SUCCESSFUL")
|
||||||
|
self.successfultests += 1
|
||||||
|
elif ex.errno == EIO:
|
||||||
|
print("An unspecified error occurred (EIO).\nCompleted Test 6/9: ENODEV - FAILED")
|
||||||
|
self.failedtests["ENODEV"] = "EIO - Unspecified Error"
|
||||||
|
else:
|
||||||
|
print(f"Another error occurred with code: {ex.errno}.\nCompleted Test 6/9: ENODEV - FAILED")
|
||||||
|
self.failedtests["ENODEV"] = ex.errno
|
||||||
|
def print_results:
|
||||||
|
for key, value in self.failedtests():
|
||||||
|
print(f"{key}: {value}")
|
||||||
|
|||||||
Reference in New Issue
Block a user