Class: Tinkerforge::BrickletAnalogOutV2

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

Overview

Generates configurable DC voltage between 0V and 12V

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

256
DEVICE_DISPLAY_NAME =

:nodoc:

'Analog Out Bricklet 2.0'
FUNCTION_SET_OUTPUT_VOLTAGE =

:nodoc:

1
FUNCTION_GET_OUTPUT_VOLTAGE =

:nodoc:

2
FUNCTION_GET_INPUT_VOLTAGE =

:nodoc:

3
FUNCTION_GET_IDENTITY =

:nodoc:

255

Constants inherited from Device

Device::RESPONSE_EXPECTED_ALWAYS_FALSE, 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, #registered_callbacks, #uid

Instance Method Summary collapse

Methods inherited from Device

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

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletAnalogOutV2

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



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tinkerforge/bricklet_analog_out_v2.rb', line 26

def initialize(uid, ipcon)
  super uid, ipcon

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_SET_OUTPUT_VOLTAGE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_OUTPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

end

Instance Method Details

#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’ or ‘d’.

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



61
62
63
# File 'lib/tinkerforge/bricklet_analog_out_v2.rb', line 61

def get_identity
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
end

#get_input_voltageObject

Returns the input voltage in mV.



49
50
51
# File 'lib/tinkerforge/bricklet_analog_out_v2.rb', line 49

def get_input_voltage
  send_request(FUNCTION_GET_INPUT_VOLTAGE, [], '', 2, 'S')
end

#get_output_voltageObject

Returns the voltage as set by BrickletAnalogOutV2#set_output_voltage.



44
45
46
# File 'lib/tinkerforge/bricklet_analog_out_v2.rb', line 44

def get_output_voltage
  send_request(FUNCTION_GET_OUTPUT_VOLTAGE, [], '', 2, 'S')
end

#set_output_voltage(voltage) ⇒ Object

Sets the voltage in mV. The possible range is 0V to 12V (0-12000).



39
40
41
# File 'lib/tinkerforge/bricklet_analog_out_v2.rb', line 39

def set_output_voltage(voltage)
  send_request(FUNCTION_SET_OUTPUT_VOLTAGE, [voltage], 'S', 0, '')
end