Class DInput10Module

Class Examples

DInput10Module class callback example
from emod_controller_python_binding import dinput10_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 = dinput10_module.DInput10Module()

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

    # Reset event config
    f.reset_event_config()
    # Config module with a time interval event
    if f.config_event_on_new_data() == 0:
        print("Event properly configured")

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

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

# Create an object DInput10Module
f = dinput10_module.DInput10Module()

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

    while 1:

        # Get pulse width for one and all inputs
        width = f.get_pulse_width(dinput10_module.DI10MODULE_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(dinput10_module.DI10MODULE_INPUT01)
        print("Count DI01:" + 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(dinput10_module.DI10MODULE_INPUT05)
        print("DI05:" + 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))

        # Reset all pulse counters
        f.reset_all_pulse_count()
        counts = f.get_all_pulse_count()
        for c in counts:
            print("Counts[]:" + str(c))

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

Public Functions

class emod_controller_python_binding.dinput10_module.DInput10Module[source]

Bases: object

config_event_at_time_interval(time_interval)[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(threshold, event_mask)[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).

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

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_config()[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).