Class: PhidgetsNative::InterfaceKit

Inherits:
Device
  • Object
show all
Defined in:
ext/phidgets_native/interfacekit_ruby.c,
ext/phidgets_native/interfacekit_ruby.c

Overview

This class provides functionality specific to the “InterfaceKit” device class. Primarily, this phidget reports the values of analog and digital inputs, and provides interfaces for outputing to analog and digital components.

NOTE: Unlike the native phidget libraries, this implementation supports a “Dual Ratiometric” mode for the interface kit. This dual-mode is acheived by rapidly cycling the controller between ratiometric on and off states in the device polling loop. The benefit to supporting mixed states is that you can support multiple devices types on a single controller. Unfortunately, the ramification of doing so reduces the sample rates to a small fraction (roughly 8 times per second) of the maximum data rate (roughly 125 times per second). For many applications, the sampling rates aren’t so sensitive that dual-ratiometric mode will be a problem.

“Dual ratiometric” mode will automatically enable itself if you specify per-sensor ratiometric states using the ratiometric() method. Similary, uniform-ratiometric mode will automatically return at any time that all sensors return to a uniform state. If you don’t intend to take advantage of this feature, simply use the ratiometric= method to set all analog inputs to the same state, and ignore the ratiometric() method.

Defined Under Namespace

Classes: RatiometricNotUniform

Instance Method Summary collapse

Constructor Details

#new(serial_number) ⇒ Object

All phidget objects are created from the device serial number. Serial numbers are required to be Fixnums (aka “unsigned integers”).

Instance Method Details

#change_trigger(Fixnumindex, Fixnumthreshold) ⇒ Fixnum

This method sets the change trigger for the analog sensor at the provided index the specified threshold. This threshould must be between 1 and 1000. The return value is simply what was specified for the rate. Keep in mind that setting a data rate, reverts the data_rate for that input to nil. For more information on how analog inputs are polled, you can read up on the Phidget Analog Input Primer

Returns:

  • (Fixnum)

#change_triggersArray

Returns an array of either ints or nils, which specify the current change_trigger threshold for each analog input sensor. A nil indicates that this input is in data_rate mode. If the whole return value is nil, this means that the device hasn’t been connected yet.

Returns:

  • (Array)

#closenil

This method will unregister the phidget event handlers, and free up all API resources associated with the phidget. This is an optional, but useful way to remove the object’s overhead before the GC kicks in and actually frees the resource.

Returns:

  • (nil)

#data_rate(Fixnumindex, Fixnumrate) ⇒ Fixnum

This method sets the data rate for the analog sensor at the provided index to the rate specified. This rate must be between data_rate_min and data_rate_max. The return value is simply what was specified for the rate. Keep in mind that setting a data rate, reverts the change_trigger for that input to nil. For more information on how analog inputs are polled, you can read up on the Phidget Analog Input Primer

Returns:

  • (Fixnum)

#data_ratesArray

Returns an array of either ints or nils, which specify the current data_rate for each analog input sensor. A nil indicates that this input is in change_trigger mode. If the whole return value is nil, this means that the device hasn’t been connected yet.

Returns:

  • (Array)

#data_rates_maxArray

Returns an array of ints which specify the maximum data_rate value that can be configured on each analog input sensor, or nil if the device has yet to be connected.

Returns:

  • (Array)

#data_rates_minArray

Returns an array of ints which specify the minimum data_rate value that can be configured on each analog input sensor, or nil if the device has yet to be connected.

Returns:

  • (Array)

#input_countFixnum

Returns an integer which represents the number of digital inputs provided by this interface kit, or nil if the device has yet to be connected.

Returns:

  • (Fixnum)

#input_sample_ratesArray

The interface kit object tracks the sample rate of each input individually. This method returns an array containing the sample rates of each digital sensor.

Returns:

  • (Array)

#inputsArray

Returns an array of bools, which specify the current digital input states. A return of nil indicates that this device is unplugged

Returns:

  • (Array)

#output(Fixnum, Boolean) ⇒ Boolean

This method sets the value of the specified digital output at the provided Fixnum offset to the Boolean state (true is on, false is off). The return value is simply what was specified for the input state. For more information on output control, you can read up on the CPhidgetInterfaceKit_setOutputState function.

Returns:

  • (Boolean)

#output_countFixnum

Returns an integer which represents the number of digital outputs provided by this interface kit, or nil if the device has yet to be connected.

Returns:

  • (Fixnum)

#outputsArray

Returns an array of bools, which specify the current digital output states. A return of nil indicates that this device is unplugged

Returns:

  • (Array)

#ratiometric(Fixnumindex, Booleanstate) ⇒ Fixnum

This method sets the ratiometric state for the analog sensor at the provided index. Note that phidget boards only support a board-wide ratiometric state. As such, when you set the state per the sensor in this library, the library will automatically toggle the board state between ratio and non-ratio metric modes for you. As a side-effect of the toggle action, your data rate will drop substantially, and you’ll not be able to adjust the data_rate and change_trigger parameters. To re-enable the data_rate and change_trigger features, use the ratiometric= method to set the state for the entire board. The return value for this method is simply what was specified for the state. For more information on how analog inputs are polled, you can read up on the Phidget Analog Input Primer

Returns:

  • (Fixnum)

#ratiometric=(Booleanstate) ⇒ Boolean

Sets the analog sensor voltage reference to ratiometric mode on true, or stable on false. Read more about this feature in the Analog Inputs Primer

Returns:

  • (Boolean)

#ratiometric?Boolean

Returns true if the analog sensors are currently in ratiometric mode. False if the controller is set to a stable voltage reference. Read more about this feature in the Analog Inputs Primer

Returns:

  • (Boolean)

#sensor_countFixnum

Returns an integer which represents the number of analog inputs provided by this interface kit, or nil if the device has yet to be connected.

Returns:

  • (Fixnum)

#sensor_raw(Fixnum) ⇒ Fixnum

This method returns the “raw” value of the sensor at the provided offset. For more information on raw sensor values read up on the CPhidgetInterfaceKit_getSensorRawValue function.

Returns:

  • (Fixnum)

#sensor_sample_ratesArray

The interface kit object tracks the sample rate of each sensor individually. This method returns an array containing the sample rates of each analog sensor.

Returns:

  • (Array)

#sensorsArray

Returns an array of ints, which specify the current analog sensor states. A return of nil indicates that this device is unplugged

Returns:

  • (Array)