-
Notifications
You must be signed in to change notification settings - Fork 0
/
dt1322.py
executable file
·350 lines (322 loc) · 15.6 KB
/
dt1322.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
from MDSplus import Device,Data,Action,Dispatch,Method, makeArray, Range, Signal, Window, Dimension
from Dt200WriteMaster import Dt200WriteMaster
import acq200
import transport
from time import sleep
import os
import numpy
class DT1322(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
"""
return 0
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
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, 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,))
except Exception,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