namespace eval DAQ {} {
}

proc stdConfig::DAQ {} {
  controller std "\n" 20 
  prop startcmd "*IDN?"

  obj DAQ  -none
   kids settings {
    node resist upd
    node stddev upd
    node file upd
    node measure out
    default 0
    prop write DAQ::measure
    prop enum 1
    
    node freq out
    default 5000.0
    prop write DAQ::setval
    node ampl out
    default 0.1
    prop write DAQ::setval
   }

}




proc DAQ::measure {} {
    sct send "AQUIRE"
    return DAQ::update
  }


proc DAQ::update {} {
  set output [sct result]
  set items [split $output ","]
 
  hupdate [sct parent]/resist [lindex $items 0]
  hupdate [sct parent]/stddev [lindex $items 1]
  hupdate [sct parent]/file [lindex $items 2]
  hupdate [sct] 0
    return idle
}

proc DAQ::setval {} {
  sct send "PULSE [format "%0.2f" [sctval [sct parent]/freq]] [format "%0.3f" [sctval [sct parent]/ampl]]"
#  clientput "PULSE [format "%0.2f" [sctval [sct parent]/freq]] [format "%0.3f" [sctval [sct parent]/ampl]]"  
  return DAQ::readval
}

proc DAQ::readval {} {
   set dat [sct result] 
    scan $dat "F=%fHz; A= %fVpp" f a 
    hupdate [sct parent]/freq $f
    hupdate [sct parent]/ampl $a
  return idle
}
