Object .io

This class offers direct access to the IOs of the Revolution Pi.

revpimodio2.io.IOList()
Classobjects

This class offers all IOs as attributes. The names of the attributes are taken out of the  piCtory configuration.

If an Input with the name “I_1” is configured in piCtory, then you can use python to access it’s values:
.io.I_1.value

Outputs whose values can be changed via an assignment are used in the same way. For example, for an Output named “O_1”:
.io.O_1.value = True

Note: For piCtory naming, the Python rules must be respected for name assignments. If this is not possible, access is only possible via string (.io["§ad#Name"].value) .


All Attribute objects have the following properties:

Classattributes

  • .address
    Returns the absolute byte address as <class ‘int’> in the process image.

  • .bmk
    Returns the text as <class ‘str’> from the “Comment” field of the “Value Editors” in piCtory.

  • .byteorder
    For all IOs, the byte order is returned as <class ‘str’>.
    For byte-oriented IOs, e.g. the byte order can also be set on virtual devices or gateways. This is important for converting the values to <class ‘int’>. The default is “little”.
    Possible values: “little” or “big”

  • .defaultvalue
    Returns the defaultvalue of the IO, configured in piCtory.

  • .frm
    Only Returns the struct formatting as <class ‘str’> , through .replace_io(...)replaced IOs. For other IOs, the Attribute does not exist!

  • .length
    Returns the Byte length of the IO object – 0 for bits.

  • .name
    Returns name from the IO objects – Matches names in piCtory.

  • .signed
    Returns for all IOs, if the value calculation should be executed with pre-sign.
    For byte-oriented IOs, e.g. on virtual devices or gateways, the value can also be set. This is important for the conversion of the values in <class ‘int’>. The default is False.
    Possible values: True or False
  • .type
    Returns the IO type of the object as <class ‘int’>.

    • 200=INP
    • 301=OUT
    • 302=MEM

  • .value
    Returns the value from the IO object. The type of the return value is always the right one.

    • <class ‘bool’> For BIT-oriented IOs (Digital in- and outputs) or through .replace_io(... , "?", bit=0) BIT-oriented exchanged Bytes.
    • <class ‘int’> For all other IOs that are replaced by .replace_io(...)

Classfunctions

.reg_event(func, [delay=0, edge=BOTH, as_thread=False])

Registers an event on this IO at the event monitoring. If the IO value changes, the passed function is being executed. The execution can be controlled via optional parameters.

NOTE: The delay-time needs to fit into the .cycletime always, if this is not the case, it will ALWAYS be rounded up!

  • func
    Function that should be rounded up after a change.
    The io_name and io_value is being passed, which needs to be accepted: def my_function(ioname, iovalue):
  • delay=0
    Delay in milliseconds to trigger if the value remains the same.
  • edge=revpimodio2.BOTH
    Execution of RISING, FALLING or BOTH value changes from BIT-oriented IOs.
  • as_thread=False
    If True, the function is executed as an EventCallback thread and can run parallel to the actual program.
    The function is passed an instance of EventCallback , which must be accepted: def my_function(ecb): !

.reg_timerevent(func, delay, [edge=BOTH, as_thread=False])

The timer is started when the IO value changes and executes the passed function – even if the IO value changed in the meantime. If the timer has not expired and the condition reappears, then the timer WILL NOT be reset to the  delay value and won’t start a second time. For this behaviour you can use .reg_event(..., delay=value) .

NOTE: The delay-time Needs to fit into the .cycletime , if this is not the case, it will ALWAYS be rounded up!

  • func
    Function which should be called after a change.
    The  io_name and io_value are being passed to the function, which Needs to be accepted: def my_function(ioname, iovalue):
  • delay
    Delay to execute in milliseconds.
  • edge=revpimodio2.BOTH
    Execution for RISING, FALLING or BOTH value changes from BIT-oriented IOs.
  • as_thread=False
    If True, the function is executed as an EventCallback thread and can run parallel to the actual program.
    An instance from  EventCallback is being passed to the function, which needs to be accepted: def my_function(ecb): !

.replace_io(name, frm, [**kwargs])

Registers a new IO at the place of the old IO with a specified formatting. For the Format definition, with Parameter frm, the characters of the struct()-function of Python3 is being used.

Register Bit-IOs:
If “?” (BIT) is being used as format template, then the bitadress must be specified as Parameter bit ,on which position the new IO should be located in the existing Byte or Word. It is possible to create 8 new BIT oriented IOs on an IO with a length of 1 Byte – With 2 byte length 16, etc.

