agri-controller 0.0.0 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ChangeLog.txt +36 -0
- data/LICENSE.txt +15 -0
- data/agri-controller.gemspec +36 -0
- data/gpl-2.0.txt +339 -0
- data/lib/agri-controller.rb +11 -33
- data/lib/agri-controller/bcc.rb +86 -53
- data/lib/agri-controller/bit.rb +158 -143
- data/lib/agri-controller/device.rb +7 -0
- data/lib/agri-controller/device/dacs.rb +148 -0
- data/lib/agri-controller/device/kr.rb +23 -0
- data/lib/agri-controller/device/ma.rb +92 -0
- data/lib/agri-controller/device/mch383.rb +178 -0
- data/lib/agri-controller/device/tr.rb +230 -0
- data/lib/agri-controller/device/wr1010.rb +314 -0
- data/lib/agri-controller/dt.rb +17 -0
- data/lib/agri-controller/error_caption.rb +67 -46
- data/lib/agri-controller/gruff.rb +7 -0
- data/lib/agri-controller/gruff/base.rb +88 -0
- data/lib/agri-controller/gruff/chdata.rb +64 -0
- data/lib/agri-controller/gruff/join_csv.rb +62 -0
- data/lib/agri-controller/gruff/rename_csv.rb +50 -0
- data/lib/agri-controller/{thermo_data_each_day.rb → gruff/thermo_data_each_day.rb} +67 -67
- data/lib/agri-controller/{thermo_gruff.rb → gruff/thermo_gruff.rb} +112 -109
- data/lib/agri-controller/gruff/thermo_gruff2.rb +161 -0
- data/lib/agri-controller/{thermo_gruff_generate.rb → gruff/thermo_gruff_generate.rb} +28 -28
- data/lib/agri-controller/gruff/thermo_gruff_loop.rb +42 -0
- data/lib/agri-controller/loger.rb +91 -51
- data/lib/agri-controller/main.rb +0 -0
- data/lib/agri-controller/main_linux.rb +282 -0
- data/lib/agri-controller/main_new.rb +401 -401
- data/lib/agri-controller/multiple_pulse_timer.rb +190 -169
- data/lib/agri-controller/n_dan_thermo.rb +156 -154
- data/lib/agri-controller/save_threads.rb +181 -172
- data/lib/agri-controller/setting_io.rb +53 -53
- data/lib/agri-controller/ttyUSB_watchdog.rb +43 -0
- data/lib/agri-controller/value_controller.rb +209 -167
- data/lib/agri-controller/version.rb +7 -5
- data/lib/agri-controller/web.rb +39 -39
- data/lib/agri-controller/webrick_test.rb +51 -46
- data/lib/agri-controller/wet_sensor.rb +92 -0
- data/test/tc_bit.rb +14 -3
- data/test/tc_trigger.rb +27 -0
- data/test/ts_agri-controller.rb +10 -10
- metadata +62 -202
- data/bin/main.bat +0 -2
- data/bin/main.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
- data/bin/main.rb +0 -23
- data/bin/memo.txt +0 -4
- data/bin/server.bat +0 -1
- data/bin/server.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
- data/bin/server.rb +0 -4
- data/bin/set_config.rb +0 -47
- data/bin/usual.rb +0 -3
- data/bin//203R/203}/203/223/203h /203v/203/215/203/223/203v/203g.lnk +0 -0
- data/lib/agri-controller/dacs.rb +0 -114
- data/lib/agri-controller/dircopy.rb +0 -30
- data/lib/agri-controller/kr.rb +0 -34
- data/lib/agri-controller/kr_2.rb +0 -78
- data/lib/agri-controller/serial.rb +0 -114
- data/lib/agri-controller/thermo_gruff_loop.rb +0 -35
- data/lib/agri-controller/wetsensor.rb +0 -119
- data/lib/agri-controller/wr1010.rb +0 -316
- data/lib/agri-controller/wr1010_2.rb +0 -0
- data/lib/cgi-bin/auto01.cgi +0 -0
- data/lib/cgi-bin/auto02.cgi +0 -0
- data/lib/cgi-bin/change_step.cgi +0 -42
- data/lib/cgi-bin/config/change_step +0 -4
- data/lib/cgi-bin/config/house1 +0 -20
- data/lib/cgi-bin/config/house2 +0 -8
- data/lib/cgi-bin/config/kr01_readable.txt +0 -2
- data/lib/cgi-bin/config/kr02_readable.txt +0 -2
- data/lib/cgi-bin/config/kr1_bit.txt +0 -2
- data/lib/cgi-bin/config/kr2_bit.txt +0 -2
- data/lib/cgi-bin/config/last_bit.txt +0 -1
- data/lib/cgi-bin/config/last_thermo_data +0 -22
- data/lib/cgi-bin/config/last_thermo_time +0 -2
- data/lib/cgi-bin/config/manual_bool01.txt +0 -2
- data/lib/cgi-bin/config/manual_bool02.txt +0 -2
- data/lib/cgi-bin/config/reload_flag +0 -2
- data/lib/cgi-bin/config/run_check +0 -2
- data/lib/cgi-bin/config/thermo_define.yml +0 -4
- data/lib/cgi-bin/config/time_array +0 -10
- data/lib/cgi-bin/config/wait_time +0 -2
- data/lib/cgi-bin/config/wet0 +0 -3
- data/lib/cgi-bin/config/wet0_drain +0 -2
- data/lib/cgi-bin/config/wet1 +0 -3
- data/lib/cgi-bin/config/wet1_drain +0 -2
- data/lib/cgi-bin/config/wet_input.txt +0 -1
- data/lib/cgi-bin/curtain_h1.cgi +0 -43
- data/lib/cgi-bin/curtain_h1_setting.cgi +0 -43
- data/lib/cgi-bin/curtain_h2.cgi +0 -43
- data/lib/cgi-bin/curtain_h2_setting.cgi +0 -43
- data/lib/cgi-bin/dacs_port.cgi +0 -43
- data/lib/cgi-bin/delay_time_0.cgi +0 -43
- data/lib/cgi-bin/delay_time_1.cgi +0 -43
- data/lib/cgi-bin/error_clear.cgi +0 -0
- data/lib/cgi-bin/house1.cgi +0 -42
- data/lib/cgi-bin/house1a.cgi +0 -43
- data/lib/cgi-bin/house2.cgi +0 -42
- data/lib/cgi-bin/house2b.cgi +0 -43
- data/lib/cgi-bin/house_n_dan_thermo1.cgi +0 -43
- data/lib/cgi-bin/house_n_dan_thermo2.cgi +0 -0
- data/lib/cgi-bin/keitai.cgi +0 -25
- data/lib/cgi-bin/kr01.cgi +0 -0
- data/lib/cgi-bin/kr01_readable.txt.cgi +0 -42
- data/lib/cgi-bin/kr02.cgi +0 -0
- data/lib/cgi-bin/kr02_readable.txt.cgi +0 -42
- data/lib/cgi-bin/kr1_bit.txt.cgi +0 -42
- data/lib/cgi-bin/kr2_bit.txt.cgi +0 -42
- data/lib/cgi-bin/kr_log.cgi +0 -18
- data/lib/cgi-bin/last_bit.txt.cgi +0 -42
- data/lib/cgi-bin/last_thermo_data.cgi +0 -42
- data/lib/cgi-bin/last_thermo_time.cgi +0 -42
- data/lib/cgi-bin/log.cgi +0 -19
- data/lib/cgi-bin/log/errors.txt +0 -1
- data/lib/cgi-bin/log/errors_.txt +0 -93
- data/lib/cgi-bin/log/kr_command_log.txt +0 -240
- data/lib/cgi-bin/log/log.txt +0 -441
- data/lib/cgi-bin/log/old_log/log_.txt +0 -15
- data/lib/cgi-bin/log/thermo/2010-05-22_thermo.csv +0 -1438
- data/lib/cgi-bin/log/thermo/2010-06-12_thermo.csv +0 -3
- data/lib/cgi-bin/log/thermo/2010-06-13_thermo.csv +0 -2
- data/lib/cgi-bin/log/thermo/2010-06-16_thermo.csv +0 -85
- data/lib/cgi-bin/log/thermo/2010-06-17_thermo.csv +0 -285
- data/lib/cgi-bin/log/thermo_data.csv +0 -643
- data/lib/cgi-bin/log/thermo_graph_loop.txt +0 -1
- data/lib/cgi-bin/main.cgi +0 -98
- data/lib/cgi-bin/manual_bool01.txt.cgi +0 -42
- data/lib/cgi-bin/manual_bool02.txt.cgi +0 -42
- data/lib/cgi-bin/post_change_step.cgi +0 -44
- data/lib/cgi-bin/post_house1.cgi +0 -44
- data/lib/cgi-bin/post_house2.cgi +0 -44
- data/lib/cgi-bin/post_kr01.cgi +0 -0
- data/lib/cgi-bin/post_kr01_readable.txt.cgi +0 -44
- data/lib/cgi-bin/post_kr02.cgi +0 -0
- data/lib/cgi-bin/post_kr02_readable.txt.cgi +0 -44
- data/lib/cgi-bin/post_kr1_bit.txt.cgi +0 -44
- data/lib/cgi-bin/post_kr2_bit.txt.cgi +0 -44
- data/lib/cgi-bin/post_last_bit.txt.cgi +0 -44
- data/lib/cgi-bin/post_last_thermo_data.cgi +0 -44
- data/lib/cgi-bin/post_last_thermo_time.cgi +0 -44
- data/lib/cgi-bin/post_manual_bool01.txt.cgi +0 -44
- data/lib/cgi-bin/post_manual_bool02.txt.cgi +0 -44
- data/lib/cgi-bin/post_reload_flag.cgi +0 -44
- data/lib/cgi-bin/post_run_check.cgi +0 -44
- data/lib/cgi-bin/post_thermo_define.yml.cgi +0 -44
- data/lib/cgi-bin/post_time_array.cgi +0 -44
- data/lib/cgi-bin/post_wait_time.cgi +0 -44
- data/lib/cgi-bin/post_wet0.cgi +0 -44
- data/lib/cgi-bin/post_wet0_drain.cgi +0 -44
- data/lib/cgi-bin/post_wet1.cgi +0 -44
- data/lib/cgi-bin/post_wet1_drain.cgi +0 -44
- data/lib/cgi-bin/post_wet_input.txt.cgi +0 -44
- data/lib/cgi-bin/reload_flag.cgi +0 -42
- data/lib/cgi-bin/reset_.cgi +0 -0
- data/lib/cgi-bin/run_check.cgi +0 -42
- data/lib/cgi-bin/set.cgi +0 -33
- data/lib/cgi-bin/set_post_yml_each.rb +0 -72
- data/lib/cgi-bin/set_yml_cgi_each.rb +0 -0
- data/lib/cgi-bin/setting.cgi +0 -0
- data/lib/cgi-bin/setting.cgi.1 +0 -0
- data/lib/cgi-bin/setting_io.rb +0 -53
- data/lib/cgi-bin/thermo_data_graphs.cgi +0 -0
- data/lib/cgi-bin/thermo_data_list.cgi +0 -0
- data/lib/cgi-bin/thermo_define.yml.cgi +0 -42
- data/lib/cgi-bin/thermo_graph.cgi +0 -0
- data/lib/cgi-bin/time_array.cgi +0 -42
- data/lib/cgi-bin/wait_time.cgi +0 -42
- data/lib/cgi-bin/web.rb +0 -39
- data/lib/cgi-bin/wet0.cgi +0 -42
- data/lib/cgi-bin/wet0_drain.cgi +0 -42
- data/lib/cgi-bin/wet1.cgi +0 -42
- data/lib/cgi-bin/wet1_drain.cgi +0 -42
- data/lib/cgi-bin/wet_input.txt.cgi +0 -42
- data/lib/htdocs/css/str.css +0 -89
- data/lib/htdocs/favicon.ico +0 -0
- data/lib/htdocs/thermo/thermo_data.jpg +0 -0
- data/lib/htdocs/thermo/thumb/thermo_data.jpg +0 -0
- data/test/tc_bit.rb.1 +0 -15
- data/test/tc_bit.rb.2 +0 -21
- data/test/ts_agri-controller.rb.1 +0 -8
data/lib/agri-controller/bcc.rb
CHANGED
@@ -1,53 +1,86 @@
|
|
1
|
-
module AgriController
|
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
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
AgriController
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
module AgriController
|
2
|
+
##
|
3
|
+
#module Bcc is simple bcc check SUM
|
4
|
+
#
|
5
|
+
#=== example
|
6
|
+
#
|
7
|
+
# require "rubygems"
|
8
|
+
# require "agri-controller"
|
9
|
+
# include AgriController
|
10
|
+
#
|
11
|
+
# Bcc::bcc(str) # =>Bcc_String
|
12
|
+
# Bcc::bcc("%01#RCSX0000") # => "1d"
|
13
|
+
#
|
14
|
+
# Bcc::bcc?("%01#RCSX00001d\r") # => true
|
15
|
+
# Bcc::bcc?("%01#RCSX0000FF\r") # => false
|
16
|
+
# Bcc::bcc?("%01#RCSX0000","1d\r") # => true
|
17
|
+
# Bcc::bcc?("%01#RCSX0000","1d") # => true
|
18
|
+
# Bcc::bcc?("error_str","error") # => nil
|
19
|
+
module Bcc
|
20
|
+
module_function
|
21
|
+
#_xor(6,2) # =>4
|
22
|
+
def _xor(x,y)
|
23
|
+
x.ord ^ y.ord
|
24
|
+
end
|
25
|
+
|
26
|
+
#xor check SUM
|
27
|
+
def bcc(str)
|
28
|
+
x=str[0]
|
29
|
+
(str.size-1).times do |i|
|
30
|
+
x=x.ord ^ str[i+1].ord
|
31
|
+
end
|
32
|
+
#p x
|
33
|
+
res=x.to_s(16).upcase
|
34
|
+
res="0"+res if res.size==1
|
35
|
+
p res
|
36
|
+
return res
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
#Bcc::bcc?
|
41
|
+
#
|
42
|
+
#=== example
|
43
|
+
#
|
44
|
+
# require "agri-controller"
|
45
|
+
# include AgriController
|
46
|
+
#
|
47
|
+
# str1="%01#RCSX0000"+"1d\r"
|
48
|
+
# bad_bcc="%01#RCSX0000"+"00\r"
|
49
|
+
# str2="%01#RCSX0000"
|
50
|
+
# Bcc::bcc?(str1) # =>true
|
51
|
+
# Bcc::bcc?(bad_bcc) # =>false
|
52
|
+
# Bcc::bcc?(str2,"1D") # =>true
|
53
|
+
# Bcc::bcc?(str2,"1d\r")# =>true
|
54
|
+
def bcc?(str,bcc_char=nil)
|
55
|
+
#on Error returns nil...
|
56
|
+
begin
|
57
|
+
str2=str.chomp.upcase
|
58
|
+
unless bcc_char && str2.size>2
|
59
|
+
bcc_char=str2[-2..-1]
|
60
|
+
str2=str2[0..-3]
|
61
|
+
else
|
62
|
+
bcc_char=bcc_char.chomp.upcase
|
63
|
+
end
|
64
|
+
return bcc_char==bcc(str2)
|
65
|
+
rescue
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if $0==__FILE__
|
73
|
+
require "bit"
|
74
|
+
require "profile"
|
75
|
+
str="%01#RCSX0000"
|
76
|
+
include AgriController
|
77
|
+
p AgriController::Bcc::bcc(str)
|
78
|
+
str1="%01#RCSX0000"+"1d\r"
|
79
|
+
str2="%01#RCSX0000"
|
80
|
+
p Bcc::bcc?(str1)==true
|
81
|
+
p Bcc::bcc?(str2,"1D")==true
|
82
|
+
p Bcc::bcc?(str2,"1d\r")==true
|
83
|
+
1000.times do
|
84
|
+
Bcc::_xor(rand(256),rand(256))
|
85
|
+
end
|
86
|
+
end
|
data/lib/agri-controller/bit.rb
CHANGED
@@ -1,143 +1,158 @@
|
|
1
|
-
##
|
2
|
-
#class Bit
|
3
|
-
# is simple bit culcurater.
|
4
|
-
# if on or off
|
5
|
-
# on(bit) # => on bit
|
6
|
-
# on(1) # =>2 (if @bit==0)
|
7
|
-
# on(1) # =>3 (if @bit==1)
|
8
|
-
# on(1) # =>7 (if @bit==5)
|
9
|
-
# bit_on(bit) # => on bit
|
10
|
-
#
|
11
|
-
# off(1) # =>0 (if @bit==2)
|
12
|
-
# off(1) # =>1 (if @bit==3)
|
13
|
-
# off(1) # =>5 (if @bit==7)
|
14
|
-
# bit_off(bit)# => off bit
|
15
|
-
#
|
16
|
-
# if check_bit
|
17
|
-
# on?(bit)# =>true or false
|
18
|
-
# off?(bit)# =>true or false
|
19
|
-
#
|
20
|
-
# boolbit(true,bit) # ==on(bit)
|
21
|
-
# boolbit(false,bit)# ==off(bit)
|
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
|
-
def
|
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
|
-
a.
|
120
|
-
p
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
p
|
132
|
-
|
133
|
-
|
134
|
-
p
|
135
|
-
p
|
136
|
-
p
|
137
|
-
p
|
138
|
-
p
|
139
|
-
p
|
140
|
-
p
|
141
|
-
p
|
142
|
-
|
143
|
-
|
1
|
+
##
|
2
|
+
#class Bit
|
3
|
+
# is simple bit culcurater.
|
4
|
+
# if on or off
|
5
|
+
# on(bit) # => on bit
|
6
|
+
# on(1) # =>2 (if @bit==0)
|
7
|
+
# on(1) # =>3 (if @bit==1)
|
8
|
+
# on(1) # =>7 (if @bit==5)
|
9
|
+
# bit_on(bit) # => on bit
|
10
|
+
#
|
11
|
+
# off(1) # =>0 (if @bit==2)
|
12
|
+
# off(1) # =>1 (if @bit==3)
|
13
|
+
# off(1) # =>5 (if @bit==7)
|
14
|
+
# bit_off(bit)# => off bit
|
15
|
+
#
|
16
|
+
# if check_bit
|
17
|
+
# on?(bit)# =>true or false
|
18
|
+
# off?(bit)# =>true or false
|
19
|
+
#
|
20
|
+
# boolbit(true,bit) # ==on(bit)
|
21
|
+
# boolbit(false,bit)# ==off(bit)
|
22
|
+
#
|
23
|
+
# blink(bit) #=> !bit (change true<=>false)
|
24
|
+
module AgriController
|
25
|
+
class Bit
|
26
|
+
attr_accessor:bit
|
27
|
+
def initialize(bit=0)
|
28
|
+
@bit=bit
|
29
|
+
end
|
30
|
+
|
31
|
+
def boolbit(bool,bit)
|
32
|
+
if bool
|
33
|
+
bit_on(bit)
|
34
|
+
else
|
35
|
+
bit_off(bit)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def blink(i)
|
40
|
+
boolbit(!on?(i),i)
|
41
|
+
end
|
42
|
+
|
43
|
+
def bit_on(bit)
|
44
|
+
unless on?(bit)
|
45
|
+
@bit+= 2**bit
|
46
|
+
end
|
47
|
+
@bit
|
48
|
+
end
|
49
|
+
|
50
|
+
def tos(int=6,bit_num=16)
|
51
|
+
x=@bit.to_s(bit_num)
|
52
|
+
|
53
|
+
# 17.tos(1,16) # => "1"
|
54
|
+
# 17.tos(2,16) # => "11"
|
55
|
+
(int-x.size).times do
|
56
|
+
x="0"+x
|
57
|
+
end
|
58
|
+
|
59
|
+
if x.size > int
|
60
|
+
x=x.slice(x.size-int,int)
|
61
|
+
end
|
62
|
+
|
63
|
+
return x.upcase
|
64
|
+
end
|
65
|
+
|
66
|
+
def bit_off(bit)
|
67
|
+
if on?(bit)
|
68
|
+
@bit=@bit - 2**bit
|
69
|
+
end
|
70
|
+
@bit
|
71
|
+
end
|
72
|
+
|
73
|
+
def on?(bit)
|
74
|
+
str=tos(24,2)
|
75
|
+
case str.slice(-1-bit,1)
|
76
|
+
when "1"
|
77
|
+
true
|
78
|
+
when "0"
|
79
|
+
false
|
80
|
+
else
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
def off?(bit)
|
85
|
+
not(on?(bit))
|
86
|
+
end
|
87
|
+
def help
|
88
|
+
"##
|
89
|
+
#class Bit
|
90
|
+
# is simple bit culcurater.
|
91
|
+
# if on or off
|
92
|
+
# on(bit) # => on bit
|
93
|
+
# on(1) # =>2 (if @bit==0)
|
94
|
+
# on(1) # =>3 (if @bit==1)
|
95
|
+
# on(1) # =>7 (if @bit==5)
|
96
|
+
# bit_on(bit) # => on bit
|
97
|
+
#
|
98
|
+
# off(1) # =>0 (if @bit==2)
|
99
|
+
# off(1) # =>1 (if @bit==3)
|
100
|
+
# off(1) # =>5 (if @bit==7)
|
101
|
+
# bit_off(bit)# => off bit
|
102
|
+
#
|
103
|
+
# if check_bit
|
104
|
+
# on?(bit)# =>true or false
|
105
|
+
# off?(bit)# =>true or false
|
106
|
+
#
|
107
|
+
# boolbit(true,bit) # ==on(bit)
|
108
|
+
# boolbit(false,bit)# ==off(bit)
|
109
|
+
#
|
110
|
+
"
|
111
|
+
end
|
112
|
+
alias on bit_on
|
113
|
+
alias off bit_off
|
114
|
+
end
|
115
|
+
end
|
116
|
+
if $0==__FILE__
|
117
|
+
#require "profile"
|
118
|
+
#Test of class Bit
|
119
|
+
a=AgriController::Bit.new
|
120
|
+
p a
|
121
|
+
a.bit_on(1)
|
122
|
+
a.bit_on(0)
|
123
|
+
a.bit_on(23)
|
124
|
+
|
125
|
+
1000.times do
|
126
|
+
a.bit_on(1)
|
127
|
+
end
|
128
|
+
a.bit_on(3)
|
129
|
+
a.bit_off(1)
|
130
|
+
a.bit_off(1)
|
131
|
+
p x=a.bit
|
132
|
+
p x.to_s(16)
|
133
|
+
a.bit_off(4)
|
134
|
+
p x.to_s(2)
|
135
|
+
p a.off?(3)
|
136
|
+
p a.off?(2)
|
137
|
+
p a.off?(1)
|
138
|
+
p a.off?(0)
|
139
|
+
p a.on?(3)
|
140
|
+
p a.on?(2)
|
141
|
+
p a.on?(1)
|
142
|
+
p a.on?(0)
|
143
|
+
p a
|
144
|
+
p b=AgriController::Bit.new(11)
|
145
|
+
p b.bit.to_s(2)
|
146
|
+
print b.help
|
147
|
+
c=AgriController::Bit.new(8388621)
|
148
|
+
p c
|
149
|
+
p c.tos
|
150
|
+
p c.boolbit(true,4)
|
151
|
+
p c.tos
|
152
|
+
p c.boolbit(false,4)
|
153
|
+
p c.tos
|
154
|
+
p c.on(4)
|
155
|
+
p c.bit
|
156
|
+
p c.blink(24)
|
157
|
+
p c.blink(24)
|
158
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#require "serial"
|
2
|
+
#require "Win32API" #for windows.
|
3
|
+
|
4
|
+
module AgriController
|
5
|
+
module_function
|
6
|
+
##
|
7
|
+
#use Dacs_32bit_I/O_photoMOS_reray on usb_serial_port (win,linux compatible)
|
8
|
+
#*Usage
|
9
|
+
# requrie "agri-controll"
|
10
|
+
# include AgriController
|
11
|
+
# include Dacs # also use Dacs::
|
12
|
+
#
|
13
|
+
#==Windows
|
14
|
+
#export is a simple IO_command send(set),and recieve(import)
|
15
|
+
#search com_port(3-19) and communicate
|
16
|
+
#export("ffffff")# =>"R0FFFFFF&"
|
17
|
+
#
|
18
|
+
#com_port number recommended
|
19
|
+
#com_port=6 #(see system infomation)
|
20
|
+
# export("ffffff",com_port,0)#return =>"R0FFFFFF&"
|
21
|
+
# export("000000",com_port,0)#return =>"R0FFFFFF&"
|
22
|
+
# export("R",com_port,1) #return =>"R883DFFF&"
|
23
|
+
# export("R",com_port) #return =>"R0FFFFFF&"
|
24
|
+
#
|
25
|
+
#hex_6
|
26
|
+
#ex. # =>"FBD017","ffffff"
|
27
|
+
#recieve only.# =>"R"
|
28
|
+
#
|
29
|
+
############################################################
|
30
|
+
#==Linux
|
31
|
+
# include dacs
|
32
|
+
# export("W0FFFFFF\r","ttyUsb0")
|
33
|
+
# import("R0R\r")
|
34
|
+
#
|
35
|
+
module Dacs
|
36
|
+
module_function
|
37
|
+
|
38
|
+
if RUBY_PLATFORM.include?("mswin")
|
39
|
+
def export(hex_6,com_port=port?,io_port=0,dip=0)
|
40
|
+
#hex_6
|
41
|
+
#ex. # =>"FBD017","ffffff"
|
42
|
+
#recieve only.# =>"R"
|
43
|
+
|
44
|
+
case io_port
|
45
|
+
#io_port must be io_port*8+dip_switch(on board)
|
46
|
+
when 1
|
47
|
+
io_port=8*io_port+dip#2nd word
|
48
|
+
else#io_port should be 0
|
49
|
+
io_port=dip#2nd word
|
50
|
+
end
|
51
|
+
a=Serial.new
|
52
|
+
#search COM port 3-9
|
53
|
+
if a.open(com_port,0,57600,8,0,0,4096,4096)!=-1
|
54
|
+
command="W#{(io_port).to_s}#{hex_6}\r"
|
55
|
+
|
56
|
+
yield command if block_given?
|
57
|
+
#p command
|
58
|
+
a.send(command)
|
59
|
+
sleep 0.04
|
60
|
+
receive=a.receive
|
61
|
+
a.close
|
62
|
+
return receive
|
63
|
+
else
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
#search ports COM3-19
|
71
|
+
#if sucsess return int(port number)
|
72
|
+
#else return nil.
|
73
|
+
def port?(x=3)
|
74
|
+
a=Serial.new
|
75
|
+
#search COM port 3-19
|
76
|
+
bool=false#serch flag
|
77
|
+
|
78
|
+
while bool==false
|
79
|
+
x+=1
|
80
|
+
if x > 20
|
81
|
+
return nil
|
82
|
+
end
|
83
|
+
|
84
|
+
if a.open(x,0,57600,8,0,0,108,324) == -1
|
85
|
+
if x > 20
|
86
|
+
return nil
|
87
|
+
end
|
88
|
+
else
|
89
|
+
a.send("W0R\r")
|
90
|
+
sleep 0.1
|
91
|
+
receive=a.receive#should_be "R0xxxxxx\r",x=hex
|
92
|
+
#p receive.split(//).last
|
93
|
+
#p x
|
94
|
+
#p receive
|
95
|
+
if receive
|
96
|
+
if receive.split(//).last=="\r"
|
97
|
+
if receive.split(//).first=="R"
|
98
|
+
bool=true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
a.close
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
return x
|
107
|
+
end
|
108
|
+
|
109
|
+
def import(com_port=port?,io_port=0,dip=0)
|
110
|
+
export("R",com_port,io_port,dip)
|
111
|
+
end
|
112
|
+
|
113
|
+
def import_bit(com_port=port?,io_port=0,dip=0)
|
114
|
+
|
115
|
+
port_bit=import(com_port=port?,io_port,dip)
|
116
|
+
if port_bit
|
117
|
+
import_bits=port_bit.slice(2,6).to_i(16)
|
118
|
+
else
|
119
|
+
import_bits=0
|
120
|
+
end
|
121
|
+
return import_bits
|
122
|
+
end
|
123
|
+
else#should be Linux
|
124
|
+
def export(command,device)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def toi(res)
|
129
|
+
begin
|
130
|
+
bit=res.slice(2,6).to_i(16)
|
131
|
+
return bit
|
132
|
+
rescue
|
133
|
+
nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def sample
|
138
|
+
"W0FFFFFF\r"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
if $0==__FILE__
|
144
|
+
include AgriController::Dacs
|
145
|
+
p port?
|
146
|
+
p x=export("FFFFFF",5)
|
147
|
+
#p x.to_s(16)
|
148
|
+
end
|