minilab 1.0.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/.document +2 -0
  2. data/CHANGES +2 -0
  3. data/LICENSE +19 -0
  4. data/README +107 -0
  5. data/Rakefile +145 -0
  6. data/config/environment.rb +15 -0
  7. data/config/objects.yml +22 -0
  8. data/lib/analog_io.rb +30 -0
  9. data/lib/digital_auxport_io.rb +49 -0
  10. data/lib/digital_configuration.rb +66 -0
  11. data/lib/digital_port_io.rb +68 -0
  12. data/lib/extension/extconf.rb +4 -0
  13. data/lib/extension/minilab_hardware.c +235 -0
  14. data/lib/extension/minilab_hardware.so +0 -0
  15. data/lib/library_translator.rb +48 -0
  16. data/lib/minilab.rb +149 -0
  17. data/lib/minilab_context.rb +39 -0
  18. data/lib/result_verifier.rb +14 -0
  19. data/test/integration/analog_input_output_test.rb +43 -0
  20. data/test/integration/connect_to_hardware_test.rb +13 -0
  21. data/test/integration/digital_input_output_test.rb +114 -0
  22. data/test/integration/integration_test.rb +53 -0
  23. data/test/integration/require_minilab_test.rb +9 -0
  24. data/test/system/analog_input.test +3 -0
  25. data/test/system/analog_output.test +37 -0
  26. data/test/system/digital_port_input.test +5 -0
  27. data/test/system/digital_port_output.test +39 -0
  28. data/test/system/digital_port_read_byte.test +26 -0
  29. data/test/system/digital_screw_terminals_input.test +2 -0
  30. data/test/system/digital_screw_terminals_output.test +11 -0
  31. data/test/system/minilab_driver.rb +85 -0
  32. data/test/test_helper.rb +11 -0
  33. data/test/unit/analog_io_test.rb +87 -0
  34. data/test/unit/digital_auxport_io_test.rb +114 -0
  35. data/test/unit/digital_configuration_test.rb +136 -0
  36. data/test/unit/digital_port_io_test.rb +117 -0
  37. data/test/unit/library_translator_test.rb +100 -0
  38. data/test/unit/minilab_context_test.rb +82 -0
  39. data/test/unit/minilab_hardware_test.rb +83 -0
  40. data/test/unit/minilab_test.rb +131 -0
  41. data/test/unit/result_verifier_test.rb +33 -0
  42. data/vendor/behaviors/lib/behaviors.rb +50 -0
  43. data/vendor/behaviors/tasks/behaviors_tasks.rake +140 -0
  44. data/vendor/behaviors/test/behaviors_tasks_test.rb +71 -0
  45. data/vendor/behaviors/test/behaviors_test.rb +50 -0
  46. data/vendor/behaviors/test/tasks_test/Rakefile +16 -0
  47. data/vendor/behaviors/test/tasks_test/doc/behaviors.html +55 -0
  48. data/vendor/behaviors/test/tasks_test/lib/user.rb +2 -0
  49. data/vendor/behaviors/test/tasks_test/test/user_test.rb +17 -0
  50. data/vendor/constructor/Rakefile +44 -0
  51. data/vendor/constructor/config/environment.rb +12 -0
  52. data/vendor/constructor/lib/constructor.rb +132 -0
  53. data/vendor/constructor/test/constructor_test.rb +366 -0
  54. data/vendor/constructor/test/helper.rb +3 -0
  55. data/vendor/diy/README +26 -0
  56. data/vendor/diy/Rakefile +18 -0
  57. data/vendor/diy/lib/constructor.rb +114 -0
  58. data/vendor/diy/lib/diy.rb +329 -0
  59. data/vendor/diy/proto/context.rb +117 -0
  60. data/vendor/diy/proto/context.yml +20 -0
  61. data/vendor/diy/test/diy_test.rb +370 -0
  62. data/vendor/diy/test/files/broken_construction.yml +7 -0
  63. data/vendor/diy/test/files/cat/cat.rb +4 -0
  64. data/vendor/diy/test/files/cat/extra_conflict.yml +5 -0
  65. data/vendor/diy/test/files/cat/heritage.rb +2 -0
  66. data/vendor/diy/test/files/cat/needs_input.yml +3 -0
  67. data/vendor/diy/test/files/cat/the_cat_lineage.rb +1 -0
  68. data/vendor/diy/test/files/dog/dog_model.rb +4 -0
  69. data/vendor/diy/test/files/dog/dog_presenter.rb +4 -0
  70. data/vendor/diy/test/files/dog/dog_view.rb +2 -0
  71. data/vendor/diy/test/files/dog/file_resolver.rb +2 -0
  72. data/vendor/diy/test/files/dog/other_thing.rb +2 -0
  73. data/vendor/diy/test/files/dog/simple.yml +11 -0
  74. data/vendor/diy/test/files/donkey/foo.rb +8 -0
  75. data/vendor/diy/test/files/donkey/foo/bar/qux.rb +7 -0
  76. data/vendor/diy/test/files/fud/objects.yml +13 -0
  77. data/vendor/diy/test/files/fud/toy.rb +15 -0
  78. data/vendor/diy/test/files/gnu/objects.yml +14 -0
  79. data/vendor/diy/test/files/gnu/thinger.rb +8 -0
  80. data/vendor/diy/test/files/goat/base.rb +8 -0
  81. data/vendor/diy/test/files/goat/can.rb +6 -0
  82. data/vendor/diy/test/files/goat/goat.rb +6 -0
  83. data/vendor/diy/test/files/goat/objects.yml +12 -0
  84. data/vendor/diy/test/files/goat/paper.rb +6 -0
  85. data/vendor/diy/test/files/goat/plane.rb +8 -0
  86. data/vendor/diy/test/files/goat/shirt.rb +6 -0
  87. data/vendor/diy/test/files/goat/wings.rb +8 -0
  88. data/vendor/diy/test/files/horse/holder_thing.rb +4 -0
  89. data/vendor/diy/test/files/horse/objects.yml +7 -0
  90. data/vendor/diy/test/files/yak/core_model.rb +4 -0
  91. data/vendor/diy/test/files/yak/core_presenter.rb +4 -0
  92. data/vendor/diy/test/files/yak/core_view.rb +1 -0
  93. data/vendor/diy/test/files/yak/data_source.rb +1 -0
  94. data/vendor/diy/test/files/yak/fringe_model.rb +4 -0
  95. data/vendor/diy/test/files/yak/fringe_presenter.rb +4 -0
  96. data/vendor/diy/test/files/yak/fringe_view.rb +1 -0
  97. data/vendor/diy/test/files/yak/my_objects.yml +21 -0
  98. data/vendor/diy/test/test_helper.rb +40 -0
  99. data/vendor/hardmock/CHANGES +8 -0
  100. data/vendor/hardmock/LICENSE +7 -0
  101. data/vendor/hardmock/README +48 -0
  102. data/vendor/hardmock/Rakefile +100 -0
  103. data/vendor/hardmock/TODO +7 -0
  104. data/vendor/hardmock/config/environment.rb +12 -0
  105. data/vendor/hardmock/homepage/demo.rb +21 -0
  106. data/vendor/hardmock/homepage/hardmock_sample.png +0 -0
  107. data/vendor/hardmock/homepage/index.html +65 -0
  108. data/vendor/hardmock/init.rb +3 -0
  109. data/vendor/hardmock/lib/hardmock.rb +634 -0
  110. data/vendor/hardmock/lib/method_cleanout.rb +14 -0
  111. data/vendor/hardmock/rcov.rake +18 -0
  112. data/vendor/hardmock/test/functional/assert_error_test.rb +52 -0
  113. data/vendor/hardmock/test/functional/auto_verify_test.rb +192 -0
  114. data/vendor/hardmock/test/functional/direct_mock_usage_test.rb +396 -0
  115. data/vendor/hardmock/test/functional/hardmock_test.rb +380 -0
  116. data/vendor/hardmock/test/test_helper.rb +23 -0
  117. data/vendor/hardmock/test/unit/expectation_builder_test.rb +18 -0
  118. data/vendor/hardmock/test/unit/expector_test.rb +56 -0
  119. data/vendor/hardmock/test/unit/method_cleanout_test.rb +35 -0
  120. data/vendor/hardmock/test/unit/mock_control_test.rb +172 -0
  121. data/vendor/hardmock/test/unit/mock_test.rb +273 -0
  122. data/vendor/hardmock/test/unit/simple_expectation_test.rb +345 -0
  123. data/vendor/hardmock/test/unit/trapper_test.rb +60 -0
  124. data/vendor/hardmock/test/unit/verify_error_test.rb +34 -0
  125. data/vendor/systir/systir.rb +403 -0
  126. data/vendor/systir/test/unit/ui/xml/testrunner.rb +192 -0
  127. data/vendor/systir/test/unit/ui/xml/xmltestrunner.xslt +109 -0
  128. metadata +235 -0