Registering Number-IOs:
If a numeric value is used as the Format template, which requires more memory than the IO has got available, subsequent IOs are also replaced. If for example “Q” is used as frm, then the IO itself plus seven subsequent IOs are being replaced (if IOs are each one Byte long). By entering “q”, the value is treated with a sign and is put out accordingly.

  • name Name of the new IO, which is also added as an attribute in .io.
  • frm struct() formatting (1 character) – According to Python preferences.
  • kwargs The following optional keyword Parameters can be passed:
    • bmk internal designation for IO.
    • bit Registriers IO as <class ‘bool’> at the specified bit im byte/word.
    • byteorder Byte order for the new IO – If not specified, then the byte order of the IO that should be replaced is being taken over.
    • defaultvalue Default value for the new IO – If not specified the default value is being calculated by the exchanged IOs.
    • event Register fuction for eventhandling.
    • delay Delay in milliseconds to Trigger if value remains the same.
    • edge Event execution at  RISING, FALLING or BOTH value change.
    • as_thread Executesthe event-function as RevPiCallback-thread.

.unreg_event([func=None, edge=None])

Removes registered Events from the event handler and no longer calls its functions when changing data. If this function is called without parameters, ALL Register functions will be removed from this IO. By specifying parameters, you can remove certain functions only.

  • func
    Delete events with declared functions only
  • edge
    Delete events with declared functions and declared edge only

.wait([edge=BOTH, exitevent=None, okvalue=None, timeout=0])

Wait for the value change on the IO at the calling point in the python program.
The value change is always checked if the AutoRefresh provides new data – so if RevPiModIO is instantiated with Parameter  autorefresh=True or if the  .autorefresh()is being called on the IO where the device is located on.

If the value changes, the wait is ended with 0 as the return value.

If edge is specified with RISING or FALLING, this edge must be triggered. If the IO value should be  True with RISING edge, the wait is only terminated with True if the value is changed from False to  True.

As an exitevent, a <class ‘threading.Event’> object can be passed, which immediately terminates the wait at is_set() with 1 as return value.

If the value okvalue is present at the Input for the wait, the wait is immediately terminated with -1 as the return value.

The value of timeout will immediately terminate with 2 as the return value when the wait is reached. (The timeout is calculated via the cycle time of the autorefresh function, so it does not exactly correspond to the specified milliseconds! It will always be rounded up!)

  • edge=revpimodio2.BOTH
    Flank RISING, FALLING, BOTH which must occur.
  • exitevent=None
    <class ‘thrading.Event’> for early termination.
  • okvalue=None
    IO value, where the wait is terminated immediately.
  • timeout=0
    Time in milliseconds, after it is canceled. At 0, timeout is not considered.

RETURN VALUE: As return value you obtain a <class ‘int’> Integer value.

  • Waited successfuly: <= 0
    • 0: IO changed the value
    • -1: okvalue matched with IO value
  • Waiting failed: > 0
    • 1: exitevent was set
    • 2: timeout timed out
    • 100: RevPiModIO.exit()was called

Advanced getter and setter functions

.get_defaultvalue()

Always returns the default value from IO as <class ‘bytes’>.


.get_intdefaultvalue()

Returns the default value from IO as <class ‘int’>.
Note: Only available for IO types from the class <class ‘revpimodio.io.IntIO’> .


.get_structdefaultvalue()

Returns the default value as <class ‘int’>, taking into account the struct format specification  .
Note: Only available for IO types of the class <class ‘revpimodio.io.StructIO’> .


.get_value()

Always returns the IO value as <class ‘bytes’> .


.get_intvalue()

Returns the IO value as<class ‘int’>.
Note: Only available for IO types of the class <class ‘revpimodio.io.IntIO’> .


.get_structvalue()

Returns the default value as <class ‘int’>, taking into account the struct format specification  .
Note: Only available for IO types of the class <class ‘revpimodio.io.StructIO’> .


.set_value(value)

Sets the IO value to passed value of type <class ‘bytes’>


.set_intvalue(value)

Sets the IO value to passed value of type <class ‘int’>
Note: Only available for IO types of the class <class ‘revpimodio.io.IntIO’> .


.set_structvalue(value)

Returns the default value as <class ‘int’>, taking into account the struct format specification .
Hinweis: Only available for IO types of the class <class ‘revpimodio.io.StructIO’>.