Class DInput2Relay1Temp2Module
Class Examples
from emod_controller_python_binding import dinput2relay1temp2_module
import ctypes
import time
################################# TEST BINDINGS #######################################
# Callback function definition
def my_callback(data, datalen, idFunction, ctx):
print("Hi, I'm in callback")
if idFunction > 7:
value = (data[0] << 8) + data[1]
print("idFunction=" + str(idFunction) + " temperature=" + str(value))
elif 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 DInput2Relay1Temp2Module
f = dinput2relay1temp2_module.DInput2Relay1Temp2Module()
# Init module
if (
f.init_with_callback(
dinput2relay1temp2_module.DInput2Relay1Temp2ModuleCallback_Type(my_callback)
)
== 0
):
print("Initialization done properly")
# Config pulse width
if f.config_pulse_width(dinput2relay1temp2_module.DI2R1T2MODULE_RELAY1, 0) == 0:
print("Pulse width properly configured")
else:
print("Pulse width NOT properly configured")
# Configure temperature sensor
if (
f.configure_temp_sensor(
dinput2relay1temp2_module.TEMP_SENSOR1,
dinput2relay1temp2_module.TWO_WIRE_PT100SENSOR,
)
== 0
):
print("Temp sensor 1 properly configured")
else:
print("Temp sensor 1 NOT properly configured")
if (
f.configure_temp_sensor(
dinput2relay1temp2_module.TEMP_SENSOR2,
dinput2relay1temp2_module.TWO_WIRE_PT100SENSOR,
)
== 0
):
print("Temp sensor 2 properly configured")
else:
print("Temp sensor 2 NOT properly configured")
if (
f.switch_mode_digital_input(
dinput2relay1temp2_module.DI2R1T2MODULE_ALL_DIGITAL_INPUT,
dinput2relay1temp2_module.PULSE_COUNTER,
)
== 0
):
print("Di mode properly configured")
else:
print("Di mode NOT properly configured")
# Config module with a time interval event
if f.reset_event_configuration() == 0:
print("Reset event configuration done properly")
res = f.config_event_at_time_interval_dinput(1000)
print(res)
if res == 0:
print("Event at time interval properly configured")
else:
print("Event at time interval not properly configured")
res2 = f.config_event_at_time_interval_temp(
3000, dinput2relay1temp2_module.DI2R1T2MODULE_ALL_TEMP_INPUT
)
print(res2)
if res2 == 0:
print("Event at time interval properly configured")
else:
print("Event at time interval not properly configured")
# Infinite loop
while 1:
time.sleep(2)
else:
print("Some error occured during module initialization...")
from emod_controller_python_binding import dinput2relay1temp2_module
import time
################################# TEST BINDINGS #######################################
# Create an object DInput2Relay1Temp2Module
f = dinput2relay1temp2_module.DInput2Relay1Temp2Module()
# Init module
if f.init() == 0:
print("Init done properly")
# Config pulse width
if f.config_pulse_width(dinput2relay1temp2_module.DI2R1T2MODULE_RELAY1, 0) == 0:
print("Pulse width properly configured")
else:
print("Pulse width NOT properly configured")
# Configure temperature sensor
f.configure_temp_sensor(
dinput2relay1temp2_module.TEMP_SENSOR1,
dinput2relay1temp2_module.TWO_WIRE_PT100SENSOR,
)
while 1:
# Activate all relays
if f.activate_all_relays() == 0:
print("Activation succeeded")
else:
print("Activation NOT succeeded")
# Get relay status
status = f.get_relay_status(dinput2relay1temp2_module.DI2R1T2MODULE_RELAY1)
print("Status Relay1:" + 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("Activation succeeded")
else:
print("Activation NOT succeeded")
# Get relay status
status = f.get_relay_status(dinput2relay1temp2_module.DI2R1T2MODULE_RELAY1)
print("Status Relay1:" + str(status))
status = f.get_all_relay_status()
print("Status Relays:" + str(status))
time.sleep(2)
# Get one and all pulse widths
width = f.get_pulse_width(dinput2relay1temp2_module.DI2R1T2MODULE_INPUT02)
print("Pulse width DI02:" + str(width))
widths = f.get_all_pulse_width()
for w in widths:
print("w[0]:" + str(w))
# Get one and all pulse counters
count = f.get_pulse_count(dinput2relay1temp2_module.DI2R1T2MODULE_INPUT01)
print("Count DI01:" + str(count))
counts = f.get_all_pulse_count()
for c in counts:
print("Counts[]:" + str(c))
# Get one and all digital inputs value
di, new_data = f.get_digital_input_status(
dinput2relay1temp2_module.DI2R1T2MODULE_INPUT01
)
print("DI01:" + 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)
temp = f.get_temp_sensor(dinput2relay1temp2_module.TEMP_SENSOR1)
print("temp_sensor1:" + str(temp))
temp = f.get_temp_sensor(dinput2relay1temp2_module.TEMP_SENSOR2)
print("temp_sensor2:" + str(temp))
temps = f.get_all_temp_sensor()
for t in temps:
print("t[]:" + str(t))
else:
print("Some error occured during module initialization...")
Public Functions
- class emod_controller_python_binding.dinput2relay1temp2_module.DInput2Relay1Temp2Module[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 al 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
0. (value is)
- Returns:
It returns if the initialization was successfull (0) or not (!=0).
- config_all_temp_sensor(config)[source]
Select a common configuration on all temperature sensors.
- Parameters:
config – type of temperature sensor as enumerated above in the constants section.
- Returns:
It returns if the initialization was successfull (0) or not (!=0).
- config_event_at_time_interval_dinput(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_at_time_interval_temp(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_dinput()[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_dinput(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).
- config_event_on_value_change_temp(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).
- 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).
- configure_event_out_of_range_temp(low_limit, high_limit, event_mask)[source]
Configures module for calling init callback_func when input value gets out of the specified range.
- Parameters:
low_limit – low limit of the range in samples.
high_limit – high limit of the range in samples.
event_mask – bit mask representing inputs that must trigger the event.
- Returns:
It returns if the initialization was successfull (0) or not (!=0).
- configure_event_within_range_temp(low_limit, high_limit, event_mask)[source]
Configures module for calling init callback_func when sensor enters the specified range..
- Parameters:
low_limit – low limit of the range in samples.
high_limit – high limit of the range in samples.
event_mask – bit mask representing inputs that must trigger the event. Default value is
kTempSensorAll.
- Returns:
It returns if the initialization was successfull (0) or not (!=0).
- configure_temp_sensor(id, config)[source]
Select configuration on a temperature sensor.
- Parameters:
id – temperature sensor number to set the configuration, as enumerated above in the constants
section.
config – type of temperature sensor as enumerated above in the constants section.
- 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_all_temp_sensor()[source]
Gets temperature (in hundredths of a degree) from all sensors.
- Returns:
It returns temperature in hundredths of a celsius degree. It is kUnplugged (as enumerated in the constants above) if the sensor is unplugged..
- 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.
- get_temp_sensor(id)[source]
Gets temperature (in hundredths of a degree) from a specified sensor.
- Parameters:
id – temperature sensor number to get the status, as enumerated above in the constants section.
- Returns:
It returns temperature in hundredths of a celsius degree. It is kUnplugged (as enumerated in the constants above) if the sensor is unplugged..
- get_temp_sensor_config(id)[source]
Gets configuration from a specified temperature sensor.
- Parameters:
id – temperature sensor number to get the status, as enumerated above in the constants section.
- Returns:
It returns the type of temperature sensor as enumerated above in the constants section.
- 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_mask, 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).