IO Classes and Types
Classes for managing Revolution Pi inputs and outputs.
IOList
- class revpimodio2.io.IOList(modio)[source]
Bases:
objectBase class for direct access to IO objects.
Container for accessing all IO objects.
The IOList provides multiple ways to access IOs:
Direct attribute access:
rpi.io.button.valueString-based access:
rpi.io["button"].valueIteration:
for io in rpi.io: ...
Example:
# Direct access value = rpi.io.I_1.value rpi.io.O_1.value = True # String-based access value = rpi.io["I_1"].value # Check if IO exists if "sensor" in rpi.io: print(rpi.io.sensor.value) # Iterate all IOs for io in rpi.io: print(f"{io.name}: {io.value}")
- __contains__(key)[source]
Checks if IO exists.
- Parameters:
key – IO name <class ‘str’> or byte number <class ‘int’>
- Returns:
True if IO exists / byte is occupied
- __enter__()[source]
Read inputs on entering context manager and write outputs on leaving.
All entries are read when entering the context manager. Within the context manager, further .readprocimg() or .writeprocimg() calls can be made and the process image can be read or written. When exiting, all outputs are always written into the process image.
When ‘autorefresh=True’ is used, all read or write actions in the background are performed automatically.
- __exit__(exc_type, exc_val, exc_tb)[source]
Write outputs to process image before leaving the context manager.
- __getattr__(key)[source]
Manages deleted IOs (attributes that do not exist).
- Parameters:
key – Name or byte of an old IO
- Returns:
Old IO if in ref lists
- __getitem__(key)[source]
Retrieves specified IO.
If the key is <class ‘str’>, a single IO is returned. If the key is passed as <class ‘int’>, a <class ‘list’> is returned with 0, 1 or 8 entries. If a <class ‘slice’> is given as key, the lists are returned in a list.
- Parameters:
key – IO name as <class ‘str’> or byte as <class ‘int’>.
- Returns:
IO object or list of IOs
IOBase
- class revpimodio2.io.IOBase(parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool)[source]
Bases:
objectBase class for all IO objects.
The basic functionality enables reading and writing of values as <class bytes’> or <class ‘bool’>. This is decided during instantiation. If a bit address is specified, <class ‘bool’> values are expected and returned, otherwise <class bytes’>.
This class serves as a basis for other IO classes with which the values can also be used as <class ‘int’>.
Base class for all IO objects.
Properties:
IO name from piCtory configuration
Current IO value (read/write)
Byte address in process image
Byte length (0 for single bits)
IO type: 300=INPUT, 301=OUTPUT, 302=MEMORY
Whether value is signed
“little” or “big” endian
Configured default value from piCtory
Comment/description from piCtory
Export flag status
- __init__(parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool)[source]
Instantiation of the IOBase class.
- Parameters:
parentdevice – Parent device on which the IO is located
valuelist – Data list for instantiation [“name”,”defval”,”bitlen”,”startaddrdev”,exp,”idx”,”bmk”,”bitaddr”]
iotype – <class ‘int’> value
byteorder – Byteorder ‘little’/’big’ for <class ‘int’> calculation
signed – Perform int calculation with sign
- bmk
- __bool__()[source]
<class ‘bool’> value of the class.
- Returns:
<class ‘bool’> Only False if False or 0, otherwise True
- __call__(value=None)[source]
Get or set the IO value using function call syntax.
- Parameters:
value – If None, returns current value; otherwise sets the value
- Returns:
Current IO value when called without arguments
- get_defaultvalue()[source]
Returns the default value from piCtory.
- Returns:
Default value as <class ‘byte’> or <class ‘bool’>
- get_value()[source]
Returns the value of the IO.
- Returns:
IO value as <class ‘bytes’> or <class ‘bool’>
- reg_event(func, delay=0, edge=33, as_thread=False, prefire=False)[source]
Registers an event for the IO in the event monitoring.
The passed function is executed when the IO value changes. With specification of optional parameters, the trigger behavior can be controlled.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering if value stays the same
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- reg_timerevent(func, delay, edge=33, as_thread=False, prefire=False)[source]
Registers a timer for the IO which executes func after delay.
The timer is started when the IO value changes and executes the passed function - even if the IO value has changed in the meantime. If the timer has not expired and the condition is met again, the timer is NOT reset to the delay value or started a second time. For this behavior, .reg_event(…, delay=value) can be used.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering - also on value change
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- set_value(value) None[source]
Sets the value of the IO.
- Parameters:
value – IO value as <class bytes’> or <class ‘bool’>
- unreg_event(func=None, edge=None) None[source]
Removes an event from event monitoring.
- Parameters:
func – Only events with specified function
edge – Only events with specified function and specified edge
- wait(edge=33, exitevent=None, okvalue=None, timeout=0) int[source]
Waits for value change of an IO.
The value change is always checked when new data has been read for devices with autorefresh enabled.
On value change, waiting ends with 0 as return value.
NOTE: If <class ‘ProcimgWriter’> does not deliver new data, it will wait forever (not when “timeout” is specified).
If edge is specified with RISING or FALLING, this edge must be triggered. If the value is 1 when entering with edge RISING, the wait will only end when changing from 0 to 1.
A <class ‘threading.Event’> object can be passed as exitevent, which ends the waiting immediately with 1 as return value when is_set().
If the value okvalue is present at the IO for waiting, the waiting ends immediately with -1 as return value.
The timeout value aborts the waiting immediately when reached with value 2 as return value. (The timeout is calculated via the cycle time of the autorefresh function, so it does not correspond exactly to the specified milliseconds! It is always rounded up!)
- Parameters:
edge – Edge RISING, FALLING, BOTH that must occur
exitevent – <class ‘threading.Event’> for early termination
okvalue – IO value at which waiting ends immediately
timeout – Time in ms after which to abort
- Returns:
<class ‘int’> successful values <= 0
- Successfully waited
Value 0: IO has changed value
Value -1: okvalue matched IO
- Erroneously waited
Value 1: exitevent was set
Value 2: timeout expired
Value 100: Devicelist.exit() was called
- property address: int
Returns the absolute byte address in the process image.
- Returns:
Absolute byte address
- property defaultvalue
Returns the default value from piCtory.
- Returns:
Default value as <class ‘byte’> or <class ‘bool’>
- property length
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- property name
<class ‘str’> value of the class.
- Returns:
Name of the IO
- property value
Returns the value of the IO.
- Returns:
IO value as <class ‘bytes’> or <class ‘bool’>
Event Registration Methods
Value Manipulation Methods
IntIO
- class revpimodio2.io.IntIO(parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool)[source]
Bases:
IOBaseClass for accessing data with conversion to int.
This class extends the functionality of <class ‘IOBase’> with functions for working with <class ‘int’> values. For the conversion, ‘byteorder’ (default ‘little’) and ‘signed’ (default False) can be set as parameters.
- Ref:
IO objects with integer value access.
Example:
# Get integer value temp = rpi.io.temperature.get_intvalue() # Set integer value rpi.io.setpoint.set_intvalue(1500)
- __int__()[source]
Returns IO value considering byteorder/signed.
- Returns:
IO value as <class ‘int’>
- __call__(value=None)[source]
Get or set the integer IO value using function call syntax.
- Parameters:
value – If None, returns current integer value; otherwise sets the integer value
- Returns:
Current IO value as integer when called without arguments
- Raises:
TypeError – If value is not an integer
- get_intdefaultvalue() int[source]
Returns the default value as <class ‘int’>.
- Returns:
<class ‘int’> Default value
- get_intvalue() int[source]
Returns IO value considering byteorder/signed.
- Returns:
IO value as <class ‘int’>
- set_intvalue(value: int) None[source]
Sets IO considering byteorder/signed.
- Parameters:
value – <class ‘int’> Value
- property defaultvalue: int
Returns the default value as <class ‘int’>.
- Returns:
<class ‘int’> Default value
- property signed: bool
Retrieves whether the value should be treated as signed.
- Returns:
True if signed
- property value: int
Returns IO value considering byteorder/signed.
- Returns:
IO value as <class ‘int’>
- __bool__()
<class ‘bool’> value of the class.
- Returns:
<class ‘bool’> Only False if False or 0, otherwise True
- __init__(parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool)
Instantiation of the IOBase class.
- Parameters:
parentdevice – Parent device on which the IO is located
valuelist – Data list for instantiation [“name”,”defval”,”bitlen”,”startaddrdev”,exp,”idx”,”bmk”,”bitaddr”]
iotype – <class ‘int’> value
byteorder – Byteorder ‘little’/’big’ for <class ‘int’> calculation
signed – Perform int calculation with sign
- __len__()
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- __str__()
<class ‘str’> value of the class.
- Returns:
Name of the IO
- property address: int
Returns the absolute byte address in the process image.
- Returns:
Absolute byte address
- bmk
- get_defaultvalue()
Returns the default value from piCtory.
- Returns:
Default value as <class ‘byte’> or <class ‘bool’>
- get_value()
Returns the value of the IO.
- Returns:
IO value as <class ‘bytes’> or <class ‘bool’>
- property length
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- property name
<class ‘str’> value of the class.
- Returns:
Name of the IO
- reg_event(func, delay=0, edge=33, as_thread=False, prefire=False)
Registers an event for the IO in the event monitoring.
The passed function is executed when the IO value changes. With specification of optional parameters, the trigger behavior can be controlled.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering if value stays the same
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- reg_timerevent(func, delay, edge=33, as_thread=False, prefire=False)
Registers a timer for the IO which executes func after delay.
The timer is started when the IO value changes and executes the passed function - even if the IO value has changed in the meantime. If the timer has not expired and the condition is met again, the timer is NOT reset to the delay value or started a second time. For this behavior, .reg_event(…, delay=value) can be used.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering - also on value change
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- set_value(value) None
Sets the value of the IO.
- Parameters:
value – IO value as <class bytes’> or <class ‘bool’>
- unreg_event(func=None, edge=None) None
Removes an event from event monitoring.
- Parameters:
func – Only events with specified function
edge – Only events with specified function and specified edge
- wait(edge=33, exitevent=None, okvalue=None, timeout=0) int
Waits for value change of an IO.
The value change is always checked when new data has been read for devices with autorefresh enabled.
On value change, waiting ends with 0 as return value.
NOTE: If <class ‘ProcimgWriter’> does not deliver new data, it will wait forever (not when “timeout” is specified).
If edge is specified with RISING or FALLING, this edge must be triggered. If the value is 1 when entering with edge RISING, the wait will only end when changing from 0 to 1.
A <class ‘threading.Event’> object can be passed as exitevent, which ends the waiting immediately with 1 as return value when is_set().
If the value okvalue is present at the IO for waiting, the waiting ends immediately with -1 as return value.
The timeout value aborts the waiting immediately when reached with value 2 as return value. (The timeout is calculated via the cycle time of the autorefresh function, so it does not correspond exactly to the specified milliseconds! It is always rounded up!)
- Parameters:
edge – Edge RISING, FALLING, BOTH that must occur
exitevent – <class ‘threading.Event’> for early termination
okvalue – IO value at which waiting ends immediately
timeout – Time in ms after which to abort
- Returns:
<class ‘int’> successful values <= 0
- Successfully waited
Value 0: IO has changed value
Value -1: okvalue matched IO
- Erroneously waited
Value 1: exitevent was set
Value 2: timeout expired
Value 100: Devicelist.exit() was called
Integer Value Methods
IntIOCounter
- class revpimodio2.io.IntIOCounter(counter_id, parentdevice, valuelist, iotype, byteorder, signed)[source]
Bases:
IntIOExtends the IntIO class with the .reset() function for counters.
Counter input objects with reset capability.
Example:
# Read counter count = rpi.io.counter.value # Reset counter rpi.io.counter.reset()
- __init__(counter_id, parentdevice, valuelist, iotype, byteorder, signed)[source]
Instantiation of the IntIOCounter class.
- Parameters:
counter_id – ID for the counter to which the IO belongs (0-15)
- Ref:
IOBase.__init__(...)()
- __bool__()
<class ‘bool’> value of the class.
- Returns:
<class ‘bool’> Only False if False or 0, otherwise True
- __call__(value=None)
Get or set the integer IO value using function call syntax.
- Parameters:
value – If None, returns current integer value; otherwise sets the integer value
- Returns:
Current IO value as integer when called without arguments
- Raises:
TypeError – If value is not an integer
- __int__()
Returns IO value considering byteorder/signed.
- Returns:
IO value as <class ‘int’>
- __len__()
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- __str__()
<class ‘str’> value of the class.
- Returns:
Name of the IO
- property address: int
Returns the absolute byte address in the process image.
- Returns:
Absolute byte address
- bmk
- property defaultvalue: int
Returns the default value as <class ‘int’>.
- Returns:
<class ‘int’> Default value
- get_defaultvalue()
Returns the default value from piCtory.
- Returns:
Default value as <class ‘byte’> or <class ‘bool’>
- get_intdefaultvalue() int
Returns the default value as <class ‘int’>.
- Returns:
<class ‘int’> Default value
- get_intvalue() int
Returns IO value considering byteorder/signed.
- Returns:
IO value as <class ‘int’>
- get_value()
Returns the value of the IO.
- Returns:
IO value as <class ‘bytes’> or <class ‘bool’>
- property length
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- property name
<class ‘str’> value of the class.
- Returns:
Name of the IO
- reg_event(func, delay=0, edge=33, as_thread=False, prefire=False)
Registers an event for the IO in the event monitoring.
The passed function is executed when the IO value changes. With specification of optional parameters, the trigger behavior can be controlled.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering if value stays the same
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- reg_timerevent(func, delay, edge=33, as_thread=False, prefire=False)
Registers a timer for the IO which executes func after delay.
The timer is started when the IO value changes and executes the passed function - even if the IO value has changed in the meantime. If the timer has not expired and the condition is met again, the timer is NOT reset to the delay value or started a second time. For this behavior, .reg_event(…, delay=value) can be used.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering - also on value change
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- set_intvalue(value: int) None
Sets IO considering byteorder/signed.
- Parameters:
value – <class ‘int’> Value
- set_value(value) None
Sets the value of the IO.
- Parameters:
value – IO value as <class bytes’> or <class ‘bool’>
- property signed: bool
Retrieves whether the value should be treated as signed.
- Returns:
True if signed
- unreg_event(func=None, edge=None) None
Removes an event from event monitoring.
- Parameters:
func – Only events with specified function
edge – Only events with specified function and specified edge
- property value: int
Returns IO value considering byteorder/signed.
- Returns:
IO value as <class ‘int’>
- wait(edge=33, exitevent=None, okvalue=None, timeout=0) int
Waits for value change of an IO.
The value change is always checked when new data has been read for devices with autorefresh enabled.
On value change, waiting ends with 0 as return value.
NOTE: If <class ‘ProcimgWriter’> does not deliver new data, it will wait forever (not when “timeout” is specified).
If edge is specified with RISING or FALLING, this edge must be triggered. If the value is 1 when entering with edge RISING, the wait will only end when changing from 0 to 1.
A <class ‘threading.Event’> object can be passed as exitevent, which ends the waiting immediately with 1 as return value when is_set().
If the value okvalue is present at the IO for waiting, the waiting ends immediately with -1 as return value.
The timeout value aborts the waiting immediately when reached with value 2 as return value. (The timeout is calculated via the cycle time of the autorefresh function, so it does not correspond exactly to the specified milliseconds! It is always rounded up!)
- Parameters:
edge – Edge RISING, FALLING, BOTH that must occur
exitevent – <class ‘threading.Event’> for early termination
okvalue – IO value at which waiting ends immediately
timeout – Time in ms after which to abort
- Returns:
<class ‘int’> successful values <= 0
- Successfully waited
Value 0: IO has changed value
Value -1: okvalue matched IO
- Erroneously waited
Value 1: exitevent was set
Value 2: timeout expired
Value 100: Devicelist.exit() was called
StructIO
- class revpimodio2.io.StructIO(parentio, name: str, frm: str, **kwargs)[source]
Bases:
IOBaseClass for accessing data via a defined struct.
It provides the values in the desired formatting via struct. The struct format value is defined during instantiation.
Structured IO with format strings for complex data types.
Example:
# Get structured value value = rpi.io.sensor_data.get_structvalue()
- __init__(parentio, name: str, frm: str, **kwargs)[source]
Creates an IO with struct formatting.
- Parameters:
parentio – ParentIO object that will be replaced
name – Name of the new IO
frm – struct formatting (1 character) or ‘NUMBERs’ e.g. ‘8s’
kwargs – Additional parameters: - bmk: Description for IO - bit: Registers IO as <class ‘bool’> at specified bit in byte - byteorder: Byteorder for IO, default from replaced IO - wordorder: Wordorder is applied before byteorder - defaultvalue: Default value for IO, default from replaced IO
- __call__(value=None)[source]
Get or set the structured IO value using function call syntax.
Handles byte and word order conversion based on configuration.
- Parameters:
value – If None, returns current value unpacked using struct format; otherwise packs and sets the value
- Returns:
Current IO value unpacked according to struct format when called without arguments
- __bool__()
<class ‘bool’> value of the class.
- Returns:
<class ‘bool’> Only False if False or 0, otherwise True
- __len__()
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- __str__()
<class ‘str’> value of the class.
- Returns:
Name of the IO
- property address: int
Returns the absolute byte address in the process image.
- Returns:
Absolute byte address
- bmk
- get_defaultvalue()
Returns the default value from piCtory.
- Returns:
Default value as <class ‘byte’> or <class ‘bool’>
- get_value()
Returns the value of the IO.
- Returns:
IO value as <class ‘bytes’> or <class ‘bool’>
- property length
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- property name
<class ‘str’> value of the class.
- Returns:
Name of the IO
- reg_event(func, delay=0, edge=33, as_thread=False, prefire=False)
Registers an event for the IO in the event monitoring.
The passed function is executed when the IO value changes. With specification of optional parameters, the trigger behavior can be controlled.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering if value stays the same
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- reg_timerevent(func, delay, edge=33, as_thread=False, prefire=False)
Registers a timer for the IO which executes func after delay.
The timer is started when the IO value changes and executes the passed function - even if the IO value has changed in the meantime. If the timer has not expired and the condition is met again, the timer is NOT reset to the delay value or started a second time. For this behavior, .reg_event(…, delay=value) can be used.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering - also on value change
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- set_value(value) None
Sets the value of the IO.
- Parameters:
value – IO value as <class bytes’> or <class ‘bool’>
- unreg_event(func=None, edge=None) None
Removes an event from event monitoring.
- Parameters:
func – Only events with specified function
edge – Only events with specified function and specified edge
- wait(edge=33, exitevent=None, okvalue=None, timeout=0) int
Waits for value change of an IO.
The value change is always checked when new data has been read for devices with autorefresh enabled.
On value change, waiting ends with 0 as return value.
NOTE: If <class ‘ProcimgWriter’> does not deliver new data, it will wait forever (not when “timeout” is specified).
If edge is specified with RISING or FALLING, this edge must be triggered. If the value is 1 when entering with edge RISING, the wait will only end when changing from 0 to 1.
A <class ‘threading.Event’> object can be passed as exitevent, which ends the waiting immediately with 1 as return value when is_set().
If the value okvalue is present at the IO for waiting, the waiting ends immediately with -1 as return value.
The timeout value aborts the waiting immediately when reached with value 2 as return value. (The timeout is calculated via the cycle time of the autorefresh function, so it does not correspond exactly to the specified milliseconds! It is always rounded up!)
- Parameters:
edge – Edge RISING, FALLING, BOTH that must occur
exitevent – <class ‘threading.Event’> for early termination
okvalue – IO value at which waiting ends immediately
timeout – Time in ms after which to abort
- Returns:
<class ‘int’> successful values <= 0
- Successfully waited
Value 0: IO has changed value
Value -1: okvalue matched IO
- Erroneously waited
Value 1: exitevent was set
Value 2: timeout expired
Value 100: Devicelist.exit() was called
- get_structdefaultvalue()[source]
Returns the default value with struct formatting.
- Returns:
Default value of struct formatting type
- get_wordorder() str[source]
Returns the wordorder for this IO.
- Returns:
“little”, “big” or “ignored”
- get_structvalue()[source]
Returns the value with struct formatting.
- Returns:
Value of struct formatting type
- set_structvalue(value)[source]
Sets the value with struct formatting.
- Parameters:
value – Value of struct formatting type
- property defaultvalue
Returns the default value with struct formatting.
- Returns:
Default value of struct formatting type
- property signed: bool
Retrieves whether the value should be treated as signed.
- Returns:
True if signed
- property value
Returns the value with struct formatting.
- Returns:
Value of struct formatting type
Structured Value Methods
MemIO
- class revpimodio2.io.MemIO(parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool)[source]
Bases:
IOBaseCreates an IO for the memory values in piCtory.
This type is only intended for read access and can return various data types via .value. This also provides access to strings that are assigned in piCtory.
Memory IO with variant value access (string or integer).
- bmk
- __bool__()
<class ‘bool’> value of the class.
- Returns:
<class ‘bool’> Only False if False or 0, otherwise True
- __call__(value=None)
Get or set the IO value using function call syntax.
- Parameters:
value – If None, returns current value; otherwise sets the value
- Returns:
Current IO value when called without arguments
- __init__(parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool)
Instantiation of the IOBase class.
- Parameters:
parentdevice – Parent device on which the IO is located
valuelist – Data list for instantiation [“name”,”defval”,”bitlen”,”startaddrdev”,exp,”idx”,”bmk”,”bitaddr”]
iotype – <class ‘int’> value
byteorder – Byteorder ‘little’/’big’ for <class ‘int’> calculation
signed – Perform int calculation with sign
- __len__()
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- __str__()
<class ‘str’> value of the class.
- Returns:
Name of the IO
- property address: int
Returns the absolute byte address in the process image.
- Returns:
Absolute byte address
- get_defaultvalue()
Returns the default value from piCtory.
- Returns:
Default value as <class ‘byte’> or <class ‘bool’>
- get_value()
Returns the value of the IO.
- Returns:
IO value as <class ‘bytes’> or <class ‘bool’>
- property length
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- property name
<class ‘str’> value of the class.
- Returns:
Name of the IO
- reg_event(func, delay=0, edge=33, as_thread=False, prefire=False)
Registers an event for the IO in the event monitoring.
The passed function is executed when the IO value changes. With specification of optional parameters, the trigger behavior can be controlled.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering if value stays the same
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- reg_timerevent(func, delay, edge=33, as_thread=False, prefire=False)
Registers a timer for the IO which executes func after delay.
The timer is started when the IO value changes and executes the passed function - even if the IO value has changed in the meantime. If the timer has not expired and the condition is met again, the timer is NOT reset to the delay value or started a second time. For this behavior, .reg_event(…, delay=value) can be used.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering - also on value change
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- set_value(value) None
Sets the value of the IO.
- Parameters:
value – IO value as <class bytes’> or <class ‘bool’>
- unreg_event(func=None, edge=None) None
Removes an event from event monitoring.
- Parameters:
func – Only events with specified function
edge – Only events with specified function and specified edge
- wait(edge=33, exitevent=None, okvalue=None, timeout=0) int
Waits for value change of an IO.
The value change is always checked when new data has been read for devices with autorefresh enabled.
On value change, waiting ends with 0 as return value.
NOTE: If <class ‘ProcimgWriter’> does not deliver new data, it will wait forever (not when “timeout” is specified).
If edge is specified with RISING or FALLING, this edge must be triggered. If the value is 1 when entering with edge RISING, the wait will only end when changing from 0 to 1.
A <class ‘threading.Event’> object can be passed as exitevent, which ends the waiting immediately with 1 as return value when is_set().
If the value okvalue is present at the IO for waiting, the waiting ends immediately with -1 as return value.
The timeout value aborts the waiting immediately when reached with value 2 as return value. (The timeout is calculated via the cycle time of the autorefresh function, so it does not correspond exactly to the specified milliseconds! It is always rounded up!)
- Parameters:
edge – Edge RISING, FALLING, BOTH that must occur
exitevent – <class ‘threading.Event’> for early termination
okvalue – IO value at which waiting ends immediately
timeout – Time in ms after which to abort
- Returns:
<class ‘int’> successful values <= 0
- Successfully waited
Value 0: IO has changed value
Value -1: okvalue matched IO
- Erroneously waited
Value 1: exitevent was set
Value 2: timeout expired
Value 100: Devicelist.exit() was called
- get_variantvalue()[source]
Get the default value as either string or integer based on bit length.
For values > 64 bits, returns as decoded string. Otherwise returns as integer.
- Returns:
Default value as string (if > 64 bits) or integer
- property defaultvalue
Get the default value as either string or integer based on bit length.
For values > 64 bits, returns as decoded string. Otherwise returns as integer.
- Returns:
Default value as string (if > 64 bits) or integer
- property value
Get the default value as either string or integer based on bit length.
For values > 64 bits, returns as decoded string. Otherwise returns as integer.
- Returns:
Default value as string (if > 64 bits) or integer
RelaisOutput
- class revpimodio2.io.RelaisOutput(parentdevice, valuelist, iotype, byteorder, signed)[source]
Bases:
IOBaseClass for relais outputs to access the cycle counters.
This class extends the function of <class ‘IOBase’> to the function ‘get_cycles’ and the property ‘cycles’ to retrieve the relay cycle counters.
- Ref:
Relay output with switching cycle counter.
Example:
# Get number of switching cycles cycles = rpi.io.relay.get_switching_cycles()
- __init__(parentdevice, valuelist, iotype, byteorder, signed)[source]
Extend <class ‘IOBase’> with functions to access cycle counters.
- Ref:
IOBase.__init__(...)()
- get_switching_cycles()[source]
Get the number of switching cycles from this relay.
If each relay output is represented as BOOL, this function returns a single integer value. If all relays are displayed as a BYTE, this function returns a tuple that contains the values of all relay outputs. The setting is determined by PiCtory and the selected output variant by the RO device.
This function is only available locally on a Revolution Pi. This function cannot be used via RevPiNetIO.
- Returns:
Integer of switching cycles as single value or tuple of all
- property switching_cycles
Get the number of switching cycles from this relay.
If each relay output is represented as BOOL, this function returns a single integer value. If all relays are displayed as a BYTE, this function returns a tuple that contains the values of all relay outputs. The setting is determined by PiCtory and the selected output variant by the RO device.
This function is only available locally on a Revolution Pi. This function cannot be used via RevPiNetIO.
- Returns:
Integer of switching cycles as single value or tuple of all
- bmk
- __bool__()
<class ‘bool’> value of the class.
- Returns:
<class ‘bool’> Only False if False or 0, otherwise True
- __call__(value=None)
Get or set the IO value using function call syntax.
- Parameters:
value – If None, returns current value; otherwise sets the value
- Returns:
Current IO value when called without arguments
- __len__()
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- __str__()
<class ‘str’> value of the class.
- Returns:
Name of the IO
- property address: int
Returns the absolute byte address in the process image.
- Returns:
Absolute byte address
- property defaultvalue
Returns the default value from piCtory.
- Returns:
Default value as <class ‘byte’> or <class ‘bool’>
- get_defaultvalue()
Returns the default value from piCtory.
- Returns:
Default value as <class ‘byte’> or <class ‘bool’>
- get_value()
Returns the value of the IO.
- Returns:
IO value as <class ‘bytes’> or <class ‘bool’>
- property length
Returns the byte length of the IO.
- Returns:
Byte length of the IO - 0 for BITs
- property name
<class ‘str’> value of the class.
- Returns:
Name of the IO
- reg_event(func, delay=0, edge=33, as_thread=False, prefire=False)
Registers an event for the IO in the event monitoring.
The passed function is executed when the IO value changes. With specification of optional parameters, the trigger behavior can be controlled.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering if value stays the same
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- reg_timerevent(func, delay, edge=33, as_thread=False, prefire=False)
Registers a timer for the IO which executes func after delay.
The timer is started when the IO value changes and executes the passed function - even if the IO value has changed in the meantime. If the timer has not expired and the condition is met again, the timer is NOT reset to the delay value or started a second time. For this behavior, .reg_event(…, delay=value) can be used.
NOTE: The delay time must fit into .cycletime, if not, it will ALWAYS be rounded up!
- Parameters:
func – Function to be called on change
delay – Delay in ms for triggering - also on value change
edge – Execute on RISING, FALLING or BOTH value change
as_thread – If True, execute function as EventCallback thread
prefire – Trigger with current value when mainloop starts
- set_value(value) None
Sets the value of the IO.
- Parameters:
value – IO value as <class bytes’> or <class ‘bool’>
- unreg_event(func=None, edge=None) None
Removes an event from event monitoring.
- Parameters:
func – Only events with specified function
edge – Only events with specified function and specified edge
- property value
Returns the value of the IO.
- Returns:
IO value as <class ‘bytes’> or <class ‘bool’>
- wait(edge=33, exitevent=None, okvalue=None, timeout=0) int
Waits for value change of an IO.
The value change is always checked when new data has been read for devices with autorefresh enabled.
On value change, waiting ends with 0 as return value.
NOTE: If <class ‘ProcimgWriter’> does not deliver new data, it will wait forever (not when “timeout” is specified).
If edge is specified with RISING or FALLING, this edge must be triggered. If the value is 1 when entering with edge RISING, the wait will only end when changing from 0 to 1.
A <class ‘threading.Event’> object can be passed as exitevent, which ends the waiting immediately with 1 as return value when is_set().
If the value okvalue is present at the IO for waiting, the waiting ends immediately with -1 as return value.
The timeout value aborts the waiting immediately when reached with value 2 as return value. (The timeout is calculated via the cycle time of the autorefresh function, so it does not correspond exactly to the specified milliseconds! It is always rounded up!)
- Parameters:
edge – Edge RISING, FALLING, BOTH that must occur
exitevent – <class ‘threading.Event’> for early termination
okvalue – IO value at which waiting ends immediately
timeout – Time in ms after which to abort
- Returns:
<class ‘int’> successful values <= 0
- Successfully waited
Value 0: IO has changed value
Value -1: okvalue matched IO
- Erroneously waited
Value 1: exitevent was set
Value 2: timeout expired
Value 100: Devicelist.exit() was called