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.
Files changed (182) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog.txt +36 -0
  3. data/LICENSE.txt +15 -0
  4. data/agri-controller.gemspec +36 -0
  5. data/gpl-2.0.txt +339 -0
  6. data/lib/agri-controller.rb +11 -33
  7. data/lib/agri-controller/bcc.rb +86 -53
  8. data/lib/agri-controller/bit.rb +158 -143
  9. data/lib/agri-controller/device.rb +7 -0
  10. data/lib/agri-controller/device/dacs.rb +148 -0
  11. data/lib/agri-controller/device/kr.rb +23 -0
  12. data/lib/agri-controller/device/ma.rb +92 -0
  13. data/lib/agri-controller/device/mch383.rb +178 -0
  14. data/lib/agri-controller/device/tr.rb +230 -0
  15. data/lib/agri-controller/device/wr1010.rb +314 -0
  16. data/lib/agri-controller/dt.rb +17 -0
  17. data/lib/agri-controller/error_caption.rb +67 -46
  18. data/lib/agri-controller/gruff.rb +7 -0
  19. data/lib/agri-controller/gruff/base.rb +88 -0
  20. data/lib/agri-controller/gruff/chdata.rb +64 -0
  21. data/lib/agri-controller/gruff/join_csv.rb +62 -0
  22. data/lib/agri-controller/gruff/rename_csv.rb +50 -0
  23. data/lib/agri-controller/{thermo_data_each_day.rb → gruff/thermo_data_each_day.rb} +67 -67
  24. data/lib/agri-controller/{thermo_gruff.rb → gruff/thermo_gruff.rb} +112 -109
  25. data/lib/agri-controller/gruff/thermo_gruff2.rb +161 -0
  26. data/lib/agri-controller/{thermo_gruff_generate.rb → gruff/thermo_gruff_generate.rb} +28 -28
  27. data/lib/agri-controller/gruff/thermo_gruff_loop.rb +42 -0
  28. data/lib/agri-controller/loger.rb +91 -51
  29. data/lib/agri-controller/main.rb +0 -0
  30. data/lib/agri-controller/main_linux.rb +282 -0
  31. data/lib/agri-controller/main_new.rb +401 -401
  32. data/lib/agri-controller/multiple_pulse_timer.rb +190 -169
  33. data/lib/agri-controller/n_dan_thermo.rb +156 -154
  34. data/lib/agri-controller/save_threads.rb +181 -172
  35. data/lib/agri-controller/setting_io.rb +53 -53
  36. data/lib/agri-controller/ttyUSB_watchdog.rb +43 -0
  37. data/lib/agri-controller/value_controller.rb +209 -167
  38. data/lib/agri-controller/version.rb +7 -5
  39. data/lib/agri-controller/web.rb +39 -39
  40. data/lib/agri-controller/webrick_test.rb +51 -46
  41. data/lib/agri-controller/wet_sensor.rb +92 -0
  42. data/test/tc_bit.rb +14 -3
  43. data/test/tc_trigger.rb +27 -0
  44. data/test/ts_agri-controller.rb +10 -10
  45. metadata +62 -202
  46. data/bin/main.bat +0 -2
  47. data/bin/main.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
  48. data/bin/main.rb +0 -23
  49. data/bin/memo.txt +0 -4
  50. data/bin/server.bat +0 -1
  51. data/bin/server.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
  52. data/bin/server.rb +0 -4
  53. data/bin/set_config.rb +0 -47
  54. data/bin/usual.rb +0 -3
  55. data/bin//203R/203}/203/223/203h /203v/203/215/203/223/203v/203g.lnk +0 -0
  56. data/lib/agri-controller/dacs.rb +0 -114
  57. data/lib/agri-controller/dircopy.rb +0 -30
  58. data/lib/agri-controller/kr.rb +0 -34
  59. data/lib/agri-controller/kr_2.rb +0 -78
  60. data/lib/agri-controller/serial.rb +0 -114
  61. data/lib/agri-controller/thermo_gruff_loop.rb +0 -35
  62. data/lib/agri-controller/wetsensor.rb +0 -119
  63. data/lib/agri-controller/wr1010.rb +0 -316
  64. data/lib/agri-controller/wr1010_2.rb +0 -0
  65. data/lib/cgi-bin/auto01.cgi +0 -0
  66. data/lib/cgi-bin/auto02.cgi +0 -0
  67. data/lib/cgi-bin/change_step.cgi +0 -42
  68. data/lib/cgi-bin/config/change_step +0 -4
  69. data/lib/cgi-bin/config/house1 +0 -20
  70. data/lib/cgi-bin/config/house2 +0 -8
  71. data/lib/cgi-bin/config/kr01_readable.txt +0 -2
  72. data/lib/cgi-bin/config/kr02_readable.txt +0 -2
  73. data/lib/cgi-bin/config/kr1_bit.txt +0 -2
  74. data/lib/cgi-bin/config/kr2_bit.txt +0 -2
  75. data/lib/cgi-bin/config/last_bit.txt +0 -1
  76. data/lib/cgi-bin/config/last_thermo_data +0 -22
  77. data/lib/cgi-bin/config/last_thermo_time +0 -2
  78. data/lib/cgi-bin/config/manual_bool01.txt +0 -2
  79. data/lib/cgi-bin/config/manual_bool02.txt +0 -2
  80. data/lib/cgi-bin/config/reload_flag +0 -2
  81. data/lib/cgi-bin/config/run_check +0 -2
  82. data/lib/cgi-bin/config/thermo_define.yml +0 -4
  83. data/lib/cgi-bin/config/time_array +0 -10
  84. data/lib/cgi-bin/config/wait_time +0 -2
  85. data/lib/cgi-bin/config/wet0 +0 -3
  86. data/lib/cgi-bin/config/wet0_drain +0 -2
  87. data/lib/cgi-bin/config/wet1 +0 -3
  88. data/lib/cgi-bin/config/wet1_drain +0 -2
  89. data/lib/cgi-bin/config/wet_input.txt +0 -1
  90. data/lib/cgi-bin/curtain_h1.cgi +0 -43
  91. data/lib/cgi-bin/curtain_h1_setting.cgi +0 -43
  92. data/lib/cgi-bin/curtain_h2.cgi +0 -43
  93. data/lib/cgi-bin/curtain_h2_setting.cgi +0 -43
  94. data/lib/cgi-bin/dacs_port.cgi +0 -43
  95. data/lib/cgi-bin/delay_time_0.cgi +0 -43
  96. data/lib/cgi-bin/delay_time_1.cgi +0 -43
  97. data/lib/cgi-bin/error_clear.cgi +0 -0
  98. data/lib/cgi-bin/house1.cgi +0 -42
  99. data/lib/cgi-bin/house1a.cgi +0 -43
  100. data/lib/cgi-bin/house2.cgi +0 -42
  101. data/lib/cgi-bin/house2b.cgi +0 -43
  102. data/lib/cgi-bin/house_n_dan_thermo1.cgi +0 -43
  103. data/lib/cgi-bin/house_n_dan_thermo2.cgi +0 -0
  104. data/lib/cgi-bin/keitai.cgi +0 -25
  105. data/lib/cgi-bin/kr01.cgi +0 -0
  106. data/lib/cgi-bin/kr01_readable.txt.cgi +0 -42
  107. data/lib/cgi-bin/kr02.cgi +0 -0
  108. data/lib/cgi-bin/kr02_readable.txt.cgi +0 -42
  109. data/lib/cgi-bin/kr1_bit.txt.cgi +0 -42
  110. data/lib/cgi-bin/kr2_bit.txt.cgi +0 -42
  111. data/lib/cgi-bin/kr_log.cgi +0 -18
  112. data/lib/cgi-bin/last_bit.txt.cgi +0 -42
  113. data/lib/cgi-bin/last_thermo_data.cgi +0 -42
  114. data/lib/cgi-bin/last_thermo_time.cgi +0 -42
  115. data/lib/cgi-bin/log.cgi +0 -19
  116. data/lib/cgi-bin/log/errors.txt +0 -1
  117. data/lib/cgi-bin/log/errors_.txt +0 -93
  118. data/lib/cgi-bin/log/kr_command_log.txt +0 -240
  119. data/lib/cgi-bin/log/log.txt +0 -441
  120. data/lib/cgi-bin/log/old_log/log_.txt +0 -15
  121. data/lib/cgi-bin/log/thermo/2010-05-22_thermo.csv +0 -1438
  122. data/lib/cgi-bin/log/thermo/2010-06-12_thermo.csv +0 -3
  123. data/lib/cgi-bin/log/thermo/2010-06-13_thermo.csv +0 -2
  124. data/lib/cgi-bin/log/thermo/2010-06-16_thermo.csv +0 -85
  125. data/lib/cgi-bin/log/thermo/2010-06-17_thermo.csv +0 -285
  126. data/lib/cgi-bin/log/thermo_data.csv +0 -643
  127. data/lib/cgi-bin/log/thermo_graph_loop.txt +0 -1
  128. data/lib/cgi-bin/main.cgi +0 -98
  129. data/lib/cgi-bin/manual_bool01.txt.cgi +0 -42
  130. data/lib/cgi-bin/manual_bool02.txt.cgi +0 -42
  131. data/lib/cgi-bin/post_change_step.cgi +0 -44
  132. data/lib/cgi-bin/post_house1.cgi +0 -44
  133. data/lib/cgi-bin/post_house2.cgi +0 -44
  134. data/lib/cgi-bin/post_kr01.cgi +0 -0
  135. data/lib/cgi-bin/post_kr01_readable.txt.cgi +0 -44
  136. data/lib/cgi-bin/post_kr02.cgi +0 -0
  137. data/lib/cgi-bin/post_kr02_readable.txt.cgi +0 -44
  138. data/lib/cgi-bin/post_kr1_bit.txt.cgi +0 -44
  139. data/lib/cgi-bin/post_kr2_bit.txt.cgi +0 -44
  140. data/lib/cgi-bin/post_last_bit.txt.cgi +0 -44
  141. data/lib/cgi-bin/post_last_thermo_data.cgi +0 -44
  142. data/lib/cgi-bin/post_last_thermo_time.cgi +0 -44
  143. data/lib/cgi-bin/post_manual_bool01.txt.cgi +0 -44
  144. data/lib/cgi-bin/post_manual_bool02.txt.cgi +0 -44
  145. data/lib/cgi-bin/post_reload_flag.cgi +0 -44
  146. data/lib/cgi-bin/post_run_check.cgi +0 -44
  147. data/lib/cgi-bin/post_thermo_define.yml.cgi +0 -44
  148. data/lib/cgi-bin/post_time_array.cgi +0 -44
  149. data/lib/cgi-bin/post_wait_time.cgi +0 -44
  150. data/lib/cgi-bin/post_wet0.cgi +0 -44
  151. data/lib/cgi-bin/post_wet0_drain.cgi +0 -44
  152. data/lib/cgi-bin/post_wet1.cgi +0 -44
  153. data/lib/cgi-bin/post_wet1_drain.cgi +0 -44
  154. data/lib/cgi-bin/post_wet_input.txt.cgi +0 -44
  155. data/lib/cgi-bin/reload_flag.cgi +0 -42
  156. data/lib/cgi-bin/reset_.cgi +0 -0
  157. data/lib/cgi-bin/run_check.cgi +0 -42
  158. data/lib/cgi-bin/set.cgi +0 -33
  159. data/lib/cgi-bin/set_post_yml_each.rb +0 -72
  160. data/lib/cgi-bin/set_yml_cgi_each.rb +0 -0
  161. data/lib/cgi-bin/setting.cgi +0 -0
  162. data/lib/cgi-bin/setting.cgi.1 +0 -0
  163. data/lib/cgi-bin/setting_io.rb +0 -53
  164. data/lib/cgi-bin/thermo_data_graphs.cgi +0 -0
  165. data/lib/cgi-bin/thermo_data_list.cgi +0 -0
  166. data/lib/cgi-bin/thermo_define.yml.cgi +0 -42
  167. data/lib/cgi-bin/thermo_graph.cgi +0 -0
  168. data/lib/cgi-bin/time_array.cgi +0 -42
  169. data/lib/cgi-bin/wait_time.cgi +0 -42
  170. data/lib/cgi-bin/web.rb +0 -39
  171. data/lib/cgi-bin/wet0.cgi +0 -42
  172. data/lib/cgi-bin/wet0_drain.cgi +0 -42
  173. data/lib/cgi-bin/wet1.cgi +0 -42
  174. data/lib/cgi-bin/wet1_drain.cgi +0 -42
  175. data/lib/cgi-bin/wet_input.txt.cgi +0 -42
  176. data/lib/htdocs/css/str.css +0 -89
  177. data/lib/htdocs/favicon.ico +0 -0
  178. data/lib/htdocs/thermo/thermo_data.jpg +0 -0
  179. data/lib/htdocs/thermo/thumb/thermo_data.jpg +0 -0
  180. data/test/tc_bit.rb.1 +0 -15
  181. data/test/tc_bit.rb.2 +0 -21
  182. data/test/ts_agri-controller.rb.1 +0 -8
