summaryrefslogtreecommitdiffstats
path: root/ruby/ffi-k8055/spec/k8055_spec.rb
blob: 310f9b65bf5c48224fa442dfeabed32442aed1ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
require 'k8055'
#
describe K8055 do
    #
    it "version should work" do
        K8055::K8055.version.should == K8055.version
    end
    #
    it "search_devices should find one" do
        K8055.search_devices.should > 0
    end
    #
    describe K8055 do
        #
        before(:all) { 
            @k = K8055::K8055.new
            @k.open_device 0
        }
        after(:all) {
            @k.close_device
            @k.free
        }
        #
        it "analog output 1" do
            @k.k8055_set_analog_channel 1
            @k.k8055_analog_output_1.should == 255
            @k.k8055_write_analog_channel 1, 10
            @k.k8055_analog_output_1.should == 10
            @k.k8055_write_analog_channel 1, 250
            @k.k8055_analog_output_1.should == 250
            @k.k8055_clear_analog_channel 1
            @k.k8055_analog_output_1.should == 0
            @k.set_analog_channel 1
            @k.analog_output_1.should == 255
            @k.write_analog_channel 1, 10
            @k.analog_output_1.should == 10
            @k.write_analog_channel 1, 250
            @k.analog_output_1.should == 250
            @k.clear_analog_channel 1
            @k.analog_output_1.should == 0
        end
        it "analog output 2" do
            @k.k8055_set_analog_channel 2
            @k.k8055_analog_output_2.should == 255
            @k.k8055_write_analog_channel 2, 10
            @k.k8055_analog_output_2.should == 10
            @k.k8055_write_analog_channel 2, 250
            @k.k8055_analog_output_2.should == 250
            @k.k8055_clear_analog_channel 2
            @k.k8055_analog_output_2.should == 0
            @k.set_analog_channel 2
            @k.analog_output_2.should == 255
            @k.write_analog_channel 2, 10
            @k.analog_output_2.should == 10
            @k.write_analog_channel 2, 250
            @k.analog_output_2.should == 250
            @k.clear_analog_channel 2
            @k.analog_output_2.should == 0
        end
        #
        it "digital output 1" do
            @k.set_all_digital
            @k.digital_output_1.should == 1
            @k.clear_digital_channel 1
            @k.digital_output_1.should == 0
            @k.set_digital_channel 1
            @k.digital_output_1.should == 1
            @k.clear_all_digital
            @k.digital_output_1.should == 0
        end
        #
        it "digital output 2" do
            @k.set_all_digital
            @k.digital_output_2.should == 1
            @k.clear_digital_channel 2
            @k.digital_output_2.should == 0
            @k.set_digital_channel 2
            @k.digital_output_2.should == 1
            @k.clear_all_digital
            @k.digital_output_2.should == 0
        end
        #
        it "digital output 3" do
            @k.set_all_digital
            @k.digital_output_3.should == 1
            @k.clear_digital_channel 3
            @k.digital_output_3.should == 0
            @k.set_digital_channel 3
            @k.digital_output_3.should == 1
            @k.clear_all_digital
            @k.digital_output_3.should == 0
        end
        #
        it "digital output 4" do
            @k.set_all_digital
            @k.digital_output_4.should == 1
            @k.clear_digital_channel 4
            @k.digital_output_4.should == 0
            @k.set_digital_channel 4
            @k.digital_output_4.should == 1
            @k.clear_all_digital
            @k.digital_output_4.should == 0
        end
        #
        it "digital output 5" do
            @k.set_all_digital
            @k.digital_output_5.should == 1
            @k.clear_digital_channel 5
            @k.digital_output_5.should == 0
            @k.set_digital_channel 5
            @k.digital_output_5.should == 1
            @k.clear_all_digital
            @k.digital_output_5.should == 0
        end
        #
        it "outputs test loop" do
            @k.set_all_digital
            @k.set_all_analog
            @k.digital_outputs.should == 255
            @k.digital_output_1.should == 1
            @k.digital_output_2.should == 1
            @k.digital_output_3.should == 1
            @k.digital_output_4.should == 1
            @k.digital_output_5.should == 1
            @k.analog_output_1.should == 255
            @k.analog_output_2.should == 255
            (0..255).each do |n|
                @k.write_all_digital n
                @k.write_all_analog n, n
                @k.digital_outputs.should == n
            end
            @k.clear_all_digital
            @k.clear_all_analog
            @k.digital_outputs.should == 0
            @k.digital_output_1.should == 0
            @k.digital_output_2.should == 0
            @k.digital_output_3.should == 0
            @k.digital_output_4.should == 0
            @k.digital_output_5.should == 0
            @k.analog_output_1.should == 0
            @k.analog_output_2.should == 0
        end
    end
end