Class: Tinkerforge::BrickletIndustrialDual020mA

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb

Overview

Measures two DC currents between 0mA and 20mA (IEC 60381-1)

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

228
DEVICE_DISPLAY_NAME =

:nodoc:

'Industrial Dual 0-20mA Bricklet'
CALLBACK_CURRENT =

This callback is triggered periodically with the period that is set by BrickletIndustrialDual020mA#set_current_callback_period. The parameter is the current of the sensor.

The CALLBACK_CURRENT callback is only triggered if the current has changed since the last triggering.

10
CALLBACK_CURRENT_REACHED =

This callback is triggered when the threshold as set by BrickletIndustrialDual020mA#set_current_callback_threshold is reached. The parameter is the current of the sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletIndustrialDual020mA#set_debounce_period.

11
FUNCTION_GET_CURRENT =

:nodoc:

1
FUNCTION_SET_CURRENT_CALLBACK_PERIOD =

:nodoc:

2
FUNCTION_GET_CURRENT_CALLBACK_PERIOD =

:nodoc:

3
FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD =

:nodoc:

4
FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD =

:nodoc:

5
FUNCTION_SET_DEBOUNCE_PERIOD =

:nodoc:

6
FUNCTION_GET_DEBOUNCE_PERIOD =

:nodoc:

7
FUNCTION_SET_SAMPLE_RATE =

:nodoc:

8
FUNCTION_GET_SAMPLE_RATE =

:nodoc:

9
FUNCTION_GET_IDENTITY =

:nodoc:

255
THRESHOLD_OPTION_OFF =

:nodoc:

'x'
THRESHOLD_OPTION_OUTSIDE =

:nodoc:

'o'
THRESHOLD_OPTION_INSIDE =

:nodoc:

'i'
THRESHOLD_OPTION_SMALLER =

:nodoc:

'<'
THRESHOLD_OPTION_GREATER =

:nodoc:

'>'
SAMPLE_RATE_240_SPS =

:nodoc:

0
SAMPLE_RATE_60_SPS =

:nodoc:

1
SAMPLE_RATE_15_SPS =

:nodoc:

2
SAMPLE_RATE_4_SPS =

:nodoc:

3

Constants inherited from Device

Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE

Instance Attribute Summary

Attributes inherited from Device

#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid

Instance Method Summary collapse

Methods inherited from Device

#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletIndustrialDual020mA

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 59

def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_SAMPLE_RATE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_SAMPLE_RATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_CURRENT] = [13, 'C l']
  @callback_formats[CALLBACK_CURRENT_REACHED] = [13, 'C l']

  @ipcon.add_device self
end

Instance Method Details

#get_current(sensor) ⇒ Object

Returns the current of the specified sensor.

It is possible to detect if an IEC 60381-1 compatible sensor is connected and if it works properly.

If the returned current is below 4mA, there is likely no sensor connected or the sensor may be defect. If the returned current is over 20mA, there might be a short circuit or the sensor may be defect.

If you want to get the current periodically, it is recommended to use the CALLBACK_CURRENT callback and set the period with BrickletIndustrialDual020mA#set_current_callback_period.



93
94
95
96
97
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 93

def get_current(sensor)
  check_validity

  send_request FUNCTION_GET_CURRENT, [sensor], 'C', 12, 'l'
end

#get_current_callback_period(sensor) ⇒ Object

Returns the period as set by BrickletIndustrialDual020mA#set_current_callback_period.



111
112
113
114
115
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 111

def get_current_callback_period(sensor)
  check_validity

  send_request FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [sensor], 'C', 12, 'L'
end

#get_current_callback_threshold(sensor) ⇒ Object

Returns the threshold as set by BrickletIndustrialDual020mA#set_current_callback_threshold.



136
137
138
139
140
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 136

def get_current_callback_threshold(sensor)
  check_validity

  send_request FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [sensor], 'C', 17, 'k l l'
end

#get_debounce_periodObject

Returns the debounce period as set by BrickletIndustrialDual020mA#set_debounce_period.



158
159
160
161
162
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 158

def get_debounce_period
  check_validity

  send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
end

#get_identityObject

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.

The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|



196
197
198
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 196

def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end

#get_sample_rateObject

Returns the sample rate as set by BrickletIndustrialDual020mA#set_sample_rate.



180
181
182
183
184
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 180

def get_sample_rate
  check_validity

  send_request FUNCTION_GET_SAMPLE_RATE, [], '', 9, 'C'
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



201
202
203
204
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 201

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#set_current_callback_period(sensor, period) ⇒ Object

Sets the period with which the CALLBACK_CURRENT callback is triggered periodically for the given sensor. A value of 0 turns the callback off.

The CALLBACK_CURRENT callback is only triggered if the current has changed since the last triggering.



104
105
106
107
108
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 104

def set_current_callback_period(sensor, period)
  check_validity

  send_request FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [sensor, period], 'C L', 8, ''
end

#set_current_callback_threshold(sensor, option, min, max) ⇒ Object

Sets the thresholds for the CALLBACK_CURRENT_REACHED callback for the given sensor.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the current is *outside* the min and max values"
"'i'",    "Callback is triggered when the current is *inside* the min and max values"
"'<'",    "Callback is triggered when the current is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the current is greater than the min value (max is ignored)"


129
130
131
132
133
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 129

def set_current_callback_threshold(sensor, option, min, max)
  check_validity

  send_request FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [sensor, option, min, max], 'C k l l', 8, ''
end

#set_debounce_period(debounce) ⇒ Object

Sets the period with which the threshold callback

  • CALLBACK_CURRENT_REACHED

is triggered, if the threshold

  • BrickletIndustrialDual020mA#set_current_callback_threshold

keeps being reached.



151
152
153
154
155
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 151

def set_debounce_period(debounce)
  check_validity

  send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
end

#set_sample_rate(rate) ⇒ Object

Sets the sample rate to either 240, 60, 15 or 4 samples per second. The resolution for the rates is 12, 14, 16 and 18 bit respectively.

"Value", "Description"

"0",    "240 samples per second, 12 bit resolution"
"1",    "60 samples per second, 14 bit resolution"
"2",    "15 samples per second, 16 bit resolution"
"3",    "4 samples per second, 18 bit resolution"


173
174
175
176
177
# File 'lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb', line 173

def set_sample_rate(rate)
  check_validity

  send_request FUNCTION_SET_SAMPLE_RATE, [rate], 'C', 8, ''
end