def acq2sh(self, arg): boardip = self.getBoardIp() try: UUT = acq200.Acq200(transport.factory(boardip)) except: print "could not connect to the board %s" % (boardip, ) try: a = UUT.uut.acq2sh(str(arg)) except: print "could not send %s to the board" % (str(arg), ) return 0 print "%s %s -> %s" % ( boardip, arg, a, ) return 1
def trigger(self, arg): if self.debugging(): print "starting trigger" boardip = self.getBoardIp() try: trig_src = self.trig_src.record.getOriginalPartName().getString( )[1:] except: print "could not read trigger source" return 0 if self.debugging(): print "executing trigger on board %s, trig_src is %s." % ( boardip, trig_src, ) trig_src = trig_src[2:] try: UUT = acq200.Acq200(transport.factory(boardip)) except: print "could not connect to the board %s" % (boardip, ) try: route = UUT.uut.acq2sh('get.route D%s' % (trig_src, )) d1 = UUT.uut.acq2sh('set.route d%s in fpga out' % (trig_src, )) d2 = UUT.uut.acq2sh('set.dtacq dio_bit %s P' % (trig_src, )) d3 = UUT.uut.acq2sh('set.route %s' % (route, )) d4 = UUT.uut.acq2sh('set.dtacq dio_bit %s -' % (trig_src, )) except: print "could not send command to the board" if self.debugging(): print "got back: %s\n" % (route, ) print " and: %s\n" % (d1, ) print " and: %s\n" % (d2, ) print " and: %s\n" % (d3, ) print " and: %s\n" % (d4, ) return 1
def store(self, arg): """ Store the data from the device Fetch and store the device status (firmware etc) If the device is finished For each channel that is on and active in the mask read the data store the data into the raw nodes store the expression into the data nodes """ debug = os.getenv("DEBUG_DEVICES") try: boardip = self.check('str(self.boardip.record)', "Must specify a board ipaddress") UUT = acq200.Acq200(transport.factory(boardip)) try: ans = [] cmds = self.status_cmds.record for cmd in cmds: print(cmd) a = UUT.uut.acq2sh(cmd) ans.append(a) self.board_status.record = Data.compile( 'build_signal($,*, $)', ans, cmds) except Exception: pass complete = 0 tries = 0 if UUT.get_state().split()[-1] == "ST_RUN": raise Exception( "Device not Triggered \n device returned -%s-" % UUT.get_state().split()[-1]) if debug: print("about to get the vins\n") vins = self.getVins(UUT) self.ranges.record = vins (tot, pre, post, run) = UUT.get_numSamples() pre = int(pre) post = int(post) if pre == 0 and post == 0: return 662480266 # DT196B$_NO_SAMPLES mask = UUT.uut.acqcmd('getChannelMask').split('=')[-1] if debug: print("pre = %d, post = %d" % ( pre, post, )) clock_src = self.check( 'str(self.clock_src.record.getOriginalPartName())[1:]', "Clock source must be a string") if clock_src == 'INT_CLOCK': self.clock.record = Range(delta=1. / self.getInternalClock(UUT)) else: self.clock.record = self.clock_src clock = self.clock.record if debug: print("about to start the script") (fd, fname) = mkstemp('.sh') f = open(fname, 'w') f.write("#!/bin/sh\n") f.write("touch /tmp/starting_%d\n" % self.boardip.tree.shot) f.write("acqcmd --until ST_STOP\n") f.write("mdsConnect %s\n" % str(self.hostip.record)) cmd = "mdsValue \"job_start('%s', %d)\"" % (self.path, self.tree.shot) cmd = cmd.replace('\\', '\\\\\\\\\\\\\\') f.write("%s\n" % (cmd, )) f.write("mdsOpen %s %d\n" % ( self.boardip.tree.name, self.boardip.tree.shot, )) for chan in range(96): chan_node = eval('self.input_%2.2d' % (chan + 1, )) chan_raw_node = eval('self.input_%2.2d_raw' % (chan + 1, )) if chan_node.on: if debug: print("it is on so ...") if mask[chan:chan + 1] == '1': try: start = eval("int(self.input_%2.2d_start_idx)" % (chan + 1)) except: start = pre try: end = eval("int(self.input_%2.2d_end_idx" % (chan + 1)) except: end = post - 1 try: inc = eval("int(self.input_%2.2d_inc)" % (chan + 1)) except: inc = 1 if debug: print("build the command") command = "mdsPutCh --field %s:raw --expr %%calsig --timebase %d,%d,%d %d\n" % ( chan_node.getFullPath(), int(start), int(end), int(inc), chan + 1) command = command.replace('\\', '\\\\') if debug: print("about to execute %s" % command) f.write(command) if inc > 1: clk = None delta = None begin = None ending = None try: clk = self.clock.evaluate() delta = clk.delta begin = clk.begin ending = clk.ending except: pass if delta: axis = Range(begin, ending, delta * inc) window = Window(start / inc, end / inc, self.trig_src) dim = Dimension(window, axis) else: dim = Data.compile( 'Map($,$)', Dimension( Window(start / inc, end / inc, trig_src), clock), Range(start, end, inc)) raw = Data.compile('data($)', chan_raw_node) chan_node.record = eval('Signal(raw, "", dim)') else: raw = Data.compile('data($)', chan_raw_node) chan_node.record = Signal( raw, "", Dimension( Window(start, end - 1, self.trig_src), clock)) f.write('mdsClose %s\n' % (self.boardip.tree.name, )) f.write("touch /tmp/finished_%d\n" % self.boardip.tree.shot) cmd = "mdsValue \"job_finish('%s', %d)\"" % (self.path, self.tree.shot) cmd = cmd.replace('\\', '\\\\\\\\\\\\\\') f.write("%s\n" % (cmd, )) f.write("rm $0\n") f.close() cmd = 'curl -s -T %s ftp://%s/%s' % (fname, boardip, 'post_shot.sh') pipe = os.popen(cmd) pipe.close() UUT.uut.acq2sh("chmod a+rx /home/ftp/post_shot.sh") UUT.uut.acq2sh("/home/ftp/post_shot.sh&") except Exception as e: print("Error storing DT196B Device\n%s" % (str(e), )) return 0 return 1
def init(self, arg): """ Initialize the device Send parameters Arm hardware """ debug = os.getenv("DEBUG_DEVICES") try: boardip = self.check('str(self.boardip.record)', "Must specify a board ipaddress") UUT = acq200.Acq200(transport.factory(boardip)) active_chans = self.check( "int(self.active_chans)", "Must specify active chans as int in (32,64,96)") if active_chans not in (32, 64, 96): print("active chans must be in (32, 64, 96 )") active_chans = 96 trig_src = self.check( 'str(self.trig_src.record.getOriginalPartName())[1:]', "Trig source must be a string") print("trig_src is %s\n" % trig_src) if not trig_src in self.trig_sources: raise Exception("Trig_src must be in %s" % str(self.trig_sources)) trig_edge = self.check('self.trig_edge.record.getString()', 'Trig edge must be a string') clock_src = self.check( 'str(self.clock_src.record.getOriginalPartName())[1:]', "Clock source must be a string") if debug: print("clock_src is %s\n" % clock_src) if not clock_src in self.clock_sources: raise Exception("Clock_src must be in %s" % str(self.clock_sources)) if clock_src == 'INT_CLOCK' or clock_src == 'MASTER': clock_freq = self.check( 'int(self.clock_freq)', "Must specify a frequency for internal clock") else: clock_freq = self.check( 'int(self.clock_freq)', "Must specify a frequency for external clock") clock_div = self.check( 'int(self.clock_div)', "Must specify a divisor for external clock") pre_trig = self.check('int(self.pre_trig.data()*1024)', "Must specify pre trigger samples") post_trig = self.check('int(self.post_trig.data()*1024)', "Must specify post trigger samples") UUT.set_abort() UUT.clear_routes() for i in range(6): line = 'd%1.1d' % i try: wire = eval('str(self.di%1.1d_wire.record)' % i) if wire not in self.wires: print("DI%d:wire must be in %s" % ( i, str(self.wires), )) wire = 'fpga' except: wire = 'fpga' try: bus = eval('str(self.di%1.1d_bus.record)' % i) if bus not in self.wires: print("DI%d:bus must be in %s" % ( i, str(self.wires), )) bus = '' except: bus = '' UUT.set_route(line, 'in %s out %s' % ( wire, bus, )) UUT.setChannelCount(active_chans) if clock_src == 'INT_CLOCK' or clock_src == 'MASTER': UUT.uut.acqcmd("setInternalClock %d" % clock_freq) if clock_src == 'MASTER': UUT.uut.acqcmd('-- setDIO -1-----') else: if (clock_div != 1): UUT.uut.acqcmd("setExternalClock %s %d D02" % ( clock_src, clock_div, )) # # the following is not generic # the clock is output on d2 and comes from DI0 # UUT.set_route('d2', 'in fpga out pxi') UUT.uut.acqcmd('-- setDIO --1-----') UUT.uut.acq2sh('set.ext_clk DI0') else: UUT.uut.acqcmd("setExternalClock %s" % clock_src) UUT.setPrePostMode(pre_trig, post_trig, trig_src, trig_edge) mask = UUT.uut.acqcmd('getChannelMask').split('=')[-1] UUT.set_arm() return 1 except Exception as e: print("%s\n" % (str(e), )) return 0
def store(self, arg): """ Store the data from the device Fetch and store the device status (firmware etc) If the device is finished For each channel that is on and active in the mask read the data store the data into the raw nodes store the expression into the data nodes """ debug = os.getenv("DEBUG_DEVICES") try: error = "Must specify a board ipaddress" boardip = str(self.boardip.record) error = None UUT = acq200.Acq200(transport.factory(boardip)) try: ans = [] cmds = self.status_cmds.record for cmd in cmds: print cmd a = UUT.uut.acq2sh(cmd) ans.append(a) self.board_status.record = Signal(makeArray(ans), None, makeArray(cmds)) except Exception, e: pass complete = 0 tries = 0 while not complete and tries < 60: if UUT.get_state().split()[-1] == "ST_POSTPROCESS": tries += 1 sleep(1) else: complete = 1 if UUT.get_state().split()[-1] != "ST_STOP": raise Exception, "Device not Triggered \n device returned -%s-" % UUT.get_state( ).split()[-1] if debug: print "about to get the vins\n" vins = self.getVins(UUT) self.ranges.record = vins (tot, pre, post, run) = UUT.get_numSamples() pre = int(pre) * -1 post = int(post) - 1 mask = UUT.uut.acqcmd('getChannelMask').split('=')[-1] error = "Clock source must be a string" clock_src = self.clock_src.record.getOriginalPartName().getString( )[1:] error = None if clock_src == 'INT_CLOCK': self.clock.record = Range(delta=1. / self.getInternalClock(UUT)) else: self.clock.record = self.clock_src clock = self.clock.record if debug: print "about to ask it to mdsconnect" UUT.uut.acq2sh("mdsConnect %s" % str(self.hostip.record)) if debug: print "about to ask it to mdsopen" UUT.uut.acq2sh('mdsOpen %s %d' % ( self.boardip.tree.name, self.boardip.tree.shot, )) for chan in range(32): if debug: print "working on channel %d" % chan chan_node = self.__getattr__('input_%2.2d' % (chan + 1, )) chan_raw_node = self.__getattr__('input_%2.2d_raw' % (chan + 1, )) if chan_node.on: if debug: print "it is on so ..." if mask[chan:chan + 1] == '1': try: start = max( int( self.__getattr__('input_%2.2d_start_idx' % (chan + 1))), pre) print "start = %d" % start except: start = pre try: end = min( int( self.__getattr__('input_%2.2d_end_idx' % (chan + 1))), post) print "end = %d" % end except: end = post try: inc = int( self.__getattr__('input_%2.2d_inc' % (chan + 1))) print "inc = %d" % inc except: inc = 1 if debug: print "build the command" command = "mdsPutCh --field %s:raw --expr %%calsig --timebase %d,%d,%d %d" % ( chan_node.getFullPath(), int(start - pre), int(end - pre), int(inc), chan + 1) command = command.replace('\\', '\\\\') if debug: print "about to execute %s" % command UUT.uut.acq2sh(command) if inc > 1: clk = '' delta = '' begin = '' end = '' try: clk = self.clock.evaluate() delta = clk.delta begin = clk.begin ending = clk.end except: pass if delta: axis = Range(begin, ending, delta / inc) window = Window(start / inc, end / inc, trigger) dim = Dimension(window, axis) else: dim = Data.Compile( 'Map($,$)', Dimension( Window(start / inc, end / inc, trigger), clock), Range(start, end, inc)) raw = Data.compile('data($)', chan_raw_node) chan_node.record = Signal(raw, None, dim) else: raw = Data.compile('data($)', chan_raw_node) chan_node.record = Signal( raw, None, Dimension(Window(start, end, self.trig_src), clock)) UUT.uut.acq2sh('mdsClose %s' % (self.boardip.tree.name, ))
def init(self, arg): """ Initialize the device Send parameters Arm hardware """ debug = os.getenv("DEBUG_DEVICES") try: error = "Must specify a board ipaddress" boardip = str(self.boardip.record) error = None error = "Must specify active chans as int in (8,16,32)" active_chans = int(self.active_chans) error = None if active_chans not in (8, 16, 32): print "active chans must be in (8, 16, 32)" active_chans = 32 error = "Trig source must be a string" trig_src = self.trig_src.record.getOriginalPartName().getString( )[1:] error = None if debug: print "trig_src is %s\n" % trig_src if not trig_src in self.trig_sources: raise Exception, "Trig_src must be in %s" % str( self.trig_sources) error = 'Trig edge must be a string' trig_edge = self.trig_edge.record.getString() error = None error = "Clock source must be a string" clock_src = self.clock_src.record.getOriginalPartName().getString( )[1:] error = None if debug: print "clock_src is %s\n" % clock_src if not clock_src in self.clock_sources: raise Exception, "Clock_src must be in %s" % str( self.clock_sources) if (clock_src == 'INT_CLOCK'): error = "Must specify a frequency for internal clock" clock_freq = int(self.clock_freq) error = None else: error = "Must specify a frequency for external clock" clock_freq = int(self.clock_freq) error = "Must specify a divisor for external clock" clock_div = int(self.clock_div) error = None error = "Must specify pre trigger samples" pre_trig = int(self.pre_trig.data() * 1024) error = "Must specify post trigger samples" post_trig = int(self.post_trig.data() * 1024) UUT = acq200.Acq200(transport.factory(boardip)) UUT.set_abort() UUT.clear_routes() for i in range(6): line = 'd%1.1d' % i try: wire = str(self.__getattr__('di%1.1d_wire' % i).record) if wire not in self.wires: print "DI%d:wire must be in %s" % ( i, str(self.wires), ) wire = 'fpga' except: wire = 'fpga' try: bus = str(self.__getattr__('di%1.1d_bus' % i).record) if bus not in self.wires: print "DI%d:bus must be in %s" % ( i, str(self.wires), ) bus = '' except: bus = '' UUT.set_route(line, 'in %s out %s' % ( wire, bus, )) UUT.setChannelCount(active_chans) if clock_src == 'INT_CLOCK': UUT.uut.acqcmd("setInternalClock %d" % clock_freq) else: UUT.uut.acqcmd("-- setExternalClock --fin %d --fout %d DI0" % ( clock_freq / 1000, clock_freq / 1000, )) UUT.setPrePostMode(pre_trig, post_trig, trig_src, trig_edge) UUT.set_arm() return 1 except Exception, e: if error is not None: e = error print "%s\n" % (str(e), ) return 0