Module: AgriController::WR1010
- Defined in:
- lib/agri-controller/device/wr1010.rb
Overview
module WR1010
before using,you must check COM_port of WR1010,and set same config.
WINDOWS
How to use
require "agri"
include Agri
Communicate with WR1010(is RS232c Wireless Thermo Recorder,Panasonic.) responce below
WR::help # => Usage string
WR::send_sample(3) # => "%01#RDD0000000011**r" #command_sample
res=WR::sample # => "%01$RD0C0129002E000f051301FFFF1E0007040E01FFFF030006023201FFFF020001001A\r" #response sample
WR::toa(res)#=>[[25.9, 36, 36, "10100001000", 5],
[26.7, false, 21, "10100001000", 5],
[26.1, false, 3, "10100001000", 5],
[26.1, false, 51, "10100001000", 5]
]
DATA meaning:
[temperature(celsius degrees), humidity(%RH) if defined , past_sec , conditon Flags , Messages and Radio strength]
Class Method Summary collapse
-
.anaryze(data) ⇒ Object
[“0201”, “2C00”, “2400”, “0805”].
-
.child_thermo(n) ⇒ Object
returns address number of child thermos(5 chars) child_thermo(1)# =>“00003” child_thermo(4)# =>“00015” child_thermo(56)# =>“00223”.
-
.errors(bit_str) ⇒ Object
“10100001000”.
- .help ⇒ Object
-
.judge(x) ⇒ Object
+-tempereture judge function.
- .parse(recieve_value) ⇒ Object
-
.read(port = "/dev/ttyUSB0", speed = 57600, _to__address = 1, from_address = 0) ⇒ Object
This require “serialport” WR1010::read(port=“/dev/ttyUSB0”,speed=57600,_to=3,from=0) [_to,from]: means 1st thermo only, means 2nd 3rd thermo *usualy WR1010::read(port,speed,thermo_num).
- .sample ⇒ Object
- .send_from_to(a, b) ⇒ Object
- .send_sample(n = 4) ⇒ Object
-
.thermo_data(recieve_value) ⇒ Object
thermo_data(recieve_value)# =>[“0ff0fffff500ffff”,“1f00ffffff000000”](ex.).
- .thermo_hex_to_i(data) ⇒ Object
- .thrmo_array(str) ⇒ Object
- .toa(recieve_value) ⇒ Object
Class Method Details
.anaryze(data) ⇒ Object
- “0201”, “2C00”, “2400”, “0805”
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 |
# File 'lib/agri-controller/device/wr1010.rb', line 85 def anaryze(data)#["0201", "2C00", "2400", "0805"] result=[] #result[0] x=thermo_hex_to_i(data[0]) result << judge(x).to_f/10 #result[1] x2 = thermo_hex_to_i(data[1]) if x2==65535 result << false elsif x2<=32766 if x2<=100 result << x2 elsif result << 100 end else #p thermo_hex_to_i(data[1]) result << false end #result[2] result << thermo_hex_to_i(data[2]) #result[3] result << thermo_hex_to_i(data[3]).to_s(2) result end |
.child_thermo(n) ⇒ Object
returns address number of child thermos(5 chars) child_thermo(1)# =>“00003” child_thermo(4)# =>“00015” child_thermo(56)# =>“00223”
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/agri-controller/device/wr1010.rb', line 35 def child_thermo(n) if n==0 y="00000" else x=n*4-1 y=x.to_s (5-y.size).times{y="0"+y} end return y end |
.errors(bit_str) ⇒ Object
“10100001000”
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 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/agri-controller/device/wr1010.rb', line 111 def errors(bit_str)#"10100001000" error_list=[] #if bit_str #p bit_str bit=Bit.new(Integer("0b"+bit_str)) #p bit.bit if bit.on?(0) error_list << "bit0:causion:battery. " end if bit.on?(1) error_list << "bit1:Error:sensor cable. " end if bit.on?(2) error_list << "bit2:causion:Temp is too High or Low. " end if bit.off?(3) error_list << "bit3:Error:FATAL ERROR.child thermo Non-defined. " end #if bit.on?(4) # error_list << "R-on "#"Reray-unit On. " #end #p error_list #radio power size=bit_str.size*-1 #p bit_str #p bit_str.slice((size..-9)) begin radio_power=Integer("0b"+bit_str.slice((size..-9))) rescue#if battery empty bit_str="00FFFF0000" radio_power=0 end if error_list==[] begin return radio_power rescue return nil end end #else # nil #end error_list << radio_power end |
.help ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/agri-controller/device/wr1010.rb', line 217 def help '## # ++module WR1010 # +Communicate with WR1010(is RS232c Wireless Thermo Recorder,Panasonic.) responce below # before using,you must check port of WR1010,and set same config. # # +How to use # require "agri" # include Agri # # WR::help # => Usage string # # WR::send_sample(3) # => "%01#RDD0000000011**r" #command_sample # # res=WR::sample # => "%01$RD0C0129002E000f051301FFFF1E0007040E01FFFF030006023201FFFF020001001A\r" #response sample # # WR::toa(res)#=>[[25.9, 36, 36, "10100001000", 5], # [26.7, false, 21, "10100001000", 5], # [26.1, false, 3, "10100001000", 5], # [26.1, false, 51, "10100001000", 5] # ] # DATA meaning: # [temperature(celsius degrees), humidity(%RH) if defined , past_sec , conditon Flags , Messages and Radio strength] #' end |
.judge(x) ⇒ Object
+-tempereture judge function
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/agri-controller/device/wr1010.rb', line 163 def judge(x) begin bit=Bit.new(x) unless bit.on?(15) return x else res= x-65535 #under -100 'c (degrees Celsius) #thermo must be error 35536 => "1000101011010000" => -2999.9 unless res< -1000 return res else return nil end end rescue nil end end |
.parse(recieve_value) ⇒ Object
213 214 215 |
# File 'lib/agri-controller/device/wr1010.rb', line 213 def parse(recieve_value) toa(recieve_value) end |
.read(port = "/dev/ttyUSB0", speed = 57600, _to__address = 1, from_address = 0) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/agri-controller/device/wr1010.rb', line 265 def read(port="/dev/ttyUSB0",speed=57600,_to__address=1,from_address=0) require "rubygems" require "serialport" #require "timeout" command=send_from_to(from_address,_to__address) begin #timeout(1.5) do sp=SerialPort.new(port,speed,8,1,0)#port,baud,byte,stopbit,parityNONE sp.write(command) res=sp.gets #end rescue Timeout::Error res=nil rescue res=false ensure sp.close if sp end return res end |
.sample ⇒ Object
243 244 245 |
# File 'lib/agri-controller/device/wr1010.rb', line 243 def sample "%01$RD0C0129002E000f051301FFFF1E0007040E01FFFF030006023201FFFF020001001A\r" end |
.send_from_to(a, b) ⇒ Object
253 254 255 256 |
# File 'lib/agri-controller/device/wr1010.rb', line 253 def send_from_to(a,b) channel="01" "%"+channel+"#RDD"+child_thermo(a)+child_thermo(b)+"**\r" end |
.send_sample(n = 4) ⇒ Object
247 248 249 250 251 |
# File 'lib/agri-controller/device/wr1010.rb', line 247 def send_sample(n=4) #child_thermo(1)# =>"00003" channel="01" "%"+channel+"#RDD00000"+child_thermo(n)+"**\r" end |
.thermo_data(recieve_value) ⇒ Object
thermo_data(recieve_value)# =>[“0ff0fffff500ffff”,“1f00ffffff000000”](ex.)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/agri-controller/device/wr1010.rb', line 46 def thermo_data(recieve_value)#ex# =>["0ff0fffff500ffff","1f00ffffff000000"] begin if recieve_value str=recieve_value[6..(-4)] size=str.size if (size)%16 ==0 array=[] (size/16).times do |i| array[i]=str.slice!(0..15) end array else nil end else nil end rescue return nil end end |
.thermo_hex_to_i(data) ⇒ Object
184 185 186 187 188 189 |
# File 'lib/agri-controller/device/wr1010.rb', line 184 def thermo_hex_to_i(data) #hex="f100" # =>241 x=data.slice(0..1) y=data.slice(2..3) result=((y+x).to_i(16)) end |
.thrmo_array(str) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/agri-controller/device/wr1010.rb', line 68 def thrmo_array(str) begin result=[] str.each do |data| #p data ;p data.size result_1=[] (data.size/4).times do |i| result_1 << data.slice((i*4),4) end result << anaryze(result_1) end return result rescue return nil end end |
.toa(recieve_value) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/agri-controller/device/wr1010.rb', line 191 def toa(recieve_value) result=[] #begin if recieve_value ret=thermo_data(recieve_value) if ret x=thrmo_array(ret) if x x.each do |data| ret=errors(data[3]) data << ret#"10100001000" result << data end return result end end end #rescue nil #end end |