openflexure-microscope-server/openflexure_microscope/rescue/check_sangaboard.py
Richard Bowman a9fff24848 Explicitly specify encoding
The update to pylint means we were failing because open()
doesn't specify the encoding everywhere.  I have now specified utf-8
everywhere.  This was patchy before, and is default behaviour on the
Pi.  There's a slim chance it will cause some issues on Windows, but
that shouldn't affect anyone outside the developers.

I've also ignored a couple of new spurious warnings, and explicitly
ignored some unused variables.
2022-08-09 07:16:44 +01:00

45 lines
1.5 KiB
Python

from openflexure_microscope.config import user_configuration
from .error_sources import ErrorSource
def main():
error_sources = []
try:
from sangaboard import Sangaboard
except ImportError as e:
error_sources.append(ErrorSource(str(e)))
else:
configuration = user_configuration.load()
stage_type = configuration["stage"].get("type")
stage_port = configuration["stage"].get("port")
# If any Sangaboard-based stage is configured for use
if stage_type in ("SangaBoard", "SangaStage", "SangaDeltaStage"):
# Try connecting on the specified port
try:
stage = Sangaboard(stage_port)
except FileNotFoundError as _:
if stage_port:
error_sources.append(
ErrorSource(
f"No {stage_type} device was found on the configured port {stage_port}."
)
)
else:
error_sources.append(
ErrorSource(
f"No {stage_type} device was found during port scanning."
)
)
else:
stage.close()
else:
error_sources.append(
ErrorSource(
f"Invalid stage type {stage_type} specified in configuration file."
)
)
return error_sources