Selected / Driver gegen nun einen DeviceNotFoundError aus, wenn nicht vorhanden

debug und replace_io_file über Namen abrufbar
This commit is contained in:
2019-07-23 09:09:34 +02:00
parent 56945d607e
commit 40d7c132a5
7 changed files with 99 additions and 15 deletions

View File

@@ -38,6 +38,13 @@ MEM = 302
warnings.simplefilter(action="always")
class DeviceNotFoundError(Exception):
"""Fehler wenn ein Device nicht gefunden wird."""
pass
def acheck(check_type, **kwargs):
"""Check type of given arguments.

View File

@@ -10,7 +10,7 @@ from json import load as jload
from multiprocessing import cpu_count
from os import access, F_OK, R_OK
from queue import Empty
from revpimodio2 import acheck
from revpimodio2 import acheck, DeviceNotFoundError
from signal import signal, SIG_DFL, SIGINT, SIGTERM
from threading import Thread, Event, Lock
from timeit import default_timer
@@ -368,9 +368,7 @@ class RevPiModIO(object):
except Exception as e:
raise RuntimeError(
"replace_io_file: can not replace '{0}' with '{1}' "
"| RevPiModIO message: {2}".format(
parentio, io, e
)
"| RevPiModIO message: {2}".format(parentio, io, e)
)
def _create_myfh(self):
@@ -389,6 +387,11 @@ class RevPiModIO(object):
@return Millisekunden"""
return self._imgwriter.refresh
def _get_debug(self):
"""Gibt Status des Debugflags zurueck.
@return Status des Debugflags"""
return self._debug
def _get_ioerrors(self):
"""Getter function.
@return Aktuelle Anzahl gezaehlter Fehler"""
@@ -417,6 +420,11 @@ class RevPiModIO(object):
@return Pfad des verwendeten Prozessabbilds"""
return self._procimg
def _get_replace_io_file(self):
"""Gibt Pfad zur verwendeten replace IO Datei aus.
@return Pfad zur replace IO Datei"""
return self._replace_io_file
def _get_simulator(self):
"""Getter function.
@return True, wenn als Simulator gestartet"""
@@ -992,6 +1000,7 @@ class RevPiModIO(object):
return workokay
debug = property(_get_debug)
configrsc = property(_get_configrsc)
cycletime = property(_get_cycletime, _set_cycletime)
ioerrors = property(_get_ioerrors)
@@ -999,6 +1008,7 @@ class RevPiModIO(object):
maxioerrors = property(_get_maxioerrors, _set_maxioerrors)
monitoring = property(_get_monitoring)
procimg = property(_get_procimg)
replace_io_file = property(_get_replace_io_file)
simulator = property(_get_simulator)
@@ -1052,20 +1062,20 @@ class RevPiModIOSelected(RevPiModIO):
if len(self.device) == 0:
if type(self) == RevPiModIODriver:
raise RuntimeError(
raise DeviceNotFoundError(
"could not find any given VIRTUAL devices in config"
)
else:
raise RuntimeError(
raise DeviceNotFoundError(
"could not find any given devices in config"
)
elif len(self.device) != len(self._lst_devselect):
if type(self) == RevPiModIODriver:
raise RuntimeError(
raise DeviceNotFoundError(
"could not find all given VIRTUAL devices in config"
)
else:
raise RuntimeError(
raise DeviceNotFoundError(
"could not find all given devices in config"
)

View File

@@ -3,11 +3,11 @@
__author__ = "Sven Sager"
__copyright__ = "Copyright (C) 2018 Sven Sager"
__license__ = "LGPLv3"
import socket
import warnings
from json import loads as jloads
from re import compile
from revpimodio2 import DeviceNotFoundError
from threading import Thread, Event, Lock
from .device import Device
@@ -696,20 +696,20 @@ class RevPiNetIOSelected(RevPiNetIO):
if len(self.device) == 0:
if type(self) == RevPiNetIODriver:
raise RuntimeError(
raise DeviceNotFoundError(
"could not find any given VIRTUAL devices in config"
)
else:
raise RuntimeError(
raise DeviceNotFoundError(
"could not find any given devices in config"
)
elif len(self.device) != len(self._lst_devselect):
if type(self) == RevPiNetIODriver:
raise RuntimeError(
raise DeviceNotFoundError(
"could not find all given VIRTUAL devices in config"
)
else:
raise RuntimeError(
raise DeviceNotFoundError(
"could not find all given devices in config"
)