Class: Minilab::Minilab
- Inherits:
-
Object
- Object
- Minilab::Minilab
- Defined in:
- lib/minilab/minilab.rb
Overview
Instance Method Summary collapse
-
#configure_input_port(port) ⇒ true
Configure one of the DB37 ports for input.
-
#configure_output_port(port) ⇒ true
Configure one of the DB37 ports for output.
-
#connect ⇒ true
Connect to the device.
-
#read_analog(channel) ⇒ Float
Read from one of the eight analog channels on top of the device.
-
#read_digital(pin) ⇒ Fixnum
Read a single bit from one of the auxport pins (on the top of the device) or from a DB37 pin.
-
#read_digital_byte(port) ⇒ Fixnum
Read a byte from one of the DB37 ports.
-
#write_analog(channel, volts) ⇒ Object
Output a voltage on one of the eight analog channels.
-
#write_digital(pin, value) ⇒ true
Write a single bit to one of the auxport pins (on the top of the device) or to a DB37 pin.
Instance Method Details
#configure_input_port(port) ⇒ true
Configure one of the DB37 ports for input.
64 65 66 67 |
# File 'lib/minilab/minilab.rb', line 64 def configure_input_port(port) ensure_connected_to_device @digital_port_io.configure_input_port(port) end |
#configure_output_port(port) ⇒ true
Configure one of the DB37 ports for output.
74 75 76 77 |
# File 'lib/minilab/minilab.rb', line 74 def configure_output_port(port) ensure_connected_to_device @digital_port_io.configure_output_port(port) end |
#connect ⇒ true
Connect to the device. There are two side effects of connecting.
-
Error reporting from MCC’s universal library is set to print errors to standard out instead of popping up a Windows dialog.
-
Each of the DB37 digital ports is setup for input.
24 25 26 27 28 29 30 |
# File 'lib/minilab/minilab.rb', line 24 def connect @minilab_wrapper.setup_error_handling(DONTPRINT, STOPALL) @minilab_wrapper.declare_revision(CURRENTREVNUM) @connection_state.connected = true DigitalConfiguration::PORTS.each { |port| configure_input_port(port) } true end |
#read_analog(channel) ⇒ Float
Read from one of the eight analog channels on top of the device.
Single-ended mode is the only analog mode supported.
39 40 41 42 |
# File 'lib/minilab/minilab.rb', line 39 def read_analog(channel) ensure_connected_to_device @analog_io.read_analog(channel) end |
#read_digital(pin) ⇒ Fixnum
Read a single bit from one of the auxport pins (on the top of the device) or from a DB37 pin. Ensure the pin has been configured for input (see #configure_input_port) before using this method. auxport pins do not need to be configured.
89 90 91 92 |
# File 'lib/minilab/minilab.rb', line 89 def read_digital(pin) ensure_connected_to_device perform_digital_op(pin, :read, pin) end |
#read_digital_byte(port) ⇒ Fixnum
Read a byte from one of the DB37 ports.
117 118 119 120 |
# File 'lib/minilab/minilab.rb', line 117 def read_digital_byte(port) ensure_connected_to_device @digital_port_io.read_port(port) end |
#write_analog(channel, volts) ⇒ Object
Output a voltage on one of the eight analog channels. The output voltage must be in the range of 0.0 - 5.0 volts.
Single-ended mode is the only analog mode supported.
53 54 55 56 |
# File 'lib/minilab/minilab.rb', line 53 def write_analog(channel, volts) ensure_connected_to_device @analog_io.write_analog(channel, volts) end |
#write_digital(pin, value) ⇒ true
Write a single bit to one of the auxport pins (on the top of the device) or to a DB37 pin. Ensure the pin has been configured for output (see #configure_output_port) before using this method. auxport pins do not need to be configured.
107 108 109 110 |
# File 'lib/minilab/minilab.rb', line 107 def write_digital(pin, value) ensure_connected_to_device perform_digital_op(pin, :write, pin, value) end |