Module: AgriController::Dacs

Defined in:
lib/agri-controller/device/dacs.rb

Overview

use Dacs_32bit_I/O_photoMOS_reray on usb_serial_port (win,linux compatible) *Usage

requrie "agri-controll"
include AgriController
include Dacs # also use Dacs::

Windows

export is a simple IO_command send(set),and recieve(import) search com_port(3-19) and communicate export(“ffffff”)# =>“R0FFFFFF&”

com_port number recommended com_port=6 #(see system infomation)

export("ffffff",com_port,0)#return =>"R0FFFFFF&"
export("000000",com_port,0)#return =>"R0FFFFFF&"
export("R",com_port,1)     #return =>"R883DFFF&"
export("R",com_port)       #return =>"R0FFFFFF&"

hex_6 ex. # =>“FBD017”,“ffffff” recieve only.# =>“R”

Linux

include dacs
export("W0FFFFFF\r","ttyUsb0") 
import("R0R\r")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sampleObject



137
138
139
# File 'lib/agri-controller/device/dacs.rb', line 137

def sample
  "W0FFFFFF\r"
end

.toi(res) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/agri-controller/device/dacs.rb', line 128

def toi(res)
  begin
    bit=res.slice(2,6).to_i(16)
    return bit
  rescue
    nil
  end
end

Instance Method Details

#export(command, device) ⇒ Object

should be Linux



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
# File 'lib/agri-controller/device/dacs.rb', line 124

def export(hex_6,com_port=port?,io_port=0,dip=0)
  #hex_6
  #ex.          # =>"FBD017","ffffff"
  #recieve only.# =>"R"

  case io_port
  #io_port must be io_port*8+dip_switch(on board)
  when 1
    io_port=8*io_port+dip#2nd word
  else#io_port should be 0
    io_port=dip#2nd word
  end
  a=Serial.new
    #search COM port 3-9
    if a.open(com_port,0,57600,8,0,0,4096,4096)!=-1
      command="W#{(io_port).to_s}#{hex_6}\r"
      
      yield command if block_given?
      #p command
      a.send(command)
      sleep 0.04
      receive=a.receive
      a.close
      return receive
    else
      return false
    end
  nil
end

#import(com_port = port?,i, io_port = 0, dip = 0) ⇒ Object



109
110
111
# File 'lib/agri-controller/device/dacs.rb', line 109

def import(com_port=port?,io_port=0,dip=0)
  export("R",com_port,io_port,dip)
end

#import_bit(com_port = port?,i, io_port = 0, dip = 0) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/agri-controller/device/dacs.rb', line 113

def import_bit(com_port=port?,io_port=0,dip=0)
  
  port_bit=import(com_port=port?,io_port,dip)
  if port_bit
    import_bits=port_bit.slice(2,6).to_i(16)
  else
    import_bits=0
  end
  return import_bits
end

#port?(x = 3) ⇒ Boolean

search ports COM3-19 if sucsess return int(port number) else return nil.

Returns:

  • (Boolean)


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
# File 'lib/agri-controller/device/dacs.rb', line 73

def port?(x=3)
  a=Serial.new
    #search COM port 3-19
    bool=false#serch flag
    
    while bool==false
      x+=1
      if x > 20
        return nil
      end

      if a.open(x,0,57600,8,0,0,108,324) == -1
        if x > 20
          return nil
        end
      else
        a.send("W0R\r")
        sleep 0.1
        receive=a.receive#should_be "R0xxxxxx\r",x=hex
        #p receive.split(//).last
        #p x
        #p receive
        if receive
          if receive.split(//).last=="\r"
            if receive.split(//).first=="R"
              bool=true
            end
          end
        end
        a.close
      end
    end

  return x
end