require "timeout" class UsbTmc def initialize(adrs=0) @port=open("/dev/usbtmc%d"%adrs,"r+") each_init end def finish @port.close end def each_init() # initialization for each instrument end def talk(str) begin timeout(1){ @port.write(str) @port.flush } rescue TimeoutError puts "write timeout error at #{Time::now} on USB with '#{str}'" end end def listen(n=256) begin timeout(1){ @port.readpartial(n) } rescue TimeoutError puts "read timeout error at #{Time::now} on USB" return 0 end end def idn() talk(sprintf("*IDN?")) listen() end #def init() # talk("*CLS") #end #def reset() # talk("*RST") #end end #class