Class: Phidgets::Analog::AnalogOutputs

Inherits:
Object
  • Object
show all
Defined in:
lib/phidgets-ffi/analog.rb

Overview

This class represents an analog output for a PhidgetAnalog. All the properties of an output are stored and modified in this class.

Constant Summary collapse

Klass =
Phidgets::FFI::CPhidgetAnalog

Instance Method Summary collapse

Instance Method Details

#enabledBoolean

Returns the enabled state of an output, or raises an error.

Returns:

  • (Boolean)

    returns the enabled state of an output, or raises an error.



64
65
66
67
68
# File 'lib/phidgets-ffi/analog.rb', line 64

def enabled
  ptr = ::FFI::MemoryPointer.new(:int)
  Klass.getEnabled(@handle, @index, ptr)
  (ptr.get_int(0) == 0) ? false : true
end

#enabled=(new_state) ⇒ Boolean

Sets the enabled state of an output, or raises an error.

Parameters:

  • new_state (Boolean)

    new state

Returns:

  • (Boolean)

    returns the enabled state of an output, or raises an error.



73
74
75
76
77
# File 'lib/phidgets-ffi/analog.rb', line 73

def enabled=(new_state)
  tmp = new_state ? 1 : 0
  Klass.setEnabled(@handle, @index, tmp)
  new_state
end

#indexInteger

Returns the index of an output, or raises an error.

Returns:

  • (Integer)

    returns the index of an output, or raises an error.



58
59
60
# File 'lib/phidgets-ffi/analog.rb', line 58

def index 
	@index
end

#inspectObject

Displays data for the analog output



53
54
55
# File 'lib/phidgets-ffi/analog.rb', line 53

def inspect
     "#<#{self.class} @index=#{index}, @enabled=#{enabled}, @voltage=#{voltage}, @voltage_min=#{voltage_min}, @voltage_max=#{voltage_max}>"
end

#voltageFloat

Returns the voltage of an output, in V, or raises an error.

Returns:

  • (Float)

    returns the voltage of an output, in V, or raises an error.



80
81
82
83
84
# File 'lib/phidgets-ffi/analog.rb', line 80

def voltage
  ptr = ::FFI::MemoryPointer.new(:double)
  Klass.getVoltage(@handle, @index, ptr)
  ptr.get_double(0)
end

#voltage=(new_voltage) ⇒ Float

Sets the voltage of an output, in V, or raises an error.

Parameters:

  • new_voltage (Float)

    new voltage

Returns:

  • (Float)

    returns the voltage of an output, in V, or raises an error.



89
90
91
92
# File 'lib/phidgets-ffi/analog.rb', line 89

def voltage=(new_voltage)
  Klass.setVoltage(@handle, @index, new_voltage.to_f)
  new_voltage
end

#voltage_maxFloat

Returns the maximum supported output voltage, or raises an error.

Returns:

  • (Float)

    returns the maximum supported output voltage, or raises an error.



102
103
104
105
106
# File 'lib/phidgets-ffi/analog.rb', line 102

def voltage_max
  ptr = ::FFI::MemoryPointer.new(:double)
  Klass.getVoltageMax(@handle, @index, ptr)
  ptr.get_double(0)
end

#voltage_minFloat

Returns the minimum supported output voltage, or raises an error.

Returns:

  • (Float)

    returns the minimum supported output voltage, or raises an error.



95
96
97
98
99
# File 'lib/phidgets-ffi/analog.rb', line 95

def voltage_min
  ptr = ::FFI::MemoryPointer.new(:double)
  Klass.getVoltageMin(@handle, @index, ptr)
  ptr.get_double(0)
end