Indexzugriff auf IOs eines Devices

This commit is contained in:
2019-07-23 09:59:24 +02:00
parent 40d7c132a5
commit 23f9095d5c
4 changed files with 53 additions and 6 deletions

View File

@@ -556,6 +556,9 @@ Methods</h3>
<td><a style="color:#0000FF" href="#Device.__getioiter">__getioiter</a></td> <td><a style="color:#0000FF" href="#Device.__getioiter">__getioiter</a></td>
<td>Gibt <class 'iter'> mit allen IOs zurueck.</td> <td>Gibt <class 'iter'> mit allen IOs zurueck.</td>
</tr><tr> </tr><tr>
<td><a style="color:#0000FF" href="#Device.__getitem__">__getitem__</a></td>
<td>Gibt IO an angegebener Stelle zurueck.</td>
</tr><tr>
<td><a style="color:#0000FF" href="#Device.__int__">__int__</a></td> <td><a style="color:#0000FF" href="#Device.__int__">__int__</a></td>
<td>Gibt die Positon im RevPi Bus zurueck.</td> <td>Gibt die Positon im RevPi Bus zurueck.</td>
</tr><tr> </tr><tr>
@@ -580,6 +583,9 @@ Methods</h3>
<td><a style="color:#0000FF" href="#Device._get_producttype">_get_producttype</a></td> <td><a style="color:#0000FF" href="#Device._get_producttype">_get_producttype</a></td>
<td>Gibt den Produkttypen des device zurueck.</td> <td>Gibt den Produkttypen des device zurueck.</td>
</tr><tr> </tr><tr>
<td><a style="color:#0000FF" href="#Device._update_my_io_list">_update_my_io_list</a></td>
<td>Erzeugt eine neue IO Liste fuer schnellen Zugriff.</td>
</tr><tr>
<td><a style="color:#0000FF" href="#Device.autorefresh">autorefresh</a></td> <td><a style="color:#0000FF" href="#Device.autorefresh">autorefresh</a></td>
<td>Registriert dieses Device fuer die automatische Synchronisierung.</td> <td>Registriert dieses Device fuer die automatische Synchronisierung.</td>
</tr><tr> </tr><tr>
@@ -676,6 +682,22 @@ Filter fuer 'Export' Flag in piCtory
<dd> <dd>
IOs als Iterator IOs als Iterator
</dd> </dd>
</dl><a NAME="Device.__getitem__" ID="Device.__getitem__"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
Device.__getitem__</h3>
<b>__getitem__</b>(<i>key</i>)
<p>
Gibt IO an angegebener Stelle zurueck.
</p><dl>
<dt><i>key</i></dt>
<dd>
Index des IOs auf dem device als <class 'int'>
</dd>
</dl><dl>
<dt>Returns:</dt>
<dd>
Gefundenes IO-Objekt
</dd>
</dl><a NAME="Device.__int__" ID="Device.__int__"></a> </dl><a NAME="Device.__int__" ID="Device.__int__"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000"> <h3 style="background-color:#FFFFFF;color:#FF0000">
Device.__int__</h3> Device.__int__</h3>
@@ -767,7 +789,13 @@ Gibt den Produkttypen des device zurueck.
<dd> <dd>
Deviceprodukttyp Deviceprodukttyp
</dd> </dd>
</dl><a NAME="Device.autorefresh" ID="Device.autorefresh"></a> </dl><a NAME="Device._update_my_io_list" ID="Device._update_my_io_list"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
Device._update_my_io_list</h3>
<b>_update_my_io_list</b>(<i></i>)
<p>
Erzeugt eine neue IO Liste fuer schnellen Zugriff.
</p><a NAME="Device.autorefresh" ID="Device.autorefresh"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000"> <h3 style="background-color:#FFFFFF;color:#FF0000">
Device.autorefresh</h3> Device.autorefresh</h3>
<b>autorefresh</b>(<i>activate=True</i>) <b>autorefresh</b>(<i>activate=True</i>)
@@ -1049,7 +1077,7 @@ DeviceList.__iter__</h3>
Gibt Iterator aller Devices zurueck. Gibt Iterator aller Devices zurueck.
</p><p> </p><p>
Die Reihenfolge ist nach Position im Prozessabbild sortiert und nicht Die Reihenfolge ist nach Position im Prozessabbild sortiert und nicht
nach Position (Dies entspricht der Positionierung aus piCtory)! nach Positionsnummer (Dies entspricht der Positionierung aus piCtory)!
</p><dl> </p><dl>
<dt>Returns:</dt> <dt>Returns:</dt>
<dd> <dd>

View File

@@ -43,6 +43,7 @@ revpimodio2.device.Device._buildio?5(dict_io, iotype)
revpimodio2.device.Device._devconfigure?5() revpimodio2.device.Device._devconfigure?5()
revpimodio2.device.Device._get_offset?5() revpimodio2.device.Device._get_offset?5()
revpimodio2.device.Device._get_producttype?5() revpimodio2.device.Device._get_producttype?5()
revpimodio2.device.Device._update_my_io_list?5()
revpimodio2.device.Device.autorefresh?4(activate=True) revpimodio2.device.Device.autorefresh?4(activate=True)
revpimodio2.device.Device.get_allios?4(export=None) revpimodio2.device.Device.get_allios?4(export=None)
revpimodio2.device.Device.get_inputs?4(export=None) revpimodio2.device.Device.get_inputs?4(export=None)

