Class DInput5Relay2Module

Class Examples

DInput5Relay2Module class callback example
from emod_controller_python_binding import dinput5relay2_module
import ctypes
import time

################################# TEST BINDINGS #######################################
# Callback function definition
def my_callback(data, datalen, idFunction, ctx):
    print("Hi, I'm in callback")
    if datalen == 2:
        short_val = (data[0] << 8) + data[1]
        print("idFunction=" + str(idFunction) + " short_val=" + str(short_val))
    elif datalen == 4:
        long_val = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]
        print("idFunction=" + str(idFunction) + " long_val=" + str(long_val))
    else:
        print("idFunction=" + str(idFunction) + " dataLen=" + str(datalen))


# Context variable initialization
context = ctypes.c_void_p()

# Create an object DInput10Module
f = dinput5relay2_module.DInput5Relay2Module()

# Init module
if (
    f.init_with_callback(
        dinput5relay2_module.DInput5Relay2ModuleCallback_Type(my_callback)
    )
    == 0
):
    print("Initialization done properly")

    # Config module with a time interval event
    if f.config_event_at_time_interval(1000) == 0:
        print("Event at time interval properly configured")

    # Infinite loop
    while 1:
        time.sleep(2)
else:
    print("Some error occured during module initialization...")
DInput5Relay2Module class example
from emod_controller_python_binding import dinput5relay2_module
import time


################################# TEST BINDINGS #######################################

# Create DInput5Relay2Module object
f = dinput5relay2_module.DInput5Relay2Module()

# Init module
if f.init() == 0:
    print("Initialization done properly")

    # Reset all pulse counters
    f.reset_all_pulse_count()
    # Config pulse width
    if f.config_all_pulse_width(0) == 0:
        print("Pulse width properly configured")
    else:
        print("Pulse width NOT properly configured")

    while 1:
        # Activate all relays
        if f.activate_all_relays() == 0:
            print("Activation succeeded")
        else:
            print("Activation NOT succeeded")

        # Check relays status
        status = f.get_relay_status(dinput5relay2_module.DI5PR2MODULE_RELAY2)
        print("Status Relay2:" + str(status))
        status = f.get_all_relay_status()
        print("Status Relays:" + str(status))

        time.sleep(2)

        # Deactivate all relays
        if f.deactivate_all_relays() == 0:
            print("Deactivation succeeded")
        else:
            print("Deactivation NOT succeeded")

        # Check relays status
        status = f.get_relay_status(dinput5relay2_module.DI5PR2MODULE_RELAY1)
        print("Status Relay1:" + str(status))
        status = f.get_all_relay_status()
        print("Status Relays:" + str(status))

        time.sleep(2)

        # Activate relay 1
        f.activate_relay(dinput5relay2_module.DI5PR2MODULE_RELAY1)
        status = f.get_relay_status(dinput5relay2_module.DI5PR2MODULE_RELAY1)
        print("Status Relay1:" + str(status))
        status = f.get_all_relay_status()
        print("Status Relays:" + str(status))

        time.sleep(2)

        # Get pulse width for one and all inputs
        width = f.get_pulse_width(dinput5relay2_module.DI5PR2MODULE_INPUT02)
        print("Pulse width DI02:" + str(width))
        widths = f.get_all_pulse_width()
        for w in widths:
            print("w[0]:" + str(w))

        # Get count pulse for one and all inputs
        count = f.get_pulse_count(dinput5relay2_module.DI5PR2MODULE_INPUT01)
        print("Count DI01:" + str(count))
        count = f.get_pulse_count(dinput5relay2_module.DI5PR2MODULE_INPUT02)
        print("Count DI02:" + str(count))
        counts = f.get_all_pulse_count()
        for c in counts:
            print("Counts[]:" + str(c))

        # Get the input value for one and all inputs
        di, new_data = f.get_digital_input_status(
            dinput5relay2_module.DI5PR2MODULE_INPUT01
        )
        print("DI01:" + str(di))
        print("new_data:" + str(new_data))
        di, new_data = f.get_digital_input_status(
            dinput5relay2_module.DI5PR2MODULE_INPUT02
        )
        print("DI02:" + str(di))
        print("new_data:" + str(new_data))
        dis, new_data = f.get_digital_input_all_status()
        for d in dis:
            print("DI[]:" + str(d))
        print("new_data:" + str(new_data))

        time.sleep(2)
else:
    print("Some error occured during module initialization...")

Public Functions

class emod_controller_python_binding.dinput5relay2_module.DInput5Relay2Module[source]

Bases: object

activate_all_relays()[source]

Activates all module relays.

Returns

It returns if the initialization was successfull (0) or not (!=0).

activate_relay(relay_mask)[source]

Activates a relay or set of relays..

Parameters

relay_mask – relay or list of relays to activate.

Returns

It returns if the initialization was successfull (0) or not (!=0).

config_all_pulse_width(width_ms)[source]

Configure pulse width of all relays. When pulse width is 0 a relay stays in the current state, and there is no pulse.

Parameters

width_ms – pulse width in ms. Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.

Returns

It returns if the initialization was successfull (0) or not (!=0).

config_event_at_time_interval(time_interval, event_mask)[source]

Configures module for calling init callback_func at specified period.

Parameters
  • time_interval – period in milliseconds. Minimum value is 500ms.

  • event_mask – bit mask representing inputs that must trigger the event.

Returns

It returns if the initialization was successfull (0) or not (!=0).

config_event_on_new_data()[source]

