setup.py für Package angepasst

get_inps _outs _mems umbenannt in get_inputs _outputs _memmories
IOType von __init__ auf io.Type geändert
IOBase.type eingefügt
This commit is contained in:
2017-08-18 18:41:43 +02:00
parent e124da758f
commit 37eb012e16
10 changed files with 138 additions and 65 deletions

View File

@@ -35,12 +35,3 @@ FALLING = 32
BOTH = 33
warnings.simplefilter(action="always")
class IOType(object):
"""IO Typen."""
INP = 300
OUT = 301
MEM = 302

View File

@@ -7,7 +7,6 @@
# -*- coding: utf-8 -*-
"""Modul fuer die Verwaltung der Devices."""
from threading import Lock
from .__init__ import IOType
from .helper import ProcimgWriter
@@ -99,12 +98,16 @@ class Device(object):
# IOM-Objekte erstellen und Adressen in SLCs speichern
if kwargs.get("simulator", False):
self.slc_inp = self._buildio(dict_device.pop("out"), IOType.INP)
self.slc_out = self._buildio(dict_device.pop("inp"), IOType.OUT)
self.slc_inp = self._buildio(
dict_device.pop("out"), iomodule.Type.INP)
self.slc_out = self._buildio(
dict_device.pop("inp"), iomodule.Type.OUT)
else:
self.slc_inp = self._buildio(dict_device.pop("inp"), IOType.INP)
self.slc_out = self._buildio(dict_device.pop("out"), IOType.OUT)
self.slc_mem = self._buildio(dict_device.pop("mem"), IOType.MEM)
self.slc_inp = self._buildio(
dict_device.pop("inp"), iomodule.Type.INP)
self.slc_out = self._buildio(
dict_device.pop("out"), iomodule.Type.OUT)
self.slc_mem = self._buildio(dict_device.pop("mem"), iomodule.Type.MEM)
# SLCs mit offset berechnen
self.slc_devoff = slice(self.offset, self.offset + self._length)
@@ -174,7 +177,7 @@ class Device(object):
"""Erstellt aus der piCtory-Liste die IOs fuer dieses Device.
@param dict_io dict()-Objekt aus piCtory Konfiguration
@param iotype IOType() Wert
@param iotype io.Type() Wert
@return slice()-Objekt mit Start und Stop Position dieser IOs
"""
@@ -267,7 +270,7 @@ class Device(object):
lst_return += lst_io
return lst_return
def get_inps(self):
def get_inputs(self):
"""Gibt eine Liste aller Inputs zurueck.
@return list() Inputs"""
lst_return = []
@@ -275,7 +278,7 @@ class Device(object):
lst_return += lst_io
return lst_return
def get_outs(self):
def get_outputs(self):
"""Gibt eine Liste aller Outputs zurueck.
@return list() Outputs"""
lst_return = []
@@ -283,7 +286,7 @@ class Device(object):
lst_return += lst_io
return lst_return
def get_mems(self):
def get_memmories(self):
"""Gibt eine Liste aller mems zurueck.
@return list() Mems"""
lst_return = []
@@ -537,9 +540,9 @@ class Gateway(Device):
super().__init__(parent, dict_device, **kwargs)
self._dict_slc = {
IOType.INP: self.slc_inp,
IOType.OUT: self.slc_out,
IOType.MEM: self.slc_mem
iomodule.Type.INP: self.slc_inp,
iomodule.Type.OUT: self.slc_out,
iomodule.Type.MEM: self.slc_mem
}
def get_rawbytes(self):

View File

