Object .io

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

You also can acces the IO object via String:.io["I_1"].value

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.

.export
Returns the export flag value of the io, set on piCtory.

.frm
Returns the struct formatting as <class ‘str’>. Only available on replaced IOs (see .replace_io(...)).

.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.

Classfunctions

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 behavior 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.

NOTE: Only available on IOs of a gateway- or virtual Device!

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.

Raw Byte-IOs:

If you want to get the pure byte value of contiguous IOs (often on gateways), you use “s”. Before the “s” must be a number that indicates how many bytes should be used for the new IO. If you pass “16s” to frm, it replaces the IO itself, plus 15 subsequent IOs (if each IO is one byte long).

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.

.reset()

Reset the counter of the Input to 0.Note: Only available at counter inputs of the DI and DIO modules!

.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.