Configures module for calling init callback_func when new data on input occurs.

Returns

It returns if the initialization was successfull (0) or not (!=0).

config_event_on_value_change(event_mask, threshold)[source]

Configures module for calling init callback_func when input changes its value by a specified amount.

Parameters
  • threshold – amount of samples that triggers the event.

  • event_mask – bit mask representing inputs that must trigger the event.

Returns

It returns if the initialization was successfull (0) or not (!=0).

config_pulse_width(relay_mask, width_ms)[source]

Configure pulse width of a relay or list of relays. When pulse width is 0 a relay stays in the current state, and there is no pulse.

Parameters
  • relay_mask – relay or list of relays to configure.

  • width_ms – pulse width in ms. Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.

Returns

It returns if the initialization was successfull (0) or not (!=0).

deactivate_all_relays()[source]

Deactivates all module relays.

Returns

It returns if the initialization was successfull (0) or not (!=0).

deactivate_relay(relay_mask)[source]

Deactivates a relay or set of relays..

Parameters

relay_mask – relay or list of relays to deactivate.

Returns

It returns if the initialization was successfull (0) or not (!=0).

get_all_pulse_count()[source]

Gets number of pulses occurred in all inputs.

Returns

It returns the number of pulses for each digital input.

get_all_pulse_filter_time()[source]

Gets current pulse filter time for all inputs.

Returns

It returns pulse width (in ms) for each input.

get_all_pulse_width()[source]

Gets last pulse width occurred in all inputs..

Returns

It returns an an array of counts representing the last pulse width occurred in each input.

get_all_relay_status()[source]

Gets all relay status..

Returns

Every bit represents a relay order status. Status is 1 when is activate and 0 when deactivate.

get_digital_input_all_status()[source]

Gets all digital input status.

Returns

returns last received input number status (0:deactivated, 1: activated) for each digital input. new_data: returns if new data has arrived since the last function call. If a digital input status has not been received yet, NO_NEW_DATA_READ is returned in that input. Parameter is initialized inside the class.

Return type

status

get_digital_input_status(input_mask)[source]

Gets a digital input status.

Parameters

input_mask – digital input number to get the status, as enumerated above in the constants section.

Returns

returns last received input number status (0:deactivated, 1: activated). new_data: returns if new data has arrived since the last function call. If status has not been received yet, NO_NEW_DATA_READ is returned. Parameter is initialized inside the class.

Return type

status

get_pulse_count(input_mask)[source]

Gets number of pulses occurred in an input after a reset.

Parameters

input_mask – digital input number to get the status, as enumerated above in the constants section.

Returns

It returns the number of pulses.

get_pulse_filter_time(input_mask)[source]

Gets current pulse filter time.

Parameters

input_mask – digital input number to get the status, as enumerated above in the constants section.

Returns

It returns pulse width (in ms).

get_pulse_width(input_mask)[source]

Gets last pulse width occurred in an input..

Parameters

input_mask – digital input number to get the status, as enumerated above in the constants section.

Returns

It returns pulse width (in ms).

get_relay_status(relay_mask)[source]

Gets a relay status.

Parameters

relay_mask – relay mask number to get the status.

Returns

Every bit represents a relay order status. Status is 1 when is activate and 0 when deactivate.

init()[source]

Initialize module. It is important to emphasize that init() method is mandatory to call it and must be called always after instantiating the module. It can be called several times, each of which the module is initialized again.

Returns

It returns if the initialization was successfull (0) or not (!=0).

init_v(callback, variant)[source]

Initialize module. It is important to emphasize that this method is mandatory to call it. It can be called several times, each of which the module is initialized again.

Parameters
  • callback – function that will be called when a configured event occurs.

  • variant – identifies the module in case more than one module of the same type are present.

Returns

It returns if the initialization was successfull (0) or not (!=0).

init_with_callback(callback)[source]

Initialize module. It is important to emphasize that this method is mandatory to call it. It can be called several times, each of which the module is initialized again.

Parameters

callback – function that will be called when a configured event occurs.

Returns

It returns if the initialization was successfull (0) or not (!=0).

reset_all_pulse_count()[source]

Resets the number of pulses in all inputs..

Returns

It returns if the initialization was successfull (0) or not (!=0).

reset_event_configuration()[source]

Resets all previously configured events.

Returns

It returns if the initialization was successfull (0) or not (!=0).

reset_pulse_count(input_mask)[source]

Resets the number of pulses in an input.

Parameters

input_mask – digital input number to get the status, as enumerated above in the constants section.

Returns

It returns if the initialization was successfull (0) or not (!=0).

set_all_pulse_filter_time(ms_time)[source]

Sets the pulse filter time for all inputs.

Parameters

ms_time – pulse width (in ms). Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.

Returns

It returns if the initialization was successfull (0) or not (!=0).

set_pulse_filter_time(input_mask, ms_time)[source]

Sets the pulse filter time. All pulses with a shorter time will be discarded.

Parameters
  • input_mask – digital input number to get the status, as enumerated above in the constants section.

  • ms_time – pulse width (in ms). Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.

Returns

It returns if the initialization was successfull (0) or not (!=0).

switch_mode_digital_input(input_number, mode)[source]

Usually, this function only needs to be called at the beginning in the configuration stage.

Parameters
  • input_mask – digital input number to be configured.

  • mode – desired mode for the input; PULSE_COUNTER or PULSE_WIDTH as enumerated above in the constants section.

Returns

It returns if the initialization was successfull (0) or not (!=0).