@@ -8,7 +8,16 @@
"""RevPiModIO Modul fuer die Verwaltung der IOs."""
import struct
from threading import Event
from .__init__ import RISING, FALLING, BOTH, IOType
from .__init__ import RISING, FALLING, BOTH
class Type(object):
"""IO Typen."""
INP = 300
OUT = 301
MEM = 302
class IOList(object):
@@ -207,7 +216,7 @@ class IOBase(object):
@param parentdevice Parentdevice auf dem der IO liegt
@param valuelist Datenliste fuer Instantiierung
@param iotype IOType() Wert
@param iotype io.Type() Wert
@param byteorder Byteorder 'little' / 'big' fuer int() Berechnung
@param sigend Intberechnung mit Vorzeichen durchfuehren
@@ -291,6 +300,11 @@ class IOBase(object):
@return str() Byteorder"""
return self._byteorder
def _get_iotype(self):
"""Gibt io.Type zurueck.
@return int() io.Type"""
return self._iotype
def _get_length(self):
"""Gibt die Bytelaenge des IO zurueck.
@return Bytelaenge des IO"""
@@ -400,13 +414,13 @@ class IOBase(object):
reg_event = kwargs.get("event", None)
if reg_event is not None:
as_thread = kwargs.get("as_thread", False)
edge = kwargs.get("edge", None)
edge = kwargs.get("edge", BOTH)
io_new.reg_event(reg_event, as_thread=as_thread, edge=edge)
def set_value(self, value):
"""Setzt den Wert des IOs mit bytes() oder bool().
@param value IO-Wert als bytes() oder bool()"""
if self._iotype == IOType.OUT:
if self._iotype == Type.OUT:
if self._bitaddress >= 0:
# Versuchen egal welchen Typ in Bool zu konvertieren
value = bool(value)
@@ -437,18 +451,25 @@ class IOBase(object):
value
else:
raise ValueError(
"requires a bytes() object of length {}, but"
" {} was given".format(self._length, len(value))
"'{}' requires a bytes() object of length {}, but "
"{} was given".format(
self._name, self._length, len(value)
)
)
else:
raise ValueError(
"requires a bytes() object, not {}".format(type(value))
"'{}' requires a bytes() object, not {}"
"".format(self._name, type(value))
)
elif self._iotype == IOType.INP:
raise AttributeError("can not write to input")
elif self._iotype == IOType.MEM:
raise AttributeError("can not write to memory")
elif self._iotype == Type.INP:
raise AttributeError(
"can not write to input '{}'".format(self._name)
)
elif self._iotype == Type.MEM:
raise AttributeError(
"can not write to memory '{}'".format(self._name)
)
def unreg_event(self, func=None, edge=None):
"""Entfernt ein Event aus der Eventueberwachung.
@@ -579,6 +600,7 @@ class IOBase(object):
byteorder = property(_get_byteorder)
length = property(_get_length)
name = property(_get_name)
type = property(_get_iotype)
value = property(get_value, set_value)
@@ -638,7 +660,8 @@ class IntIO(IOBase):
))
else:
raise ValueError(
"need an int() value, but {} was given".format(type(value))
"'{}' need an int() value, but {} was given"
"".format(self._name, type(value))
)
byteorder = property(IOBase._get_byteorder, _set_byteorder)

View File

@@ -152,7 +152,7 @@ class RevPiModIO(object):
# Für RS485 errors defaults laden und schreiben
# NOTE: Soll das wirklich gemacht werden?
for io in dev_new.get_outs():
for io in dev_new.get_outputs():
io.set_value(io.defaultvalue)
if not self._monitoring:
self.writeprocimg(True, dev_new)
@@ -676,7 +676,7 @@ class RevPiModIO(object):
for dev in mylist:
if (force or dev.autoupdate):
for io in dev.get_outs():
for io in dev.get_outputs():
io.set_value(io.defaultvalue)
def syncoutputs(self, force=False, device=None):
@@ -747,7 +747,7 @@ class RevPiModIO(object):
workokay = True
dev._filelock.acquire()
for io in dev.get_inps():
for io in dev.get_inputs():
dev._ba_devdata[io.slc_address] = io.defaultvalue
# Outpus auf Bus schreiben