@@ -0,0 +1,2 @@
1
+ README
2
+ lib/minilab.rb
data/CHANGES ADDED
@@ -0,0 +1,2 @@
1
+ == 1.0.0
2
+ First release
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2007 Atomic Object, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,107 @@
1
+ == About
2
+
3
+ minilab is a Ruby extension for Measurement Computing's miniLAB 1008 device. The minilab extension provides a simple interface to several of the miniLAB 1008's analog and digital IO functions. I've used the miniLAB to control the input and examine the output from our embedded devices; the minilab extension allowed us to use automated system testing tools for Ruby.
4
+
5
+ minilab is not guaranteed to work with other Measurement Computing devices, but could be extended to do so.
6
+
7
+ == Installation
8
+
9
+ 1. Install the minilab gem onto your system or unpack it into a local directory in your project. Install Measurement Computing's Universal Library and InstaCal software; both come on CDs with the device.
10
+
11
+ 1. Plug in the device and then fire up the InstaCal software. Go to Install -> Configure in the menus and the Custom Serial Number to 253, No. of Channels to 8 Single Ended, and Trigger Source to DIO0. Use the Flash LED button to ensure that InstaCal can communicate with the device (I've never had a problem with this). Although I don't think the Custom Serial Number and Trigger Source make much difference to my extension, the No. of Channels is important (see Known limitations below).
12
+
13
+ 1. That should be it---you should now be able to require 'lib/minilab,' create a minilab object, and connect to it. If you can't, please contact me! I've only installed this on a limited number of computers, so I'd like to hear about problems with the library installation, gem installation, LOAD_PATH, etc.
14
+
15
+ === Building the C extension
16
+ I included a precompiled version of the C extension with the gem so that everyone doesn't need to worry about compiling. If you'd really like to compile it, then the Rakefile has several targets for managing the build (see extension:build, extension:clean). In order to build, there is a good chance you'll need to edit the Rakefile to use the correct paths to your build environment (they are at the bottom). Right now they're set up strictly for my laptop.
17
+
18
+ == Usage
19
+ === Build and connect
20
+
21
+ First you'll need to build the Minilab object; use the Minilab.build class method to do this. The class method is important to use instead of +new+, since it takes care of a lot of behind-the-scenes object construction for you.
22
+
23
+ After building the object, use the +connect+ method. This will establish the connection to the library. None of the other methods will work until you connect.
24
+
25
+ Example:
26
+
27
+ <tt>minilab = Minilab.build</tt>
28
+
29
+ <tt>minilab.connect</tt>
30
+
31
+ === Reading and writing data
32
+
33
+ I've created methods for reading and writing both digital and analog data from the device. Analog data goes through the read and write pins on the top of the device; no configuration is needed for the analog methods.
34
+
35
+ Digital data goes through either the DIO pins on the top of the device or the digital ports on the DB37 port. If you're using the DIO pins, then you don't need to do any configuration. If you're using the DB37 pins, then you'll need to configure the appropriate port for input and output. You can find a mapping of DB37 pin numbers to ports either in Measurement Computing's miniLAB 1008 data sheet or at the end of this README.
36
+
37
+ Check out the read and write analog and read, write, and configure digital methods in the Minilab document for more information.
38
+
39
+ Example:
40
+
41
+ <tt> minilab.configure_input_port(:portb) </tt>
42
+
43
+ <tt> value = minilab.read_digital_byte(:portb) </tt>
44
+
45
+ <tt> assert_equal 12, value, "wrong value read for system time" </tt>
46
+
47
+ The adventurous may also want to look at the included system tests for the device, since they are examples of how to use the device and are not contrived.
48
+
49
+ == Tests
50
+
51
+ The minilab extension comes with unit, integration, and system tests. The unit tests stress individual units. The integration and system tests represent real use cases for the software; in the case of integration tests, the hardware is mocked out whereas the hardware is not mocked during system tests. This means that unit and integration tests can be run without the hardware plugged in, but system tests require the hardware. Even though there is some overlap between integration and system tests, integration tests made it easier for me to safely develop new features without having bulky hardware plugged in all the time.
52
+
53
+ See the end of the document of this document for an outline of how a miniLAB and DB37 connector should be set up in order to run the system tests.
54
+
55
+ == Known limitations
56
+
57
+ * The minilab extension only supports one device plugged in at a time. I could add support for multiple devices, but since I only have one, I haven't bothered adding support for more than one.
58
+
59
+ * I never got around to writing out an entire digital byte because I never needed it.
60
+
61
+ * Reading analog values only supports single-ended mode. As you can probably guess, I didn't need differential mode, so I didn't add support for it.
62
+
63
+ In any case, contact me if you'd like me to implement any of this functionality. Add functionality yourself is always possible and may be quicker than waiting for me to do it.
64
+
65
+ == Contact information
66
+ Matt Fletcher
67
+
68
+ Developer
69
+
70
+ Atomic Object, LLC
71
+
72
+ fletcher@atomicobject.com
73
+
74
+ == Appendix
75
+ === DB37 pin to port mapping
76
+ Pin:: Port
77
+ 30-37:: :porta
78
+ 3-10:: :portb
79
+ 26-29:: :portcl
80
+ 22-25:: :portch
81
+
82
+ === System test setup
83
+
84
+ On top of the miniLAB:
85
+ CH0 IN:: D/A OUT 1
86
+ CH1 IN:: GND
87
+ CH2 IN:: DIO0
88
+ CH4 IN:: PC +5V
89
+ CH6 IN:: D/A OUT 0
90
+ DIO0:: DIO3
91
+ DIO1:: PC +5V
92
+ DIO2:: GND
93
+
94
+ On the DB37 pins:
95
+ 3:: 11
96
+ 4:: 11
97
+ 5:: 28
98
+ 6:: 11
99
+ 7:: 36
100
+ 8:: 11
101
+ 9:: 11
102
+ 10:: 20
103
+ 22:: 27
104
+ 23:: 21
105
+ 24:: 34
106
+ 25:: 21
107
+ 30:: 21
@@ -0,0 +1,145 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/config/environment")
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ EXTENSION_DIR = 'lib/extension/'
7
+ extension = namespace :extension do
8
+ file "#{EXTENSION_DIR}/Makefile" do
9
+ run_in_build_environment do
10
+ sh 'ruby extconf.rb'
11
+ end
12
+ end
13
+
14
+ file "#{EXTENSION_DIR}/minilab_hardware.c" => "#{EXTENSION_DIR}/Makefile"
15
+
16
+ file "#{EXTENSION_DIR}/minilab_hardware.so" => "#{EXTENSION_DIR}/minilab_hardware.c" do
17
+ run_in_build_environment do
18
+ sh 'nmake'
19
+ end
20
+ end
21
+
22
+ desc "Build the minilab_hardware extension"
23
+ task :build => "#{EXTENSION_DIR}/minilab_hardware.so"
24
+
25
+ desc "Clean out extension build artifacts"
26
+ task :clean do
27
+ run_in_build_environment do
28
+ sh 'nmake clean'
29
+ rm_f 'Makefile'
30
+ rm_f 'minilab_hardware-i386-mswin32.def'
31
+ rm_f 'mkmf.log'
32
+ end
33
+ end
34
+ end
35
+
36
+ test = namespace :test do
37
+ desc "Run the unit tests (doesn't require hardware)"
38
+ Rake::TestTask.new(:units => extension[:build]) do |t|
39
+ t.pattern = 'test/unit/**/*_test.rb'
40
+ t.verbose = true
41
+ end
42
+
43
+ desc "Run the integration tests (doesn't require hardware)"
44
+ Rake::TestTask.new(:integration => extension[:build]) do |t|
45
+ t.pattern = "test/integration/**/*_test.rb"
46
+ t.verbose = true
47
+ end
48
+
49
+ desc "Run the system tests (requires hardware)"
50
+ task :system => extension[:build] do
51
+ require 'systir'
52
+ require "#{SYSTEST_ROOT}/minilab_driver.rb"
53
+ result = Systir::Launcher.new.find_and_run_all_tests(MinilabDriver, SYSTEST_ROOT)
54
+ raise "SYSTEM TESTS FAILED" unless result.passed?
55
+ end
56
+
57
+ desc "Run every suite of tests"
58
+ task :all => [:units, :integration, :system]
59
+ end
60
+
61
+ desc "Compile the extension, run the unit tests, and run the integration tests"
62
+ task :default => [extension[:build], test[:units], test[:integration]]
63
+
64
+ def rdoc_options
65
+ [] << '--line-numbers' << '--inline-source' << '--main' << 'README' << '--title' << 'minilab' #<< "--op" << "rdoc"
66
+ end
67
+
68
+ gem_spec = Gem::Specification.new do |spec|
69
+ spec.name = "minilab"
70
+ spec.version = "1.0.0"
71
+ spec.author = "Matt Fletcher - Atomic Object, LLC"
72
+ spec.email = "fletcher@atomicobject.com"
73
+ spec.homepage = "http://atomicobject.com"
74
+ spec.platform = Gem::Platform::WIN32
75
+ spec.summary = "Ruby interface to Measurement Computing's miniLAB 1008"
76
+ spec.files = FileList["{test,config,vendor}/**/*"].exclude("rdoc").to_a
77
+ spec.files += FileList["lib/*"].exclude("rdoc").to_a
78
+ spec.files += ["Rakefile", "README", "LICENSE", "CHANGES", ".document"]
79
+ spec.files += ["#{EXTENSION_DIR}/minilab_hardware.c", "#{EXTENSION_DIR}/minilab_hardware.so", "#{EXTENSION_DIR}/extconf.rb"]
80
+ spec.test_files = FileList["{test/unit,test/integration}/*"]
81
+ spec.has_rdoc = true
82
+ spec.extra_rdoc_files = ["README", "CHANGES", "LICENSE"]
83
+ spec.rdoc_options = rdoc_options
84
+ end
85
+
86
+ package_task = Rake::GemPackageTask.new(gem_spec) do |pkg|
87
+ pkg.need_tar = true
88
+ pkg.need_zip = true
89
+ end
90
+
91
+ task :package => extension[:build]
92
+
93
+ desc "Clean the project of build artifacts"
94
+ task :clean => [extension[:clean], Rake::Task[:clobber_package]]
95
+
96
+ namespace :doc do
97
+ desc "Generate RDoc documentation"
98
+ Rake::RDocTask.new { |rdoc|
99
+ rdoc.rdoc_dir = 'rdoc'
100
+ rdoc.title = "minilab: Ruby extension for the miniLAB 1008"
101
+ rdoc.options = rdoc_options
102
+ rdoc.rdoc_files.include('lib/minilab.rb', 'README','CHANGES','LICENSE')
103
+ }
104
+ end
105
+
106
+ private
107
+ # These paths are all defaults for the Visual Studio .NET installation.
108
+ # This stuff is not meant to work on anyone but Matt's laptop. Working anywhere else is purely coincidence.
109
+ NEW_PATH_VARS = [
110
+ 'C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE',
111
+ 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin',
112
+ ]
113
+
114
+ NEW_INCLUDE_VARS = [
115
+ 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include',
116
+ 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include',
117
+ 'C:\MCC\C',
118
+ ]
119
+
120
+ NEW_LIB_VARS = [
121
+ 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib',
122
+ 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib',
123
+ 'C:\MCC\C',
124
+ ]
125
+
126
+ def run_in_build_environment
127
+ original_path = ENV['PATH']
128
+ original_include = ENV['INCLUDE']
129
+ original_lib = ENV['LIB']
130
+
131
+ begin
132
+ ENV['PATH'] = [NEW_PATH_VARS, ENV['PATH']].flatten.join(';')
133
+ ENV['INCLUDE'] = [NEW_INCLUDE_VARS, ENV['INCLUDE']].flatten.join(';')
134
+ ENV['LIB'] = [NEW_LIB_VARS, ENV['LIB']].flatten.join(';')
135
+
136
+ cd EXTENSION_DIR
137
+ yield
138
+ ensure
139
+ ENV['PATH'] = original_path
140
+ ENV['INCLUDE'] = original_include
141
+ ENV['LIB'] = original_lib
142
+
143
+ cd APP_ROOT
144
+ end
145
+ end
@@ -0,0 +1,15 @@
1
+ unless $environment_already_defined
2
+ APP_ROOT = File.expand_path(File.dirname(__FILE__) + "/..")
3
+ SYSTEST_ROOT = APP_ROOT + "/test/system"
4
+
5
+ [ 'lib',
6
+ 'vendor/systir',
7
+ 'vendor/hardmock/lib',
8
+ 'vendor/behaviors/lib',
9
+ 'vendor/constructor/lib',
10
+ 'vendor/diy/lib',
11
+ ].each do |dir|
12
+ $LOAD_PATH << File.join(APP_ROOT, dir)
13
+ end
14
+ $environment_already_defined = true
15
+ end
@@ -0,0 +1,22 @@
1
+ minilab:
2
+ compose: minilab_hardware, result_verifier, analog_io, digital_auxport_io, digital_port_io
3
+
4
+ minilab_hardware:
5
+ lib: extension/minilab_hardware
6
+
7
+ result_verifier:
8
+ compose: minilab_hardware
9
+
10
+ analog_io:
11
+ compose: minilab_hardware, result_verifier
12
+
13
+ digital_auxport_io:
14
+ compose: minilab_hardware, result_verifier
15
+
16
+ digital_port_io:
17
+ compose: minilab_hardware, result_verifier, digital_configuration, library_translator
18
+
19
+ library_translator:
20
+
21
+ digital_configuration:
22
+ compose: minilab_hardware, result_verifier
@@ -0,0 +1,30 @@
1
+ require 'constructor'
2
+
3
+ class AnalogIo #:nodoc:
4
+ constructor :minilab_hardware, :result_verifier
5
+
6
+ def read_analog(channel)
7
+ check_channel_range(channel, 0, 7)
8
+
9
+ result = @minilab_hardware.read_analog(channel)
10
+ @result_verifier.verify(result, "read_analog")
11
+
12
+ result[:value]
13
+ end
14
+
15
+ def write_analog(channel, volts)
16
+ check_channel_range(channel, 0, 1)
17
+
18
+ unless (0.0 .. 5.0) === volts
19
+ raise "#{volts} volts is out of range for this device; Only voltage between 0.0 and 5.0 is supported."
20
+ end
21
+
22
+ result = @minilab_hardware.write_analog(channel, volts)
23
+ @result_verifier.verify(result, "write_analog")
24
+ end
25
+
26
+ private
27
+ def check_channel_range(channel, low, high)
28
+ raise "Channel #{channel} is out of range." unless (low..high) === channel
29
+ end
30
+ end
@@ -0,0 +1,49 @@
1
+ require 'constructor'
2
+ require 'extension/minilab_hardware'
3
+
4
+ class DigitalAuxportIo #:nodoc:
5
+ constructor :minilab_hardware, :result_verifier
6
+ include MinilabConstants
7
+
8
+ VALID_PINS = ['DIO0', 'DIO1', 'DIO2', 'DIO3']
9
+
10
+ def read_digital(pin)
11
+ check_pin_valid(pin)
12
+ pin = get_pin_number(pin)
13
+
14
+ configuration = {:direction => DIGITALIN, :pin => pin}
15
+ result = @minilab_hardware.configure_auxport(configuration)
16
+ @result_verifier.verify(result, "configure_auxport_in")
17
+
18
+ result = @minilab_hardware.read_auxport(pin)
19
+ @result_verifier.verify(result, "read_auxport")
20
+
21
+ result[:value]
22
+ end
23
+
24
+ def write_digital(pin, value)
25
+ check_pin_valid(pin)
26
+ pin = get_pin_number(pin)
27
+
28
+ raise "#{value} is not a valid digital output." if (value < 0)
29
+ value = 1 if (value > 0)
30
+
31
+ configuration = { :direction => DIGITALOUT, :pin => pin }
32
+ result = @minilab_hardware.configure_auxport(configuration)
33
+ @result_verifier.verify(result, "configure_auxport_out")
34
+
35
+ result = @minilab_hardware.write_auxport(pin, value)
36
+ @result_verifier.verify(result, "write_auxport")
37
+ end
38
+
39
+ private
40
+ def check_pin_valid(pin)
41
+ if !VALID_PINS.include?(pin.to_s.upcase)
42
+ raise "#{pin} is not a valid digital IO pin"
43
+ end
44
+ end
45
+
46
+ def get_pin_number(pin)
47
+ pin.match(/(\d)$/)[0].to_i
48
+ end
49
+ end
@@ -0,0 +1,66 @@
1
+ require 'constructor'
2
+ require 'extension/minilab_hardware'
3
+
4
+ class DigitalConfiguration #:nodoc:
5
+ include MinilabConstants
6
+ constructor :minilab_hardware, :result_verifier
7
+
8
+ PORTS = [:porta, :portb, :portcl, :portch]
9
+ LIBRARY_PORT_NAMES = {
10
+ :porta => FIRSTPORTA,
11
+ :portb => FIRSTPORTB,
12
+ :portcl => FIRSTPORTCL,
13
+ :portch => FIRSTPORTCH
14
+ }
15
+
16
+ def setup
17
+ @port_status = {}
18
+ PORTS.each { |port| @port_status[port] = :not_configured }
19
+ end
20
+
21
+ def get_valid_ports
22
+ PORTS
23
+ end
24
+
25
+ def configure_port_for_input(port)
26
+ configure_port(port, DIGITALIN)
27
+ end
28
+
29
+ def configure_port_for_output(port)
30
+ configure_port(port, DIGITALOUT)
31
+ end
32
+
33
+ def is_port_configured_for_input?(port)
34
+ check_port_status(port, DIGITALIN)
35
+ end
36
+
37
+ def is_port_configured_for_output?(port)
38
+ check_port_status(port, DIGITALOUT)
39
+ end
40
+
41
+ private
42
+ def is_port_recognized?(port)
43
+ if get_valid_ports.include?(port)
44
+ true
45
+ else
46
+ raise "Port #{port} is not valid."
47
+ end
48
+ end
49
+
50
+ def configure_port(port, direction)
51
+ is_port_recognized?(port)
52
+
53
+ result = @minilab_hardware.configure_port(:direction => direction, :port => LIBRARY_PORT_NAMES[port])
54
+ @result_verifier.verify(result)
55
+
56
+ @port_status[port] = direction
57
+ true
58
+ end
59
+
60
+ def check_port_status(port, status)
61
+ is_port_recognized?(port)
62
+
63
+ return false unless @port_status[port] == status
64
+ true
65
+ end
66
+ end