@@ -1,53 +1,86 @@
1
- module AgriController
2
- module Bcc
3
- module_function
4
- def _xor(x,y)
5
- x1=Bit.new(x.ord)
6
- y1=Bit.new(y.ord)
7
- #p x1.tos(8,2)
8
- #p y1.tos(8,2)
9
- (0..7).each do |i|
10
- x1.boolbit(!(((x1.on?(i) && y1.on?(i))or x1.off?(i) && y1.off?(i))),i)
11
- end
12
- #p ret=x1.tos(8,2)
13
-
14
- x1.bit
15
-
16
- end
17
-
18
- #xor check SUM
19
- def bcc(str)
20
- x=str[0]
21
- (str.size-1).times do |i|
22
- x=_xor(x,str[i+1])
23
- end
24
- #p x
25
- ret=Bit.new(x).tos(2,16).upcase
26
- end
27
- end
28
- def bcc?(str,bcc_char=nil)
29
- str2=str.chomp.upcase
30
- unless bcc_char && str2.size>2
31
- bcc_char=str2[-2..-1]
32
- str2=str2[0..-3]
33
- else
34
- bcc_char=bcc_char.chomp.upcase
35
- end
36
- bcc_char==bcc(str2)
37
- end
38
- end
39
-
40
- if $0==__FILE__
41
- require "bit"
42
-
43
- str="%01#RCSX0000"
44
- include AgriController
45
- AgriController::Bcc::bcc(str)
46
- str1="%01#RCSX0000"+"1d\r"
47
- str2="%01#RCSX0000"
48
- p Bcc::bcc?(str1)==true
49
- p Bcc::bcc?(str2,"1D")==true
50
- p Bcc::bcc?(str2,"1d\r")==true
51
-
52
-
53
- end
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
@@ -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
- module AgriController
23
- class Bit
24
- attr_accessor:bit
25
- def initialize(bit=0)
26
- @bit=bit
27
- end
28
-
29
- def boolbit(bool,bit)
30
- if bool
31
- bit_on(bit)
32
- else
33
- bit_off(bit)
34
- end
35
- end
36
-
37
- def bit_on(bit)
38
- unless on?(bit)
39
- @bit+= 2**bit
40
- end
41
- @bit
42
- end
43
-
44
- def tos(int=6,bit_num=16)
45
- x=@bit.to_s(bit_num)
46
- (int-x.size).times do
47
- x="0"+x
48
- end
49
- return x.upcase
50
- end
51
-
52
- def bit_off(bit)
53
- if on?(bit)
54
- @bit=@bit - 2**bit
55
- end
56
- @bit
57
- end
58
-
59
- def on?(bit)
60
- str=tos(24,2)
61
- case str.slice(-1-bit,1)
62
- when "1"
63
- true
64
- when "0"
65
- false
66
- else
67
- nil
68
- end
69
- end
70
- def off?(bit)
71
- not(on?(bit))
72
- end
73
- def help
74
- "##
75
- #class Bit
76
- # is simple bit culcurater.
77
- # if on or off
78
- # on(bit) # => on bit
79
- # on(1) # =>2 (if @bit==0)
80
- # on(1) # =>3 (if @bit==1)
81
- # on(1) # =>7 (if @bit==5)
82
- # bit_on(bit) # => on bit
83
- #
84
- # off(1) # =>0 (if @bit==2)
85
- # off(1) # =>1 (if @bit==3)
86
- # off(1) # =>5 (if @bit==7)
87
- # bit_off(bit)# => off bit
88
- #
89
- # if check_bit
90
- # on?(bit)# =>true or false
91
- # off?(bit)# =>true or false
92
- #
93
- # boolbit(true,bit) # ==on(bit)
94
- # boolbit(false,bit)# ==off(bit)
95
- #
96
- "
97
- end
98
- alias on bit_on
99
- alias off bit_off
100
- end
101
- end
102
- if $0==__FILE__
103
- #require "profile"
104
- #Test of class Bit
105
- a=AgriController::Bit.new
106
- p a
107
- a.bit_on(1)
108
- a.bit_on(0)
109
- a.bit_on(23)
110
-
111
- 1000.times do
112
- a.bit_on(1)
113
- end
114
- a.bit_on(3)
115
- a.bit_off(1)
116
- a.bit_off(1)
117
- p x=a.bit
118
- p x.to_s(16)
119
- a.bit_off(4)
120
- p x.to_s(2)
121
- p a.off?(3)
122
- p a.off?(2)
123
- p a.off?(1)
124
- p a.off?(0)
125
- p a.on?(3)
126
- p a.on?(2)
127
- p a.on?(1)
128
- p a.on?(0)
129
- p a
130
- p b=AgriController::Bit.new(11)
131
- p b.bit.to_s(2)
132
- print b.help
133
- c=AgriController::Bit.new(8388621)
134
- p c
135
- p c.tos
136
- p c.boolbit(true,4)
137
- p c.tos
138
- p c.boolbit(false,4)
139
- p c.tos
140
- p c.on(4)
141
- p c.bit
142
-
143
- end
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,7 @@
1
+ #!ruby
2
+ #coding:utf-8
3
+ $KCODE="u" if RUBY_VERSION < "1.9.0"
4
+
5
+ Dir.glob(File.dirname(__FILE__)+"/device/*.rb").each do |file|
6
+ require file
7
+ 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