Class AInput7Relay2Module
Class Examples
from emod_controller_python_binding import ainput7relay2_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:
value = (data[0] << 8) + data[1]
print("idFunction=" + str(idFunction) + " temperature=" + str(value))
else:
print("idFunction=" + str(idFunction) + " dataLen=" + str(datalen))
# Context variable initialization
context = ctypes.c_void_p()
# Create an object AInput7Relay2Module
f = ainput7relay2_module.AInput7Relay2Module()
# Init module
if (
f.init_with_callback(
ainput7relay2_module.AInput7Relay2ModuleCallback_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...")
from emod_controller_python_binding import ainput7relay2_module
import time
################################# TEST BINDINGS #######################################
# Create an object AInput7Relay2Module
f = ainput7relay2_module.AInput7Relay2Module()
# Init module
if f.init() == 0:
print("Init done properly")
# 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")
# Get relay status
status = f.get_relay_status(ainput7relay2_module.AI7R2MODULE_RELAY1)
print("Status Relay1:" + str(status))
status = f.get_relay_status(ainput7relay2_module.AI7R2MODULE_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("Activation succeeded")
else:
print("Activation NOT succeeded")
# Get relay status
status = f.get_relay_status(ainput7relay2_module.AI7R2MODULE_RELAY1)
print("Status Relay1:" + str(status))
status = f.get_relay_status(ainput7relay2_module.AI7R2MODULE_RELAY2)
print("Status Relay2:" + str(status))
status = f.get_all_relay_status()
print("Status Relays:" + str(status))
# Get one and all analog inputs
data = f.get_analog_input(ainput7relay2_module.AI7R2MODULE_INPUT01)
print("Data AI01:" + str(data))
data = f.get_all_analog_inputs()
for d in data:
print("data[]:" + str(d))
# Get analog input config
config = f.get_analog_input_config()
print("config:" + str(config))
time.sleep(2)
else:
print("Some error occured during module initialization...")
Public Functions
- class emod_controller_python_binding.ainput7relay2_module.AInput7Relay2Module[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_analog_input(input_mask)[source]
Configure an input or set of inputs to select them for acquiring current (4 to 20 mA) or voltage (0 to 10 V).
- Parameters
input_mask – input or list of analog inputs, as enumerated above in the constants section,
acquiring (to configure them for acquiring current. The rest of inputs will be configured for) – voltage.
- 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_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).
- config_event_out_of_range(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).
- config_event_within_range(low_limit, high_limit, event_mask)[source]
Configures module for calling init callback_func when input value 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.
- 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).
- config_sample_rate(ms_period)[source]
Configure sample rate at which you want to check the analog input data.
- Parameters
ms_period – time in milliseconds, which represents the sampling time, where the ADC will
ms. (sample the seven channels. Minimum value is 1) –
- 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_analog_inputs()[source]
Gets last measured values for all analog inputs.
- Returns
It returns last measured input number data for each analog input. If an analog input data has not been measured yet, NO_NEW_DATA_READ is returned in that input. Parameter is initialized
inside the class. When input was configured as current, value is shown in mA; otherwise it’s
represented in V. When an input is configured in current mode and **sampled_data is 0, it means that the current loop is broken.
- 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_analog_input(input_num)[source]
Gets last measured value of a specified analog input..
- Parameters
input_num – analog input number to get the data, as enumerated above in the constants section.
- Returns
It returns last measured input data. If data has not been received yet, NO_NEW_DATA_READ is returned. Parameter is initialized inside the class. When input was configured as current, value is shown in mA; otherwise it’s represented in V. When an input is configured in current mode and **sampled_data is 0, it means that the current loop is broken.
- get_analog_input_config()[source]
Gets configured inputs mask. Each input indicates if it is configured to acquire voltage (0) or current (1).
- Returns
It returns the current input mask configuration (V/A) for each input as a mask.
- 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).