Class: Tinkerforge::BrickletAnalogOut
- Defined in:
- lib/tinkerforge/bricklet_analog_out.rb
Overview
Generates configurable DC voltage between 0V and 5V
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
220
- DEVICE_DISPLAY_NAME =
:nodoc:
'Analog Out Bricklet'
- FUNCTION_SET_VOLTAGE =
:nodoc:
1
- FUNCTION_GET_VOLTAGE =
:nodoc:
2
- FUNCTION_SET_MODE =
:nodoc:
3
- FUNCTION_GET_MODE =
:nodoc:
4
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- MODE_ANALOG_VALUE =
:nodoc:
0
- MODE_1K_TO_GROUND =
:nodoc:
1
- MODE_100K_TO_GROUND =
:nodoc:
2
- MODE_500K_TO_GROUND =
: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
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_mode ⇒ Object
Returns the mode as set by BrickletAnalogOut#set_mode.
-
#get_voltage ⇒ Object
Returns the voltage as set by BrickletAnalogOut#set_voltage.
-
#initialize(uid, ipcon) ⇒ BrickletAnalogOut
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#set_mode(mode) ⇒ Object
Sets the mode of the analog value.
-
#set_voltage(voltage) ⇒ Object
Sets the voltage.
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) ⇒ BrickletAnalogOut
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 33 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 0] @response_expected[FUNCTION_SET_VOLTAGE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_MODE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @ipcon.add_device self end |
Instance Method Details
#get_identity ⇒ Object
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|
95 96 97 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 95 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_mode ⇒ Object
Returns the mode as set by BrickletAnalogOut#set_mode.
79 80 81 82 83 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 79 def get_mode check_validity send_request FUNCTION_GET_MODE, [], '', 9, 'C' end |
#get_voltage ⇒ Object
Returns the voltage as set by BrickletAnalogOut#set_voltage.
57 58 59 60 61 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 57 def get_voltage check_validity send_request FUNCTION_GET_VOLTAGE, [], '', 10, 'S' end |
#set_mode(mode) ⇒ Object
Sets the mode of the analog value. Possible modes:
-
0: Normal Mode (Analog value as set by BrickletAnalogOut#set_voltage is applied)
-
1: 1k Ohm resistor to ground
-
2: 100k Ohm resistor to ground
-
3: 500k Ohm resistor to ground
Setting the mode to 0 will result in an output voltage of 0 V. You can jump to a higher output voltage directly by calling BrickletAnalogOut#set_voltage.
72 73 74 75 76 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 72 def set_mode(mode) check_validity send_request FUNCTION_SET_MODE, [mode], 'C', 8, '' end |
#set_voltage(voltage) ⇒ Object
Sets the voltage. Calling this function will set the mode to 0 (see BrickletAnalogOut#set_mode).
50 51 52 53 54 |
# File 'lib/tinkerforge/bricklet_analog_out.rb', line 50 def set_voltage(voltage) check_validity send_request FUNCTION_SET_VOLTAGE, [voltage], 'S', 8, '' end |