class PtM3500a < Instrument # multimeter # PICOTEST M3500A def instrument() @function="voltage:dc" @delay=0 @count=1 end def function(str="") strs=["voltage:ac", "voltage:dc", "resistance","fresistance", "current:ac","current:dc", "frequency","temperature", "period","diode","continuity"] # command("sense:function",v,*str) if strs.include?(str) talk('sense:function "%s"'%str) @function=str else talk("sense:function?") @function=listen() # remove quote end @function end def range(v=nil) command("sense:%s:range"%@function,v,"min","max") end def rangeauto(v=nil) command("sense:%s:range:auto"%@function,v,"on","off") end def resolution(v=nil) #min is good resolution command("sense:%s:resolution"%@function,v,"min","max") end def cycle(v=nil) # measuring time in the unit of 1s/cycle of AC line command("sense:%s:nplcycles"%@function,v,"min","max") #0.02|0.1|1|10 end def average(n=nil,v=nil,o=nil) o="on" if n n=command("sense:average:count",n,"min","max") v=command("sense:average:tcontrol",v,"mov","rep") o=command("sense:average:state",o,"on","off") [n,v,o] end def thermocouple(v=nil) command("sense:tcouple:type",v,*%w"E J K N R S T") end def unit(v=nil) command("sense:unit",v,"C","F","K") end #sense:tcouple:rjunction:rselect real|sim def simulate(v=nil) #temperature reference command("sense:tcouple:simulated",v,"min","max") end def trigger(v=nil) #bus trigger, internal immediate mode, external mode command("trigger:source",v,"bus","imm","ext") end def delay(v=nil) #second @delay=command("trigger:delay",v,"min","max").to_f end def delayauto(v=nil) command("trigger:delay:auto",v,"on","off") end def measure() #sigle measurement talk("measure?") sleep @delay listen().to_s.sub(/^\w*/){""}.to_f end def read() # not stored in memory talk("read?") #trigger listen().to_s.sub(/^\w*/){""}.to_f end #TRIGger:COUNt def count(v=nil) #several measuremts in one trigger @count=command("sample:count",v).to_i end def initiate() # stored into memory talk("INITIATE") end def memory() # wait and read from memory sleep 0.01 while command("data:points",nil).to_f<@count talk("fetch?") listen(20*@count).split(/,/).map(&:to_f) end def point() command("data:points",nil) end def fetch() command("fetch",nil) end protected def command(str="",v=nil,*strs) if String===v and v.to_s=~/^(#{strs*"|"})/i talk("%s %s"%[str,$1.upcase]) elsif Numeric===v #Numeric===strs[0] and v # sign=(strs[0]==strs.max)?1:-1 #descending/ascending # v=v.to_f.abs # v=[strs.find_index{|vv|sign*vv.to_f