View File

@@ -72,7 +72,7 @@ class DeviceList(object):
"""Gibt Iterator aller Devices zurueck. """Gibt Iterator aller Devices zurueck.
Die Reihenfolge ist nach Position im Prozessabbild sortiert und nicht Die Reihenfolge ist nach Position im Prozessabbild sortiert und nicht
nach Position (Dies entspricht der Positionierung aus piCtory)! nach Positionsnummer (Dies entspricht der Positionierung aus piCtory)!
@return <class 'iter'> aller Devices""" @return <class 'iter'> aller Devices"""
for dev in sorted( for dev in sorted(
@@ -106,7 +106,7 @@ class Device(object):
""" """
__slots__ = "_ba_devdata", "_ba_datacp", \ __slots__ = "__my_io_list", "_ba_devdata", "_ba_datacp", \
"_dict_events", "_filelock", "_length", "_modio", "_name", "_offset", \ "_dict_events", "_filelock", "_length", "_modio", "_name", "_offset", \
"_position", "_producttype", "_selfupdate", "_slc_devoff", \ "_position", "_producttype", "_selfupdate", "_slc_devoff", \
"_slc_inp", "_slc_inpoff", "_slc_mem", "_slc_memoff", \ "_slc_inp", "_slc_inpoff", "_slc_mem", "_slc_memoff", \
@@ -126,6 +126,7 @@ class Device(object):
self._dict_events = {} self._dict_events = {}
self._filelock = Lock() self._filelock = Lock()
self._length = 0 self._length = 0
self.__my_io_list = []
self._selfupdate = False self._selfupdate = False
# Wertzuweisung aus dict_device # Wertzuweisung aus dict_device
@@ -182,6 +183,9 @@ class Device(object):
# Spezielle Konfiguration von abgeleiteten Klassen durchführen # Spezielle Konfiguration von abgeleiteten Klassen durchführen
self._devconfigure() self._devconfigure()
# IO Liste aktualisieren für schnellen Indexzugriff
self._update_my_io_list()
def __bytes__(self): def __bytes__(self):
"""Gibt alle Daten des Devices als <class 'bytes'> zurueck. """Gibt alle Daten des Devices als <class 'bytes'> zurueck.
@return Devicedaten als <class 'bytes'>""" @return Devicedaten als <class 'bytes'>"""
@@ -205,6 +209,12 @@ class Device(object):
return key in self._modio.io \ return key in self._modio.io \
and getattr(self._modio.io, key)._parentdevice == self and getattr(self._modio.io, key)._parentdevice == self
def __getitem__(self, key):
"""Gibt IO an angegebener Stelle zurueck.
@param key Index des IOs auf dem device als <class 'int'>
@return Gefundenes IO-Objekt"""
return self.__my_io_list[key]
def __int__(self): def __int__(self):
"""Gibt die Positon im RevPi Bus zurueck. """Gibt die Positon im RevPi Bus zurueck.
@return Positionsnummer""" @return Positionsnummer"""
@@ -312,6 +322,10 @@ class Device(object):
@return Deviceprodukttyp""" @return Deviceprodukttyp"""
return self._producttype return self._producttype
def _update_my_io_list(self):
"""Erzeugt eine neue IO Liste fuer schnellen Zugriff."""
self.__my_io_list = list(self.__iter__())
def autorefresh(self, activate=True): def autorefresh(self, activate=True):
"""Registriert dieses Device fuer die automatische Synchronisierung. """Registriert dieses Device fuer die automatische Synchronisierung.
@param activate Default True fuegt Device zur Synchronisierung hinzu""" @param activate Default True fuegt Device zur Synchronisierung hinzu"""

View File

@@ -68,6 +68,7 @@ class IOList(object):
self.__dict_iobyte[io_del.address] = [] self.__dict_iobyte[io_del.address] = []
object.__delattr__(self, key) object.__delattr__(self, key)
io_del._parentdevice._update_my_io_list()
def __getattr__(self, key): def __getattr__(self, key):
"""Verwaltet geloeschte IOs (Attribute, die nicht existieren). """Verwaltet geloeschte IOs (Attribute, die nicht existieren).
@@ -125,10 +126,10 @@ class IOList(object):
def __setattr__(self, key, value): def __setattr__(self, key, value):
"""Verbietet aus Leistungsguenden das direkte Setzen von Attributen.""" """Verbietet aus Leistungsguenden das direkte Setzen von Attributen."""
if key in [ if key in (
"_IOList__dict_iobyte", "_IOList__dict_iobyte",
"_IOList__dict_iorefname" "_IOList__dict_iorefname"
]: ):
object.__setattr__(self, key, value) object.__setattr__(self, key, value)
else: else:
raise AttributeError( raise AttributeError(
@@ -221,6 +222,9 @@ class IOList(object):
None, None, None, None, None, None, None, None None, None, None, None, None, None, None, None
] ]
self.__dict_iobyte[new_io.address][new_io._bitaddress] = new_io self.__dict_iobyte[new_io.address][new_io._bitaddress] = new_io
if type(new_io) is StructIO:
new_io._parentdevice._update_my_io_list()
else: else:
raise TypeError("io must be <class 'IOBase'> or sub class") raise TypeError("io must be <class 'IOBase'> or sub class")