def TIME(*arg): def TimeToNs(v): try: v = v.data() except: pass if v<=1E16: v = int(v*1000)*1000000 return v if len(arg)==0: pass elif len(arg)==1: if arg[0] is None: EmptyData().setTdiVar('_time') else: TdiExecute('TreeOpen($,$)',('W7X',int(arg[0]))) TdiExecute("DATA(TIMING)").setTdiVar('_time') elif len(arg)<=3: arg = map(TimeToNs,arg) if len(arg)==2: t = [arg[0],arg[1],arg[0]] elif len(arg)==3: t = [arg[0],arg[1],arg[2]] makeArray(t).setTdiVar('_time') else: raise Exception('Only upto 3 arguments allowed.') try: time = TdiExecute('PUBLIC("_time")') except: print("cleared") return print('from %s upto %s, t=0 @ %s' % tuple(base.TimeArray(time.data()).utc)) return time
def TIME(*arg): def TimeToNs(v): try: v = v.data() except: pass if v <= 1E16: v = int(v * 1000) * 1000000 return v if len(arg) == 0: pass elif len(arg) == 1: if arg[0] is None: EmptyData().setTdiVar('_time') else: TdiExecute('TreeOpen($,$)', ('W7X', int(arg[0]))) TdiExecute("DATA(TIMING)").setTdiVar('_time') elif len(arg) <= 3: arg = map(TimeToNs, arg) if len(arg) == 2: t = [arg[0], arg[1], arg[0]] elif len(arg) == 3: t = [arg[0], arg[1], arg[2]] makeArray(t).setTdiVar('_time') else: raise Exception('Only upto 3 arguments allowed.') try: time = TdiExecute('PUBLIC("_time")') except: print("cleared") return print('from %s upto %s, t=0 @ %s' % tuple(base.TimeArray(time.data()).utc)) return time
def getVins(self, UUT): vins = UUT.uut.acq2sh('get.vin 1:32') vins = vins[0] vins = vins[:-1] return makeArray(numpy.array(vins.split()).astype('int'))
class DT132(Device): """ D-Tacq ACQ132 32 channel transient recorder Methods: Add() - add a DTAO32 device to the tree open for edit Init(arg) - initialize the DTAO32 device write setup parameters and waveforms to the device Store(arg) - store the data acquired by the device Help(arg) - Print this message Nodes: :HOSTIP - mdsip address of the host storing the data. Usually 192.168.0.254:8106 BOARDIP'- ip addres sof the card as a string something like 192.168.0.40 COMMENT - user comment string DI[0-5] - time(s) of the signal on this internal wire (trig reference or clock reference) :wire - string specifying the source of this signal { 'fpga','mezz','rio','pxi','lemo', 'none } :bus - string specifying the destination of this signal { 'fpga','rio','pxi', 'none } :ACTIVE_CHANS - number of active channels {8, 16, 32} INT_CLOCK - stored by module (representation of internal clock TRIG_SRC - reference to DIn line used for trigger (DI3) TRIG_EDGE - string {rising, falling} CLOCK_SRC - reference to line (DIn) used for clock or INT_CLOCK CLOCK_DIV - NOT CURRENTLY IMPLIMENTED CLOCK_EDGE - string {rising, falling} CLOCK_FREQ - frequency for internal clock PRE_TRIG - pre trigger samples MUST BE ZERO FOR NOW POST_TRIG - post trigger samples SEGMENTS - number of segments to store data in NOT IMPLIMENTED FOR NOW CLOCK - Filled in by store place for module to store clock information RANGES - place for module to store calibration information STATUS_CMDS - array of shell commands to send to the module to record firmware version etc BOARD_STATUS - place for module to store answers for STATUS_CMDS as signal INPUT_[01-32] - place for module to store data in volts (reference to INPUT_NN:RAW) :RAW - place for module to store raw data in volts for each channel START_IDX - first sample to store for this channel END_IDX - last sample to store for this channel INC - decimation factor for this channel INIT_ACTION - dispatching information for INIT STORE_ACTION - dispatching information for STORE """ parts = [ { 'path': ':HOSTIP', 'type': 'text', 'value': '192.168.0.254', 'options': ('no_write_shot', ) }, { 'path': ':BOARDIP', 'type': 'text', 'value': '192.168.0.0', 'options': ('no_write_shot', ) }, { 'path': ':COMMENT', 'type': 'text' }, ] for i in range(6): parts.append({ 'path': ':DI%1.1d' % (i, ), 'type': 'numeric', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:BUS' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:WIRE' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts2 = [ { 'path': ':ACTIVE_CHANS', 'type': 'numeric', 'value': 32, 'options': ('no_write_shot', ) }, { 'path': ':INT_CLOCK', 'type': 'axis', 'options': ('no_write_model', 'write_once') }, { 'path': ':TRIG_SRC', 'type': 'numeric', 'valueExpr': 'head.di3', 'options': ('no_write_shot', ) }, { 'path': ':TRIG_EDGE', 'type': 'text', 'value': 'rising', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_SRC', 'type': 'numeric', 'valueExpr': 'head.int_clock', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_DIV', 'type': 'numeric', 'value': 1, 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_EDGE', 'type': 'text', 'value': 'rising', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_FREQ', 'type': 'numeric', 'value': 1000000, 'options': ('no_write_shot', ) }, { 'path': ':PRE_TRIG', 'type': 'numeric', 'value': 0, 'options': ('no_write_shot', ) }, { 'path': ':POST_TRIG', 'type': 'numeric', 'value': 128, 'options': ('no_write_shot', ) }, { 'path': ':SEGMENTS', 'type': 'numeric', 'value': 1, 'options': ('no_write_shot', ) }, { 'path': ':CLOCK', 'type': 'axis', 'options': ('no_write_model', 'write_once') }, { 'path': ':RANGES', 'type': 'numeric', 'options': ('no_write_model', 'write_once') }, { 'path': ':STATUS_CMDS', 'type': 'text', 'value': makeArray(['cat /proc/cmdline', 'get.d-tacq.release']), 'options': ('no_write_shot', ) }, { 'path': ':BOARD_STATUS', 'type': 'SIGNAL', 'options': ('no_write_model', 'write_once') }, ] parts.extend(parts2) del parts2 for i in range(32): parts.append({ 'path': ':INPUT_%2.2d' % (i + 1, ), 'type': 'signal', 'options': ( 'no_write_model', 'write_once', ) }) parts.append({ 'path': ':INPUT_%2.2d:RAW' % (i + 1, ), 'type': 'SIGNAL', 'options': ('no_write_model', 'write_once') }) parts.append({ 'path': ':INPUT_%2.2d:START_IDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:END_IDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:INC' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INIT_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','INIT',50,None),Method(None,'INIT',head))", 'options': ('no_write_shot', ) }) parts.append({ 'path': ':STORE_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','STORE',50,None),Method(None,'STORE',head))", 'options': ('no_write_shot', ) }) clock_edges = ['rising', 'falling'] trigger_edges = clock_edges trig_sources = [ 'DI0', 'DI1', 'DI2', 'DI3', 'DI4', 'DI5', ] clock_sources = trig_sources clock_sources.append('INT_CLOCK') masks = { 8: '11110000000000001111000000000000', 16: '11111111000000001111111100000000', 32: '11111111111111111111111111111111', } wires = ['fpga', 'mezz', 'rio', 'pxi', 'lemo', 'none', 'fpga pxi'] del i 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
class DT196B(Device): """ D-Tacq ACQ196 96 channel transient recorder Methods: Add() - add a DT196B device to the tree open for edit Init(arg) - initialize the DT196B device write setup parameters and waveforms to the device Store(arg) - store the data acquired by the device Help(arg) - Print this message Nodes: :HOSTIP - mdsip address of the host storing the data. Usually 192.168.0.254:8106 BOARDIP'- ip addres sof the card as a string something like 192.168.0.40 COMMENT - user comment string DI[0-5] - time(s) of the signal on this internal wire (trig reference or clock reference) :wire - string specifying the source of this signal { 'fpga','mezz','rio','pxi','lemo', 'none } :bus - string specifying the destination of this signal { 'fpga','rio','pxi', 'none } :ACTIVE_CHANS - number of active channels {32, 64, 96} INT_CLOCK - stored by module (representation of internal clock MASTER - points to INT_CLOCK node - needed a node to fill into clock_src TRIG_SRC - reference to DIn line used for trigger (DI3) TRIG_EDGE - string {rising, falling} CLOCK_SRC - reference to line (DIn) used for clock or INT_CLOCK, or MASTER CLOCK_DIV - NOT CURRENTLY IMPLIMENTED CLOCK_EDGE - string {rising, falling} CLOCK_FREQ - frequency for internal clock PRE_TRIG - pre trigger samples MUST BE ZERO FOR NOW POST_TRIG - post trigger samples SEGMENTS - number of segments to store data in NOT IMPLIMENTED FOR NOW CLOCK - Filled in by store place for module to store clock information RANGES - place for module to store calibration information STATUS_CMDS - array of shell commands to send to the module to record firmware version etc BOARD_STATUS - place for module to store answers for STATUS_CMDS as signal INPUT_[01-96] - place for module to store data in volts (reference to INPUT_NN:RAW) :RAW - place for module to store raw data in volts for each channel START_IDX - first sample to store for this channel END_IDX - last sample to store for this channel INC - decimation factor for this channel INIT_ACTION - dispatching information for INIT STORE_ACTION - dispatching information for STORE """ parts = [ { 'path': ':HOSTIP', 'type': 'text', 'value': '192.168.0.254', 'options': ('no_write_shot', ) }, { 'path': ':BOARDIP', 'type': 'text', 'value': '192.168.0.0', 'options': ('no_write_shot', ) }, { 'path': ':COMMENT', 'type': 'text' }, ] for i in range(6): parts.append({ 'path': ':DI%1.1d' % (i, ), 'type': 'numeric', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:BUS' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:WIRE' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts2 = [ { 'path': ':ACTIVE_CHANS', 'type': 'numeric', 'value': 96, 'options': ('no_write_shot', ) }, { 'path': ':INT_CLOCK', 'type': 'axis', 'options': ('no_write_model', 'write_once') }, { 'path': ':MASTER', 'type': 'axis', 'valueExpr': 'head.int_clock', 'options': ('no_write_model', 'write_once') }, { 'path': ':TRIG_SRC', 'type': 'numeric', 'valueExpr': 'head.di3', 'options': ('no_write_shot', ) }, { 'path': ':TRIG_EDGE', 'type': 'text', 'value': 'rising', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_SRC', 'type': 'numeric', 'valueExpr': 'head.int_clock', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_DIV', 'type': 'numeric', 'value': 1, 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_EDGE', 'type': 'text', 'value': 'rising', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_FREQ', 'type': 'numeric', 'value': 100000, 'options': ('no_write_shot', ) }, { 'path': ':PRE_TRIG', 'type': 'numeric', 'value': 0, 'options': ('no_write_shot', ) }, { 'path': ':POST_TRIG', 'type': 'numeric', 'value': 128, 'options': ('no_write_shot', ) }, { 'path': ':SEGMENTS', 'type': 'numeric', 'value': 1, 'options': ('no_write_shot', ) }, { 'path': ':CLOCK', 'type': 'axis', 'options': ('no_write_model', 'write_once') }, { 'path': ':RANGES', 'type': 'numeric', 'options': ('no_write_model', 'write_once') }, { 'path': ':STATUS_CMDS', 'type': 'text', 'value': makeArray(['cat /proc/cmdline', 'get.d-tacq.release']), 'options': ('no_write_shot', ) }, { 'path': ':BOARD_STATUS', 'type': 'SIGNAL', 'options': ('no_write_model', 'write_once') }, ] parts.extend(parts2) del parts2 for i in range(96): parts.append({ 'path': ':INPUT_%2.2d' % (i + 1, ), 'type': 'signal', 'options': ( 'no_write_model', 'write_once', ) }) parts.append({ 'path': ':INPUT_%2.2d:RAW' % (i + 1, ), 'type': 'SIGNAL', 'options': ('no_write_model', 'write_once') }) parts.append({ 'path': ':INPUT_%2.2d:START_IDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:END_IDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:INC' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INIT_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','INIT',50,None),Method(None,'INIT',head))", 'options': ('no_write_shot', ) }) parts.append({ 'path': ':STORE_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','STORE',50,None),Method(None,'STORE',head))", 'options': ('no_write_shot', ) }) parts.append({ 'path': ':WAIT_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','STORE',60,None),Method(None,'WAIT',head))", 'options': ('no_write_shot', ) }) clock_edges = ['rising', 'falling'] trigger_edges = clock_edges trig_sources = [ 'DI0', 'DI1', 'DI2', 'DI3', 'DI4', 'DI5', ] clock_sources = trig_sources clock_sources.append('INT_CLOCK') clock_sources.append('MASTER') wires = ['fpga', 'mezz', 'rio', 'pxi', 'lemo', 'none', 'fpga pxi'] del i def check(self, expression, message): try: ans = eval(expression) return ans except: raise Exception(message) 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 INIT = init def getVins(self, UUT): vin1 = UUT.uut.acq2sh('get.vin 1:32') vin2 = UUT.uut.acq2sh('get.vin 33:64') vin3 = UUT.uut.acq2sh('get.vin 65:96') ans = eval('makeArray([%s, %s, %s])' % ( vin1, vin2, vin3, )) return ans def getInternalClock(self, UUT): clock_str = UUT.uut.acqcmd('getInternalClock').split()[0].split('=')[1] print("clock_str is -%s-" % clock_str) return eval('int(%s)' % clock_str) 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 STORE = store def help(self, arg): """ Help method to describe the methods and nodes of the DT196B module type """ help(DT196B) return 1 HELP = help def wait(self, arg): """ Wait method for dt216b module wait for the device to complete asynchronous data acquisition tasks """ cmd = "job_wait %s %d" % ( str(self.path).replace('\\', '\\\\'), self.tree.shot, ) pipe = os.popen(cmd) pipe.close() return 1 WAIT = wait
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 """ print "=========== ANUDEVICES SH edited dt132.py 13/06/2012 ===========" stall=os.getenv("Shaun_Stall") 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 complete2=0 tries2 = 0 #SHAUN MODIFICATION SO THAT IT CAN BE RUN IN A LOOP AND WILL STALL HERE UNTIL CARD GOES TO POSTPROCESS if stall=="YES": print "stall is yes" while complete2==0: if UUT.get_state().split()[-1] != "ST_STOP" : tries2 +=1 sleep(1) #print 'Still in run state' else: complete2=1 print 'Finished' #End Shaun Modification 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] print mask error="Clock source must be a string" #clock_src=self.clock_src.record.getOriginalPartName().getString()[1:] clock_src=str(self.clock_src.record)[-3:] #edit!! #print "clock_src:", clock_src error=None if clock_src == 'INT_CLOCK' : self.clock.record = Range(delta=1./self.getInternalClock(UUT)) else: self.clock.record = Range(delta=1./self.getInternalClock(UUT)) #TEST FOR 32MHZ clock!!! - getInternalCock is deceptively named - it also works for external clock and is the second value that is given when setting it #self.clock.record = Range(delta=1./self.clock_src.data()) #SHAUN EDIT!!!!! #SHAUN FAST DTACQ EDIT # if os.getenv('DTACQFAST')=='YES16' and boardip=='192.168.1.9': # self.clock.record = Range(delta=1./(16000000)) #SHAUN EDIT!!!!! # if os.getenv('DTACQFAST')=='YES32' and boardip=='192.168.1.9': # self.clock.record = Range(delta=1./(32000000)) #SHAUN EDIT!!!!! #print self.clock_src.data() #self.clock.record = self.clock_src clock = self.clock.record #print 'clock record being used is : '#SHAUN EDIT if debug: print "about to ask it to mdsconnect" #print "mdsConnect %s" % str(self.hostip.record) UUT.uut.acq2sh("mdsConnect %s" % str(self.hostip.record)) if debug: print "about to ask it to mdsopen" #print 'mdsOpen %s %d' % (self.boardip.tree.name, self.boardip.tree.shot,) UUT.uut.acq2sh('mdsOpen %s %d' % (self.boardip.tree.name, self.boardip.tree.shot,)) #SHAUN EDIT START mdsputchsent=0 #Remember if command has been sent - initialise to be 0 listofchannels="" #Initialise list of channels to be used by bulk command for spot in range(32):#Build list of channels to be used chan_node = self.__getattr__('input_%2.2d' % (spot+1,)) if chan_node.on: listofchannels=listofchannels + str(spot+1) + "," if listofchannels[len(listofchannels)-1]==",": #remove the last comma listofchannels=listofchannels[:len(listofchannels)-1] #Shaun edit for DTACQ Fast Sampling if os.getenv('DTACQFAST')=='YES16' and boardip=='192.168.1.9': listofchannels='1,5,17,21' if os.getenv('DTACQFAST')=='YES32' and boardip=='192.168.1.9': listofchannels='1,17' mdsputchbulkcommand=1 #switch to use bulk mdsputch or not #SHAUN EDIT END 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) 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" #!!!!!!!!!!!!!!! SHAUN MODIFIED THE FOLLOWING LINE (ADDED the +1 on the third argument to fix 1 more sample in time/data - ORIGINALLY WASN"T THERE - also replaced %%calsig with %%CAL to reduce complexity of the created tree - Boyd???) command = "mdsPutCh --field %s:raw --expr %%CAL --timebase %d,%d,%d %d" % (chan_node.getFullPath(), int(start-pre), int(end-pre)+1, int(inc), chan+1) command = command.replace('\\','\\\\') if debug: print "about to execute %s" % command #START Shaun EDIT TO USE MDSPUTCH TO DO LOTS OF CHANNELS (mdsputchbulkcommand decides if it is used) if mdsputchbulkcommand==1: if mdsputchsent==0: #Check to see if command has already been sent fieldstring=str(chan_node.getFullPath()) #building the string fieldstring=fieldstring[0:len(fieldstring)-2]+"%02d" #building the string bulkcommand = "mdsPutCh --field %s:raw --expr %%CAL --timebase %d,%d,%d %s" % (fieldstring, int(start-pre), int(end-pre)+1, int(inc), listofchannels) bulkcommand = bulkcommand.replace('\\','\\\\') print bulkcommand UUT.uut.acq2sh(bulkcommand) #send command mdsputchsent=1 #Remember the command has been sent else: UUT.uut.acq2sh(command) #ORIGINAL COMMAND #END SHAUN EDIT 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,))
class DT216A(Device): """ D-Tacq ACQ216 16 channel transient recorder """ parts = [ { 'path': ':NODE', 'type': 'text', 'value': '192.168.0.254', 'options': ('no_write_shot', ) }, { 'path': ':BOARD', 'type': 'text', 'value': '192.168.0.0', 'options': ('no_write_shot', ) }, { 'path': ':COMMENT', 'type': 'text' }, { 'path': ':RANGES', 'type': 'text', 'value': '192.168.0.0', 'options': ('write_once', ) }, { 'path': ':STATUS_CMDS', 'type': 'text', 'value': makeArray(['cat /proc/cmdline', 'get.d-tacq.release']), 'options': ('no_write_shot', ) }, { 'path': ':BOARD_STATUS', 'type': 'signal', 'options': ('write_shot', ) }, { 'path': ':SEG_LENGTH', 'type': 'numeric', 'options': ('no_write_shot', ) }, ] for i in range(6): parts.append({ 'path': ':DI%1.1d' % (i, ), 'type': 'axis', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:WIRE' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:BUS' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts2 = [ { 'path': ':CLOCK_SRC', 'type': 'text', 'value': 'INT', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_DIV', 'type': 'numeric', 'value': 1, 'options': ('no_write_shot', ) }, { 'path': ':DAQ_MEM', 'type': 'numeric', 'value': 512, 'options': ('no_write_shot', ) }, { 'path': ':ACTIVE_CHAN', 'type': 'numeric', 'value': 16, 'options': ('no_write_shot', ) }, { 'path': ':TRIG_SRC', 'type': 'text', 'value': 'DI3', 'options': ('no_write_shot', ) }, { 'path': ':POST_TRIG', 'type': 'numeric', 'value': 128, 'options': ('no_write_shot', ) }, { 'path': ':PRE_TRIG', 'type': 'numeric', 'value': 0, 'options': ('no_write_shot', ) }, ] parts.extend(parts2) del parts2 for i in range(16): parts.append({ 'path': ':INPUT_%2.2d' % (i + 1, ), 'type': 'signal', 'options': ( 'no_write_model', 'write_once', ) }) parts.append({ 'path': ':INPUT_%2.2d:STARTIDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:ENDIDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:INC' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:FILTER_COEFS' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:VIN' % (i + 1, ), 'type': 'NUMERIC', 'value': 10, 'options': ('no_write_shot') }) parts.append({ 'path': ':INIT_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','INIT',50,None),Method(None,'INITFTP',head))", 'options': ('no_write_shot', ) }) parts.append({ 'path': ':STORE_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','STORE',50,None),Method(None,'WAITFTP',head))", 'options': ('no_write_shot', ) }) trig_sources = [ 'DI0', 'DI1', 'DI2', 'DI3', 'DI4', 'DI5', ] clock_sources = trig_sources clock_sources.append('INT') clock_sources.append('MASTER') wires = ['fpga', 'mezz', 'rio', 'pxi', 'lemo', 'none', 'fpga pxi', ' '] del i def getPreTrig(self, str): parts = str.split('=') pre_trig = int(parts[2].split(' ')[0]) return pre_trig def getPostTrig(self, str): parts = str.split('=') post_trig = int(parts[3].split(' ')[0]) return post_trig def readRawData(self, name, pre, start, end, inc): # print "readRawData(self, %s, %d, %d, %d, %d)" % (name, pre, start, end, inc) f = open(name, mode='rb') try: f.seek((pre + start) * 2) binValues = array.array('H') binValues.read(f, end - start + 1) ans = numpy.array(binValues, dtype=numpy.int16) if inc > 1: asns = ans[::inc] f.close() except Exception, e: print "readRawData - %s" % e raise e return ans
class DT196A(Device): """ D-Tacq ACQ196 96 channel transient recorder """ parts=[ {'path':':NODE','type':'text','value':'192.168.0.254','options':('no_write_shot',)}, {'path':':BOARD','type':'text','value':'192.168.0.0','options':('no_write_shot',)}, {'path':':COMMENT','type':'text'}, ] for i in range(6): parts.append({'path':':DI%1.1d'%(i,),'type':'axis','options':('no_write_shot',)}) parts.append({'path':':DI%1.1d:WIRE'%(i,),'type':'text','options':('no_write_shot',)}) parts.append({'path':':DI%1.1d:BUS'%(i,),'type':'text','options':('no_write_shot',)}) parts2=[ {'path':':CLOCK_SRC','type':'text','value':'INT','options':('no_write_shot',)}, {'path':':CLOCK_DIV','type':'numeric','value':1,'options':('no_write_shot',)}, {'path':':DAQ_MEM','type':'numeric','value':512,'options':('no_write_shot',)}, {'path':':ACTIVE_CHAN','type':'numeric','value':96,'options':('no_write_shot',)}, {'path':':TRIG_SRC','type':'text','value':'DI3','options':('no_write_shot',)}, {'path':':POST_TRIG','type':'numeric','value':128,'options':('no_write_shot',)}, {'path':':PRE_TRIG','type':'numeric','value':0,'options':('no_write_shot',)}, {'path':':RANGES','type':'text','options':('write_once',)}, {'path':':STATUS_CMDS','type':'text','value':makeArray(['cat /proc/cmdline', 'get.d-tacq.release']),'options':('no_write_shot',)}, {'path':':BOARD_STATUS','type':'signal','options':('write_shot',)}, ] parts.extend(parts2) del parts2 for i in range(96): parts.append({'path':':INPUT_%2.2d'%(i+1,),'type':'signal','options':('no_write_model','write_once',)}) parts.append({'path':':INPUT_%2.2d:STARTIDX'%(i+1,),'type':'NUMERIC', 'options':('no_write_shot')}) parts.append({'path':':INPUT_%2.2d:ENDIDX'%(i+1,),'type':'NUMERIC', 'options':('no_write_shot')}) parts.append({'path':':INPUT_%2.2d:INC'%(i+1,),'type':'NUMERIC', 'options':('no_write_shot')}) parts.append({'path':':INPUT_%2.2d:FILTER_COEFS'%(i+1,),'type':'NUMERIC', 'options':('no_write_shot')}) parts.append({'path':':INPUT_%2.2d:RAW'%(i+1,),'type':'SIGNAL', 'options':('no_write_model','write_once')}) parts.append({'path':':INIT_ACTION','type':'action', 'valueExpr':"Action(Dispatch('CAMAC_SERVER','INIT',50,None),Method(None,'INITFTP',head))", 'options':('no_write_shot',)}) parts.append({'path':':STORE_ACTION','type':'action', 'valueExpr':"Action(Dispatch('CAMAC_SERVER','STORE',50,None),Method(None,'WAITFTP',head))", 'options':('no_write_shot',)}) trig_sources=[ 'DI0', 'DI1', 'DI2', 'DI3', 'DI4', 'DI5', ] clock_sources = trig_sources clock_sources.append('INT') clock_sources.append('MASTER') wires = [ 'fpga','mezz','rio','pxi','lemo', 'none', 'fpga pxi', ' '] del i def getPreTrig(self,str) : parts = str.split('=') pre_trig = int(parts[2].split(' ')[0]) return pre_trig def getPostTrig(self,str) : parts = str.split('=') post_trig = int(parts[3].split(' ')[0]) return post_trig def getBoardIp(self): try: boardip=str(self.node.record) if len(boardip) == 0 : raise Exception, "boardid record empty" except: try: print "trying to use the hub to get the ip" boardip=Dt200WriteMaster(int(self.board), "/sbin/ifconfig eth0 | grep 'inet addr'", 1)[0].split(':')[1].split()[0] except: raise Exception, "could not get board ip from either tree or hub" return boardip def readRawData(self, name, pre, start, end, inc) : # print "readRawData(self, %s, %d, %d, %d, %d)" % (name, pre, start, end, inc) f = open(name, mode='rb') try: f.seek((pre+start)*2) binValues = array.array('H') binValues.read(f,end-start+1) ans = numpy.array(binValues, dtype=numpy.int16) if inc > 1 : asns = ans[::inc] f.close() except Exception,e : print "readRawData - %s" % e raise e return ans
def test(): from numpy import array, int32 pytree = Tree('pytree', self.shot, 'ReadOnly') top = TreeNode(0, pytree) members = pytree.getNodeWild(':*') self.assertEqual((members == top.member_nids).all(), True) self.assertEqual((members == top.getMembers()).all(), True) self.assertEqual(top.member.nid_number, members[0].nid_number) member = top.member for idx in range(1, len(members)): self.assertEqual(member.brother.nid_number, members[idx].nid_number) member = member.brother children = pytree.getNodeWild('.*') self.assertEqual((children == top.children_nids).all(), True) self.assertEqual((children == top.getChildren()).all(), True) self.assertEqual(top.child.nid_number, children[0].nid_number) child = top.child for idx in range(1, len(children)): self.assertEqual(child.brother.nid_number, children[idx].nid_number) child = child.brother self.assertEqual(top.child.nid_number, pytree.getNode(str(top.child)).nid_number) self.assertEqual(top.child.child.parent.nid_number, top.child.nid_number) x = array(int32(0)).repeat(len(members) + len(children)) x[0:len(children)] = children.nid_number.data() x[len(children):] = members.nid_number.data() self.assertEqual( (makeArray(x) == top.descendants.nid_number).all(), True) self.assertEqual( (top.descendants.nid_number == top.getDescendants().nid_number ).all(), True) self.assertEqual(top.child.child.depth, 3) self.assertEqual(top.getNumDescendants(), len(x)) self.assertEqual(top.getNumMembers(), len(members)) self.assertEqual(top.getNumChildren(), len(children)) self.assertEqual(top.number_of_members, len(members)) self.assertEqual(top.number_of_children, len(children)) self.assertEqual(top.number_of_descendants, len(x)) devs = pytree.getNodeWild('\\PYTREESUB::TOP.***', 'DEVICE') dev = devs[0].conglomerate_nids self.assertEqual( (dev.nid_number == devs[0].getConglomerateNodes().nid_number ).all(), True) self.assertEqual( (dev.conglomerate_elt == makeArray(array(range(len(dev))) + 1)).all(), True) for idx in range(len(dev)): self.assertEqual(dev[idx].conglomerate_elt, idx + 1) self.assertEqual(dev[idx].getConglomerateElt(), idx + 1) self.assertEqual(top.child.is_child, True) self.assertEqual(top.child.is_member, False) self.assertEqual(top.member.is_child, False) self.assertEqual(top.member.is_member, True) self.assertEqual(top.child.is_child, top.child.isChild()) self.assertEqual(top.child.is_member, top.child.isMember()) ip = pytree.getNode('\\ip') pytree.setDefault(ip) self.assertEqual(ip.fullpath, "\\PYTREE::TOP.PYTREESUB:IP") self.assertEqual(ip.fullpath, ip.getFullPath()) self.assertEqual(ip.minpath, "\\IP") self.assertEqual(ip.minpath, ip.getMinPath()) self.assertEqual(ip.node_name, 'IP') self.assertEqual(ip.node_name, ip.getNodeName()) self.assertEqual(ip.path, "\\PYTREESUB::IP") self.assertEqual(ip.path, ip.getPath())
def test(): pytree = Tree('pytree', self.shot, 'ReadOnly') ip = pytree.getNode('\\ip') self.assertEqual(ip.getUsage(), 'SIGNAL') self.assertEqual(ip.usage, ip.getUsage()) try: # do not continue and print when no match self.assertEqual(ip.getClass(), 'CLASS_R') except AssertionError: print("ip.nid=%d" % (ip.nid, )) print("Error with ip in %s" % (str(ip.tree), )) raise self.assertEqual(ip.class_str, 'CLASS_R') self.assertEqual(ip.compressible, False) self.assertEqual(ip.compressible, ip.isCompressible()) self.assertEqual(ip.compress_on_put, True) self.assertEqual(ip.compress_on_put, ip.isCompressOnPut()) self.assertEqual(ip.data_in_nci, False) self.assertEqual(ip.on, True) self.assertEqual(ip.on, ip.isOn()) self.assertEqual(ip.do_not_compress, False) self.assertEqual(ip.do_not_compress, ip.isDoNotCompress()) self.assertEqual(ip.dtype_str, 'DTYPE_SIGNAL') self.assertEqual(ip.dtype_str, ip.getDtype()) self.assertEqual(ip.essential, False) self.assertEqual(ip.essential, ip.isEssential()) mhdtree = pytree.getNode('\\PYTREESUB::TOP') self.assertEqual(mhdtree.include_in_pulse, True) self.assertEqual(mhdtree.include_in_pulse, mhdtree.isIncludeInPulse()) self.assertEqual(ip.length, int(Data.execute('getnci($,"LENGTH")', ip))) self.assertEqual(ip.length, ip.getLength()) self.assertEqual(ip.no_write_shot, False) self.assertEqual(ip.no_write_shot, ip.isNoWriteShot()) self.assertEqual(ip.no_write_model, False) self.assertEqual(ip.no_write_model, ip.isNoWriteModel()) self.assertEqual(ip.write_once, False) self.assertEqual(ip.write_once, ip.isWriteOnce()) pydev = pytree.TESTDEVICE part = pydev.conglomerate_nids[1] self.assertEqual(part.PART_NAME(), ':ACTIONSERVER') self.assertEqual(part.original_part_name, ':ACTIONSERVER') self.assertEqual( str(Data.execute('GETNCI($,"ORIGINAL_PART_NAME")', part)), ':ACTIONSERVER') self.assertEqual(pydev.__class__, Device.PyDevice('TestDevice')) devs = pytree.getNodeWild('\\PYTREESUB::TOP.***', 'DEVICE') part = devs[0].conglomerate_nids[3] self.assertEqual(part.original_part_name, ':COMMENT') self.assertEqual( part.original_part_name, str(Data.execute('GETNCI($,"ORIGINAL_PART_NAME")', part))) self.assertEqual(ip.owner_id, ip.getOwnerId()) self.assertEqual(ip.rlength, 168) self.assertEqual(ip.rlength, ip.getCompressedLength()) self.assertEqual(ip.setup_information, False) self.assertEqual(ip.setup_information, ip.isSetup()) self.assertEqual(ip.status, 0) self.assertEqual(ip.status, ip.getStatus()) self.assertEqual((ip.tags == makeArray([ 'IP', 'MAGNETICS_IP', 'MAG_IP', 'MAGNETICS_PLASMA_CURRENT', 'MAG_PLASMA_CURRENT' ])).all(), True) self.assertEqual((ip.tags == ip.getTags()).all(), True) self.assertEqual(ip.time_inserted, ip.getTimeInserted())
def storeftp(self, arg): debug=os.getenv("DEBUG_DEVICES") path = self.local_path tree = self.local_tree shot = self.tree.shot CPCIDataDir = os.getenv('CPCI_DATA_DIR') if not CPCIDataDir: raise 'CPCI_DATA_DIR environment variable must be defined' dataDir="%s/%s/%s/%s"%(CPCIDataDir, tree, shot, path,) try : settingsf = open("%s/settings.xml"%(dataDir,), "r") except : raise Exception,"Could not open Settings file %s/settings.xml"%(dataDir,) try : settings = load(settingsf) except: settingsf.close() raise Exception, "Could not parse XML settings" settingsf.close() numSampsStr = settings['getNumSamples'] preTrig = self.getPreTrig(numSampsStr) postTrig = self.getPostTrig(numSampsStr) # vins = makeArray(numpy.array(settings['get.vin'].split(',')).astype('float')) range_strs = settings['getVoltsRange'].split()[1].split('=')[1].split(',') range_strs[0] = range_strs[0][:-1] range_strs[1] = range_strs[1][:-1] vins = makeArray(numpy.array(range_strs).astype('float32')) coefficent = (vins[1]-vins[0])/(2**16-1) chanMask = settings['getChannelMask'].split('=')[-1] if not 'ACTIVE' in settings['get.ext_clk'] : #intClkStr=settings['getInternalClock'].split()[0].split('=')[1] #intClock=int(intClikStr) intClock = float(settings['getInternalClock'].split()[1]) delta=1./float(intClock) else: delta = 0 #trigExpr = 'self.%s'% str(self.trig_src.record) #trig_src = eval(trigExpr.lower()) trig_src = self.__getattr__(str(self.trig_src.record).lower()) # # now store each channel # for chan in range(16): if debug: print "working on channel %d" % chan #chan_node = eval('self.input_%2.2d' % (chan+1,)) chan_node = self.__getattr__('input_%2.2d' % (chan+1,)) if chan_node.on : if debug: print "it is on so ..." if chanMask[chan:chan+1] == '1' : try: #start = max(eval('int(self.input_%2.2d:start_idx)'%(chan+1,)), preTrig) start = max(int(self.__getattr__('input_%2.2d_startidx'%(chan+1,))),-preTrig) except: start = -preTrig try: #end = min(eval('int(self.input_%2.2d:end_idx)'%(chan+1,)), postTrig) end = min(int(self.__getattr__('input_%2.2d_endidx'%(chan+1,))),postTrig-1) except: end = postTrig-1 try: #inc = max(eval('int(self.input_%2.2d:inc)'%(chan+1,)), 1) inc = max(int(self.__getattr__('input_%2.2d_inc'%(chan+1,))),1) except: inc = 1 # # could do the coeffs # chanFileName="%s/%2.2d"%(dataDir, chan+1,) buf = self.readRawData(chanFileName, preTrig, start, end, inc) # try: # buf = self.readRawData(chanFileName, start, end, inc) # except: # print "Error Reading Channel %d"%(chan+1,) if delta != 0 : axis = Range(None, None, delta/inc) else: #clockExpr = 'self.%s'% str(self.clock_src.record) #clock_src = eval(clockExpr.lower()) clock_src = self.__getattr__(str(self.clock_src.record).lower()) axis = clock_src if inc == 1: dim = Dimension(Window(start, end, trig_src ), axis) else: dim = Data.compile('Map($,$)', Dimension(Window(start/inc, end/inc, trig_src), axis), Range(start, end, inc)) dat = Data.compile('build_signal(build_with_units( $*(0. + $value), "V") ,build_with_units($,"Counts"),$)', coefficent, buf,dim) exec('c=self.input_'+'%02d'%(chan+1,)+'.record=dat') 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: 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,))
class DT132(Device): """ D-Tacq ACQ132 32 channel transient recorder Methods: Add() - add a DTAO32 device to the tree open for edit Init(arg) - initialize the DTAO32 device write setup parameters and waveforms to the device Store(arg) - store the data acquired by the device Help(arg) - print this message Nodes: :HOSTIP - mdsip address of the host storing the data. Usually 192.168.0.254:8106 BOARDIP'- ip addres sof the card as a string something like 192.168.0.40 COMMENT - user comment string DI[0-5] - time(s) of the signal on this internal wire (trig reference or clock reference) :wire - string specifying the source of this signal { 'fpga','mezz','rio','pxi','lemo', 'none } :bus - string specifying the destination of this signal { 'fpga','rio','pxi', 'none } :ACTIVE_CHANS - number of active channels {8, 16, 32} INT_CLOCK - stored by module (representation of internal clock TRIG_SRC - reference to DIn line used for trigger (DI3) TRIG_EDGE - string {rising, falling} CLOCK_SRC - reference to line (DIn) used for clock or INT_CLOCK CLOCK_DIV - NOT CURRENTLY IMPLIMENTED CLOCK_EDGE - string {rising, falling} CLOCK_FREQ - frequency for internal clock PRE_TRIG - pre trigger samples MUST BE ZERO FOR NOW POST_TRIG - post trigger samples SEGMENTS - number of segments to store data in NOT IMPLIMENTED FOR NOW CLOCK - Filled in by store place for module to store clock information RANGES - place for module to store calibration information STATUS_CMDS - array of shell commands to send to the module to record firmware version etc BOARD_STATUS - place for module to store answers for STATUS_CMDS as signal INPUT_[01-32] - place for module to store data in volts (reference to INPUT_NN:RAW) :RAW - place for module to store raw data in volts for each channel START_IDX - first sample to store for this channel END_IDX - last sample to store for this channel INC - decimation factor for this channel INIT_ACTION - dispatching information for INIT STORE_ACTION - dispatching information for STORE """ parts = [ { 'path': ':HOSTIP', 'type': 'text', 'value': '192.168.0.254', 'options': ('no_write_shot', ) }, { 'path': ':BOARDIP', 'type': 'text', 'value': '192.168.0.0', 'options': ('no_write_shot', ) }, { 'path': ':COMMENT', 'type': 'text' }, ] for i in range(6): parts.append({ 'path': ':DI%1.1d' % (i, ), 'type': 'numeric', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:BUS' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:WIRE' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts2 = [ { 'path': ':ACTIVE_CHANS', 'type': 'numeric', 'value': 32, 'options': ('no_write_shot', ) }, { 'path': ':INT_CLOCK', 'type': 'axis', 'options': ('no_write_model', 'write_once') }, { 'path': ':TRIG_SRC', 'type': 'numeric', 'valueExpr': 'head.di3', 'options': ('no_write_shot', ) }, { 'path': ':TRIG_EDGE', 'type': 'text', 'value': 'rising', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_SRC', 'type': 'numeric', 'valueExpr': 'head.int_clock', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_DIV', 'type': 'numeric', 'value': 1, 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_EDGE', 'type': 'text', 'value': 'rising', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_FREQ', 'type': 'numeric', 'value': 1000000, 'options': ('no_write_shot', ) }, { 'path': ':PRE_TRIG', 'type': 'numeric', 'value': 0, 'options': ('no_write_shot', ) }, { 'path': ':POST_TRIG', 'type': 'numeric', 'value': 128, 'options': ('no_write_shot', ) }, { 'path': ':SEGMENTS', 'type': 'numeric', 'value': 1, 'options': ('no_write_shot', ) }, { 'path': ':CLOCK', 'type': 'axis', 'options': ('no_write_model', 'write_once') }, { 'path': ':RANGES', 'type': 'numeric', 'options': ('no_write_model', 'write_once') }, { 'path': ':STATUS_CMDS', 'type': 'text', 'value': makeArray(['cat /proc/cmdline', 'get.d-tacq.release']), 'options': ('no_write_shot', ) }, { 'path': ':BOARD_STATUS', 'type': 'SIGNAL', 'options': ('no_write_model', 'write_once') }, ] parts.extend(parts2) del parts2 for i in range(32): parts.append({ 'path': ':INPUT_%2.2d' % (i + 1, ), 'type': 'signal', 'options': ( 'no_write_model', 'write_once', ) }) parts.append({ 'path': ':INPUT_%2.2d:RAW' % (i + 1, ), 'type': 'SIGNAL', 'options': ('no_write_model', 'write_once') }) parts.append({ 'path': ':INPUT_%2.2d:START_IDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:END_IDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:INC' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INIT_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','INIT',50,None),Method(None,'INIT',head))", 'options': ('no_write_shot', ) }) parts.append({ 'path': ':STORE_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','STORE',50,None),Method(None,'STORE',head))", 'options': ('no_write_shot', ) }) clock_edges = ['rising', 'falling'] trigger_edges = clock_edges trig_sources = [ 'DI0', 'DI1', 'DI2', 'DI3', 'DI4', 'DI5', ] clock_sources = trig_sources clock_sources.append('INT_CLOCK') masks = { 8: '11110000000000001111000000000000', 16: '11111111000000001111111100000000', 32: '11111111111111111111111111111111', } wires = ['fpga', 'mezz', 'rio', 'pxi', 'lemo', 'none', 'fpga pxi'] del i 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 = str(self.trig_src.record.getOriginalPartName())[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 = str(self.clock_src.record.getOriginalPartName())[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 as e: if error is not None: e = error print("%s\n" % (str(e), )) return 0 INIT = init def getVins(self, UUT): vins = UUT.uut.acq2sh('get.vin 1:32') vins = vins[0] vins = vins[:-1] return makeArray(numpy.array(vins.split()).astype('int')) def getInternalClock(self, UUT): clock_str = UUT.uut.acqcmd('getInternalClock').split()[0].split('=')[1] print("clock_str is -%s-" % clock_str) freq = int(clock_str) if freq > 16000000: freq = 2000000 return freq 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: 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 = str(self.clock_src.record.getOriginalPartName())[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, self.trig_src) dim = Dimension(window, axis) else: dim = Data.Compile( 'Map($,$)', Dimension( Window(start / inc, end / inc, self.trig_src), 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, )) except Exception as e: if error is not None: e = error print("Error storing DT132 Device\n%s" % (str(e), )) return 0 return 1 STORE = store def help(self, arg): """ Help method to describe the methods and nodes of the DTAO32 module type """ help(DT132) 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: 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 storeftp(self, arg): debug=os.getenv("DEBUG_DEVICES") path = self.local_path tree = self.local_tree shot = self.tree.shot CPCIDataDir = os.getenv('CPCI_DATA_DIR') if not CPCIDataDir: raise 'CPCI_DATA_DIR environment variable must be defined' dataDir="%s/%s/%s/%s"%(CPCIDataDir, tree, shot, path,) try : settingsf = open("%s/settings.xml"%(dataDir,), "r") except : raise Exception,"Could not open Settings file %s/settings.xml"%(dataDir,) try : settings = load(settingsf) except: settingsf.close() raise Exception, "Could not parse XML settings" settingsf.close() if debug : print "xml is loaded\n" status = [] cmds = self.status_cmds.record for cmd in cmds: cmd = cmd.strip() if debug: print "about to append answer for /%s/\n" % (cmd,) print " which is /%s/\n" %(settings[cmd],) status.append(settings[cmd]) if debug: print "%s returned %s\n" % (cmd, settings[cmd],) if debug: print "about to write board_status signal" self.board_status.record = Signal(cmds, None, status) numSampsStr = settings['getNumSamples'] preTrig = self.getPreTrig(numSampsStr) postTrig = self.getPostTrig(numSampsStr) vins = makeArray(numpy.array(settings['get.vin'].split(',')).astype('float')) self.ranges.record = vins chanMask = settings['getChannelMask'].split('=')[-1] if self.clock_src.record.lower() == 'int' or self.clock_src.record.lower() == 'master': #intClkStr=settings['getInternalClock'].split()[0].split('=')[1] #intClock=int(intClikStr) intClock = float(settings['getInternalClock'].split()[1]) delta=1./float(intClock) else: delta = 0 trig_src = self.__getattr__(str(self.trig_src.record).lower()) # # now store each channel # for chan in range(96): if debug: print "working on channel %d" % chan #chan_node = eval('self.input_%2.2d' % (chan+1,)) chan_node = self.__getattr__('input_%2.2d' % (chan+1,)) if chan_node.on : if debug: print "it is on so ..." if chanMask[chan:chan+1] == '1' : try: start = max(int(self.__getattr__('input_%2.2d_startidx'%(chan+1,))),-preTrig) except: start = -preTrig try: end = min(int(self.__getattr__('input_%2.2d_endidx'%(chan+1,))),postTrig-1) except: end = postTrig-1 try: inc = max(int(self.__getattr__('input_%2.2d_inc'%(chan+1,))),1) except: inc = 1 # # could do the coeffs # chanFileName="%s/%2.2d"%(dataDir, chan+1,) buf = self.readRawData(chanFileName, preTrig, start, end, inc) if delta != 0 : axis = Range(None, None, delta/inc) else: #clockExpr = 'self.%s'% str(self.clock_src.record) #clock_src = eval(clockExpr.lower()) clock_src = self.__getattr__(str(self.clock_src.record).lower()) axis = clock_src if inc == 1: dim = Dimension(Window(start, end, trig_src ), axis) else: dim = Data.compile('Map($,$)', Dimension(Window(start/inc, end/inc, trig_src), axis), Range(start, end, inc)) # dat = Data.compile('build_signal(build_with_units( $*(0. + $value), "V") ,build_with_units($,"Counts"),$)', coefficent, buf,dim) dat = Data.compile('_v0=$, _v1=$, build_signal(build_with_units(( _v0+ (_v1-_v0)*($value - -32768)/(32767 - -32768 )), "V") ,build_with_units($,"Counts"),$)', vins[chan*2], vins[chan*2+1], buf,dim) exec('c=self.input_'+'%02d'%(chan+1,)+'.record=dat') return 1
def storeftp(self, arg): try: from xml.marshal.generic import dumps, loads, load except: print( "you must install PyXML to use this deprecated device. Please switch to acq216 device type" ) debug = self.debug path = self.local_path tree = self.local_tree shot = self.tree.shot CPCIDataDir = os.getenv('CPCI_DATA_DIR') if not CPCIDataDir: raise 'CPCI_DATA_DIR environment variable must be defined' dataDir = "%s/%s/%s/%s" % ( CPCIDataDir, tree, shot, path, ) try: settingsf = open("%s/settings.xml" % (dataDir, ), "r") except: raise Exception("Could not open Settings file %s/settings.xml" % (dataDir, )) try: settings = load(settingsf) except: settingsf.close() raise Exception("Could not parse XML settings") settingsf.close() numSampsStr = settings['getNumSamples'] preTrig = self.getPreTrig(numSampsStr) postTrig = self.getPostTrig(numSampsStr) # vins = makeArray(numpy.array(settings['get.vin'].split(',')).astype('float')) range_strs = settings['getVoltsRange'].split()[1].split('=')[1].split( ',') range_strs[0] = range_strs[0][:-1] range_strs[1] = range_strs[1][:-1] vins = makeArray(numpy.array(range_strs).astype('float32')) coefficent = (vins[1] - vins[0]) / (2**16 - 1) chanMask = settings['getChannelMask'].split('=')[-1] if not 'ACTIVE' in settings['get.ext_clk']: #intClkStr=settings['getInternalClock'].split()[0].split('=')[1] #intClock=int(intClikStr) intClock = float(settings['getInternalClock'].split()[1]) delta = 1. / float(intClock) else: delta = 0 #trigExpr = 'self.%s'% str(self.trig_src.record) #trig_src = eval(trigExpr.lower()) trig_src = self.__getattr__(str(self.trig_src.record).lower()) # # now store each channel # for chan in range(16): if debug: print("working on channel %d" % chan) #chan_node = eval('self.input_%2.2d' % (chan+1,)) chan_node = self.__getattr__('input_%2.2d' % (chan + 1, )) if chan_node.on: if debug: print("it is on so ...") if chanMask[chan:chan + 1] == '1': try: #start = max(eval('int(self.input_%2.2d:start_idx)'%(chan+1,)), preTrig) start = max( int( self.__getattr__('input_%2.2d_startidx' % (chan + 1, ))), -preTrig) except: start = -preTrig try: #end = min(eval('int(self.input_%2.2d:end_idx)'%(chan+1,)), postTrig) end = min( int( self.__getattr__('input_%2.2d_endidx' % (chan + 1, ))), postTrig - 1) except: end = postTrig - 1 try: #inc = max(eval('int(self.input_%2.2d:inc)'%(chan+1,)), 1) inc = max( int( self.__getattr__('input_%2.2d_inc' % (chan + 1, ))), 1) except: inc = 1 # # could do the coeffs # chanFileName = "%s/%2.2d" % ( dataDir, chan + 1, ) buf = self.readRawData(chanFileName, preTrig, start, end, inc) # try: # buf = self.readRawData(chanFileName, start, end, inc) # except: # print "Error Reading Channel %d"%(chan+1,) if delta != 0: axis = Range(None, None, delta / inc) else: #clockExpr = 'self.%s'% str(self.clock_src.record) #clock_src = eval(clockExpr.lower()) clock_src = self.__getattr__( str(self.clock_src.record).lower()) axis = clock_src if inc == 1: dim = Dimension(Window(start, end, trig_src), axis) else: dim = Data.compile( 'Map($,$)', Dimension(Window(start / inc, end / inc, trig_src), axis), Range(start, end, inc)) dat = Data.compile( 'build_signal(build_with_units( $*(0. + $value), "V") ,build_with_units($,"Counts"),$)', coefficent, buf, dim) exec('c=self.input_' + '%02d' % (chan + 1, ) + '.record=dat') return 1
class DT216A(Device): """ D-Tacq ACQ216 16 channel transient recorder """ parts = [ { 'path': ':NODE', 'type': 'text', 'value': '192.168.0.254', 'options': ('no_write_shot', ) }, { 'path': ':BOARD', 'type': 'text', 'value': '192.168.0.0', 'options': ('no_write_shot', ) }, { 'path': ':COMMENT', 'type': 'text' }, { 'path': ':RANGES', 'type': 'text', 'value': '192.168.0.0', 'options': ('write_once', ) }, { 'path': ':STATUS_CMDS', 'type': 'text', 'value': makeArray(['cat /proc/cmdline', 'get.d-tacq.release']), 'options': ('no_write_shot', ) }, { 'path': ':BOARD_STATUS', 'type': 'signal', 'options': ('write_shot', ) }, { 'path': ':SEG_LENGTH', 'type': 'numeric', 'options': ('no_write_shot', ) }, ] for i in range(6): parts.append({ 'path': ':DI%1.1d' % (i, ), 'type': 'axis', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:WIRE' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts.append({ 'path': ':DI%1.1d:BUS' % (i, ), 'type': 'text', 'options': ('no_write_shot', ) }) parts2 = [ { 'path': ':CLOCK_SRC', 'type': 'text', 'value': 'INT', 'options': ('no_write_shot', ) }, { 'path': ':CLOCK_DIV', 'type': 'numeric', 'value': 1, 'options': ('no_write_shot', ) }, { 'path': ':DAQ_MEM', 'type': 'numeric', 'value': 512, 'options': ('no_write_shot', ) }, { 'path': ':ACTIVE_CHAN', 'type': 'numeric', 'value': 16, 'options': ('no_write_shot', ) }, { 'path': ':TRIG_SRC', 'type': 'text', 'value': 'DI3', 'options': ('no_write_shot', ) }, { 'path': ':POST_TRIG', 'type': 'numeric', 'value': 128, 'options': ('no_write_shot', ) }, { 'path': ':PRE_TRIG', 'type': 'numeric', 'value': 0, 'options': ('no_write_shot', ) }, ] parts.extend(parts2) del parts2 for i in range(16): parts.append({ 'path': ':INPUT_%2.2d' % (i + 1, ), 'type': 'signal', 'options': ( 'no_write_model', 'write_once', ) }) parts.append({ 'path': ':INPUT_%2.2d:STARTIDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:ENDIDX' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:INC' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:FILTER_COEFS' % (i + 1, ), 'type': 'NUMERIC', 'options': ('no_write_shot') }) parts.append({ 'path': ':INPUT_%2.2d:VIN' % (i + 1, ), 'type': 'NUMERIC', 'value': 10, 'options': ('no_write_shot') }) parts.append({ 'path': ':INIT_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','INIT',50,None),Method(None,'INITFTP',head))", 'options': ('no_write_shot', ) }) parts.append({ 'path': ':STORE_ACTION', 'type': 'action', 'valueExpr': "Action(Dispatch('CAMAC_SERVER','STORE',50,None),Method(None,'WAITFTP',head))", 'options': ('no_write_shot', ) }) trig_sources = [ 'DI0', 'DI1', 'DI2', 'DI3', 'DI4', 'DI5', ] clock_sources = trig_sources clock_sources.append('INT') clock_sources.append('MASTER') wires = ['fpga', 'mezz', 'rio', 'pxi', 'lemo', 'none', 'fpga pxi', ' '] del i def getPreTrig(self, str): parts = str.split('=') pre_trig = int(parts[2].split(' ')[0]) return pre_trig def getPostTrig(self, str): parts = str.split('=') post_trig = int(parts[3].split(' ')[0]) return post_trig def readRawData(self, name, pre, start, end, inc): # print "readRawData(self, %s, %d, %d, %d, %d)" % (name, pre, start, end, inc) f = open(name, mode='rb') try: f.seek((pre + start) * 2) binValues = array.array('H') binValues.read(f, end - start + 1) ans = numpy.array(binValues, dtype=numpy.int16) if inc > 1: asns = ans[::inc] f.close() except Exception as e: print("readRawData - %s" % e) raise e return ans def check(self, expression, message): try: ans = eval(expression) return ans except: raise Exception(message) def getBoardIp(self): try: boardip = str(self.node.record) if len(boardip) == 0: raise Exception("boardid record empty") except: try: print("trying to use the hub to get the ip") boardip = Dt200WriteMaster( int(self.board), "/sbin/ifconfig eth0 | grep 'inet addr'", 1)[0].split(':')[1].split()[0] except: raise Exception( "could not get board ip from either tree or hub") return boardip def timeoutHandler(self, sig, stack): raise Exception("Timeout occurred") def getState(self): """Get the current state""" import socket, signal s = socket.socket() state = "Unknown" try: signal.signal(signal.SIGALRM, self.timeoutHandler) signal.alarm(60) s.connect((self.getBoardIp(), 54545)) state = s.recv(100)[0:-1] except Exception as e: print("Error getting board state: %s" % (str(e), )) signal.alarm(0) s.close() return state def doInit(self, tree, shot, path): """Get the current state""" import socket, signal status = 1 s = socket.socket() try: signal.signal(signal.SIGALRM, self.timeoutHandler) signal.alarm(15) s.connect((self.getBoardIp(), 54546)) s.send("%s %d %s" % (tree, shot, path)) except Exception as e: status = 0 print("Error sending doInit: %s" % (str(e), )) signal.alarm(0) s.close() return status def initftp(self, arg): """ Initialize the device Send parameters Arm hardware """ start = time() msg = None debug = os.getenv("DEBUG_DEVICES") try: path = self.local_path tree = self.local_tree shot = self.tree.shot msg = "Must specify active chans as int in (2,4,8,16)" #active_chans = self.check("int(self.active_chans)", "Must specify active chans as int in (32,64,16)") active_chan = int(self.active_chan) msg = None if active_chan not in (2, 4, 8, 16): print("active chans must be in (2, 4, 8, 16 )") active_chan = 16 msg = "Could not read trigger source" #trig_src=self.check("str(self.trig_src.record)", "Could not read trigger source") trig_src = str(self.trig_src.record) msg = None if not trig_src in self.trig_sources: raise Exception("Trig_src must be in %s" % str(self.trig_sources)) msg = "Could not read clock source" #clock_src=self.check("str(self.clock_src.record)", "Could not read clock source") clock_src = str(self.clock_src.record) msg = None if not clock_src in self.clock_sources: raise Exception("clock_src must be in %s" % str(self.clock_sources)) msg = "Must specify pre trigger samples" #pre_trig=self.check('int(self.pre_trig.data()*1024)', "Must specify pre trigger samples") pre_trig = int(self.pre_trig.data() * 1024) msg = "Must specify post trigger samples" #post_trig=self.check('int(self.post_trig.data()*1024)', "Must specify post trigger samples") post_trig = int(self.post_trig.data() * 1024) msg = None if clock_src == "INT" or clock_src == "MASTER": msg = "Must specify clock frequency in clock_div node for internal clock" #clock_freq = self.check('int(self.clock_div)', "Must specify clock frequency in clock_div node for internal clock") clock_freq = int(self.clock_div) msg = None else: try: clock_div = int(self.clock_div) except: clock_div = 1 # # now create the post_shot ftp command file # fname = "/home/mdsftp/scratch/%s_%s_%s.sh" % (tree, shot, path) fd = open(fname, 'w') for i in range(6): line = 'd%1.1d' % i try: #wire = eval('str(self.di%1.1d_wire.record)' %i) 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 = eval('str(self.di%1.1d_bus.record)' % i) 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 = '' fd.write("set.route %s in %s out %s\n" % ( line, wire, bus, )) fd.write("acqcmd setChannelMask " + '1' * active_chan + "\n") if clock_src == 'INT' or clock_src == 'MASTER': fd.write("acqcmd setInternalClock %d\n" % clock_freq) if clock_src == 'MASTER': fd.write("acqcmd '-- setDIO -1-----'\n") # NOTE existing modules may have clock_div filled in with the desired freq even # though it is external clock. # for now IGNORE # # else: # if (clock_div != 1) : # fd.write("acqcmd setExternalClock %s %d DO2\n" % (clock_src, clock_div,)) # # the following is not generic # the clock is output on d2 and comes from DI0 # fd.write("set.route d2 in fpga out pxi\n") fd.write("acqcmd '-- setDIO --1-----'\n") fd.write("set.ext_clk DI0\n") else: fd.write("acqcmd setExternalClock %s\n" % clock_src) for chan in range(16): fd.write( "set.vin %d %d\n" % (chan + 1, int(self.__getattr__('input_%2.2d_vin' % (chan + 1, ))))) fd.write("set.pre_post_mode %d %d %s %s\n" % ( pre_trig, post_trig, trig_src, 'rising', )) fd.write(". /usr/local/bin/xmlfunctions.sh\n") fd.write("settingsf=/tmp/%s_%s_%s.xml\n" % ( tree, shot, path, )) cmds = self.status_cmds.record for cmd in cmds: cmd = cmd.strip() if debug: print('adding /xmlcmd "%s" >> $settingsf/ to the file.\n' % (cmd, )) fd.write('xmlcmd "%s" >> $settingsf\n' % (cmd, )) fd.flush() fd.close() print("Time to make init file = %g\n" % (time() - start)) start = time() self.doInit(tree, shot, path) print("Time for board to init = %g\n" % (time() - start)) return 1 except Exception as e: print("%s\n" % (str(e), )) return 0 INITFTP = initftp def storeftp(self, arg): try: from xml.marshal.generic import dumps, loads, load except: print( "you must install PyXML to use this deprecated device. Please switch to acq216 device type" ) debug = os.getenv("DEBUG_DEVICES") path = self.local_path tree = self.local_tree shot = self.tree.shot CPCIDataDir = os.getenv('CPCI_DATA_DIR') if not CPCIDataDir: raise 'CPCI_DATA_DIR environment variable must be defined' dataDir = "%s/%s/%s/%s" % ( CPCIDataDir, tree, shot, path, ) try: settingsf = open("%s/settings.xml" % (dataDir, ), "r") except: raise Exception("Could not open Settings file %s/settings.xml" % (dataDir, )) try: settings = load(settingsf) except: settingsf.close() raise Exception("Could not parse XML settings") settingsf.close() if debug: print("xml is loaded\n") status = [] cmds = self.status_cmds.record for cmd in cmds: cmd = cmd.strip() if debug: print("about to append answer for /%s/\n" % (cmd, )) print(" which is /%s/\n" % (settings[cmd], )) status.append(settings[cmd]) if debug: print("%s returned %s\n" % ( cmd, settings[cmd], )) if debug: print("about to write board_status signal") self.board_status.record = Signal(cmds, None, status) numSampsStr = settings['getNumSamples'] preTrig = self.getPreTrig(numSampsStr) postTrig = self.getPostTrig(numSampsStr) vins = makeArray( numpy.array(settings['get.vin'].split(',')).astype('float')) self.ranges.record = vins chanMask = settings['getChannelMask'].split('=')[-1] if self.clock_src.record.lower( ) == 'int' or self.clock_src.record.lower() == 'master': #intClkStr=settings['getInternalClock'].split()[0].split('=')[1] #intClock=int(intClikStr) intClock = float(settings['getInternalClock'].split()[1]) delta = 1. / float(intClock) else: delta = 0 trig_src = self.__getattr__(str(self.trig_src.record).lower()) # # now store each channel # for chan in range(16): if debug: print("working on channel %d" % chan) #chan_node = eval('self.input_%2.2d' % (chan+1,)) chan_node = self.__getattr__('input_%2.2d' % (chan + 1, )) if chan_node.on: if debug: print("it is on so ...") if chanMask[chan:chan + 1] == '1': try: start = max( int( self.__getattr__('input_%2.2d_startidx' % (chan + 1, ))), -preTrig) except: start = -preTrig try: end = min( int( self.__getattr__('input_%2.2d_endidx' % (chan + 1, ))), postTrig - 1) except: end = postTrig - 1 try: inc = max( int( self.__getattr__('input_%2.2d_inc' % (chan + 1, ))), 1) except: inc = 1 # # could do the coeffs # chanFileName = "%s/%2.2d" % ( dataDir, chan + 1, ) buf = self.readRawData(chanFileName, preTrig, start, end, inc) if delta != 0: axis = Range(None, None, delta / inc) else: #clockExpr = 'self.%s'% str(self.clock_src.record) #clock_src = eval(clockExpr.lower()) clock_src = self.__getattr__( str(self.clock_src.record).lower()) axis = clock_src if inc == 1: dim = Dimension(Window(start, end, trig_src), axis) else: dim = Data.compile( 'Map($,$)', Dimension(Window(start / inc, end / inc, trig_src), axis), Range(start, end, inc)) # dat = Data.compile('build_signal(build_with_units( $*(0. + $value), "V") ,build_with_units($,"Counts"),$)', coefficent, buf,dim) dat = Data.compile( '_v0=$, _v1=$, build_signal(build_with_units(( _v0+ (_v1-_v0)*($value - -32768)/(32767 - -32768 )), "V") ,build_with_units($,"Counts"),$)', vins[chan * 2], vins[chan * 2 + 1], buf, dim) exec('c=self.input_' + '%02d' % (chan + 1, ) + '.record=dat') return 1 STOREFTP = storeftp def waitftp(self, arg): """Wait for board to finish digitizing and ftp'ing data to host""" state = self.getState() if state == 'ARMED' or state == 'RUN': return 662470754 raise Exception("device Not triggered") for chan in range(int(self.active_chan), 0, -1): chan_node = self.__getattr__('input_%2.2d' % (chan, )) if chan_node.on: max_chan = chan_node break tries = 0 while tries < 60: if max_chan.rlength > 0: break sleep(3) tries = tries + 1 if tries == 60: print("Triggered, but data not stored !") return 0 return 1 WAITFTP = waitftp
def storeftp(self, arg): try: from xml.marshal.generic import dumps, loads, load except: print "you must install PyXML to use this deprecated device. Please switch to acq216 device type" debug = os.getenv("DEBUG_DEVICES") path = self.local_path tree = self.local_tree shot = self.tree.shot CPCIDataDir = os.getenv('CPCI_DATA_DIR') if not CPCIDataDir: raise 'CPCI_DATA_DIR environment variable must be defined' dataDir = "%s/%s/%s/%s" % ( CPCIDataDir, tree, shot, path, ) try: settingsf = open("%s/settings.xml" % (dataDir, ), "r") except: raise Exception, "Could not open Settings file %s/settings.xml" % ( dataDir, ) try: settings = load(settingsf) except: settingsf.close() raise Exception, "Could not parse XML settings" settingsf.close() if debug: print "xml is loaded\n" status = [] cmds = self.status_cmds.record for cmd in cmds: cmd = cmd.strip() if debug: print "about to append answer for /%s/\n" % (cmd, ) print " which is /%s/\n" % (settings[cmd], ) status.append(settings[cmd]) if debug: print "%s returned %s\n" % ( cmd, settings[cmd], ) if debug: print "about to write board_status signal" self.board_status.record = Signal(cmds, None, status) numSampsStr = settings['getNumSamples'] preTrig = self.getPreTrig(numSampsStr) postTrig = self.getPostTrig(numSampsStr) vins = makeArray( numpy.array(settings['get.vin'].split(',')).astype('float')) self.ranges.record = vins chanMask = settings['getChannelMask'].split('=')[-1] if self.clock_src.record.lower( ) == 'int' or self.clock_src.record.lower() == 'master': #intClkStr=settings['getInternalClock'].split()[0].split('=')[1] #intClock=int(intClikStr) intClock = float(settings['getInternalClock'].split()[1]) delta = 1. / float(intClock) else: delta = 0 trig_src = self.__getattr__(str(self.trig_src.record).lower()) # # now store each channel # for chan in range(16): if debug: print "working on channel %d" % chan #chan_node = eval('self.input_%2.2d' % (chan+1,)) chan_node = self.__getattr__('input_%2.2d' % (chan + 1, )) if chan_node.on: if debug: print "it is on so ..." if chanMask[chan:chan + 1] == '1': try: start = max( int( self.__getattr__('input_%2.2d_startidx' % (chan + 1, ))), -preTrig) except: start = -preTrig try: end = min( int( self.__getattr__('input_%2.2d_endidx' % (chan + 1, ))), postTrig - 1) except: end = postTrig - 1 try: inc = max( int( self.__getattr__('input_%2.2d_inc' % (chan + 1, ))), 1) except: inc = 1 # # could do the coeffs # chanFileName = "%s/%2.2d" % ( dataDir, chan + 1, ) buf = self.readRawData(chanFileName, preTrig, start, end, inc) if delta != 0: axis = Range(None, None, delta / inc) else: #clockExpr = 'self.%s'% str(self.clock_src.record) #clock_src = eval(clockExpr.lower()) clock_src = self.__getattr__( str(self.clock_src.record).lower()) axis = clock_src if inc == 1: dim = Dimension(Window(start, end, trig_src), axis) else: dim = Data.compile( 'Map($,$)', Dimension(Window(start / inc, end / inc, trig_src), axis), Range(start, end, inc)) # dat = Data.compile('build_signal(build_with_units( $*(0. + $value), "V") ,build_with_units($,"Counts"),$)', coefficent, buf,dim) dat = Data.compile( '_v0=$, _v1=$, build_signal(build_with_units(( _v0+ (_v1-_v0)*($value - -32768)/(32767 - -32768 )), "V") ,build_with_units($,"Counts"),$)', vins[chan * 2], vins[chan * 2 + 1], buf, dim) exec('c=self.input_' + '%02d' % (chan + 1, ) + '.record=dat') return 1
class DT196B(Device): """ D-Tacq ACQ196 96 channel transient recorder Methods: Add() - add a DT196B device to the tree open for edit Init(arg) - initialize the DT196B device write setup parameters and waveforms to the device Store(arg) - store the data acquired by the device Help(arg) - Print this message Nodes: :HOSTIP - mdsip address of the host storing the data. Usually 192.168.0.254:8106 BOARDIP'- ip addres sof the card as a string something like 192.168.0.40 COMMENT - user comment string DI[0-5] - time(s) of the signal on this internal wire (trig reference or clock reference) :wire - string specifying the source of this signal { 'fpga','mezz','rio','pxi','lemo', 'none } :bus - string specifying the destination of this signal { 'fpga','rio','pxi', 'none } :ACTIVE_CHANS - number of active channels {32, 64, 96} INT_CLOCK - stored by module (representation of internal clock MASTER - points to INT_CLOCK node - needed a node to fill into clock_src TRIG_SRC - reference to DIn line used for trigger (DI3) TRIG_EDGE - string {rising, falling} CLOCK_SRC - reference to line (DIn) used for clock or INT_CLOCK, or MASTER CLOCK_DIV - NOT CURRENTLY IMPLIMENTED CLOCK_EDGE - string {rising, falling} CLOCK_FREQ - frequency for internal clock PRE_TRIG - pre trigger samples MUST BE ZERO FOR NOW POST_TRIG - post trigger samples SEGMENTS - number of segments to store data in NOT IMPLIMENTED FOR NOW CLOCK - Filled in by store place for module to store clock information RANGES - place for module to store calibration information STATUS_CMDS - array of shell commands to send to the module to record firmware version etc BOARD_STATUS - place for module to store answers for STATUS_CMDS as signal INPUT_[01-96] - place for module to store data in volts (reference to INPUT_NN:RAW) :RAW - place for module to store raw data in volts for each channel START_IDX - first sample to store for this channel END_IDX - last sample to store for this channel INC - decimation factor for this channel INIT_ACTION - dispatching information for INIT STORE_ACTION - dispatching information for STORE """ parts=[ {'path':':HOSTIP','type':'text','value':'192.168.0.254','options':('no_write_shot',)}, {'path':':BOARDIP','type':'text','value':'192.168.0.0','options':('no_write_shot',)}, {'path':':COMMENT','type':'text'}, ] for i in range(6): parts.append({'path':':DI%1.1d'%(i,),'type':'numeric','options':('no_write_shot',)}) parts.append({'path':':DI%1.1d:BUS'%(i,),'type':'text','options':('no_write_shot',)}) parts.append({'path':':DI%1.1d:WIRE'%(i,),'type':'text','options':('no_write_shot',)}) parts2=[ {'path':':ACTIVE_CHANS','type':'numeric','value':96,'options':('no_write_shot',)}, {'path':':INT_CLOCK','type':'axis','options':('no_write_model','write_once')}, {'path':':MASTER','type':'axis','valueExpr':'head.int_clock', 'options':('no_write_model','write_once')}, {'path':':TRIG_SRC','type':'numeric','valueExpr':'head.di3','options':('no_write_shot',)}, {'path':':TRIG_EDGE','type':'text','value':'rising','options':('no_write_shot',)}, {'path':':CLOCK_SRC','type':'numeric','valueExpr':'head.int_clock','options':('no_write_shot',)}, {'path':':CLOCK_DIV','type':'numeric','value':1,'options':('no_write_shot',)}, {'path':':CLOCK_EDGE','type':'text','value':'rising','options':('no_write_shot',)}, {'path':':CLOCK_FREQ','type':'numeric','value':100000,'options':('no_write_shot',)}, {'path':':PRE_TRIG','type':'numeric','value':0,'options':('no_write_shot',)}, {'path':':POST_TRIG','type':'numeric','value':128,'options':('no_write_shot',)}, {'path':':SEGMENTS','type':'numeric','value':1,'options':('no_write_shot',)}, {'path':':CLOCK','type':'axis','options':('no_write_model','write_once')}, {'path':':RANGES','type':'numeric','options':('no_write_model','write_once')}, {'path':':STATUS_CMDS','type':'text','value':makeArray(['cat /proc/cmdline', 'get.d-tacq.release']),'options':('no_write_shot',)}, {'path':':BOARD_STATUS','type':'SIGNAL','options':('no_write_model','write_once')}, ] parts.extend(parts2) del parts2 for i in range(96): parts.append({'path':':INPUT_%2.2d'%(i+1,),'type':'signal','options':('no_write_model','write_once',)}) parts.append({'path':':INPUT_%2.2d:RAW'%(i+1,),'type':'SIGNAL', 'options':('no_write_model','write_once')}) parts.append({'path':':INPUT_%2.2d:START_IDX'%(i+1,),'type':'NUMERIC', 'options':('no_write_shot')}) parts.append({'path':':INPUT_%2.2d:END_IDX'%(i+1,),'type':'NUMERIC', 'options':('no_write_shot')}) parts.append({'path':':INPUT_%2.2d:INC'%(i+1,),'type':'NUMERIC', 'options':('no_write_shot')}) parts.append({'path':':INIT_ACTION','type':'action', 'valueExpr':"Action(Dispatch('CAMAC_SERVER','INIT',50,None),Method(None,'INIT',head))", 'options':('no_write_shot',)}) parts.append({'path':':STORE_ACTION','type':'action', 'valueExpr':"Action(Dispatch('CAMAC_SERVER','STORE',50,None),Method(None,'STORE',head))", 'options':('no_write_shot',)}) parts.append({'path':':WAIT_ACTION','type':'action', 'valueExpr':"Action(Dispatch('CAMAC_SERVER','STORE',60,None),Method(None,'WAIT',head))", 'options':('no_write_shot',)}) clock_edges=['rising', 'falling'] trigger_edges = clock_edges trig_sources=[ 'DI0', 'DI1', 'DI2', 'DI3', 'DI4', 'DI5', ] clock_sources = trig_sources clock_sources.append('INT_CLOCK') clock_sources.append('MASTER') wires = [ 'fpga','mezz','rio','pxi','lemo', 'none', 'fpga pxi'] del i def check(self, expression, message): try: ans = eval(expression) return ans except: raise Exception, message 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('self.trig_src.record.getOriginalPartName().getString()[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('self.clock_src.record.getOriginalPartName().getString()[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,e: print "%s\n" % (str(e),) return 0