1 | package require XOTcl
|
---|
2 |
|
---|
3 | package require BLT
|
---|
4 | package require swt
|
---|
5 | package require usb
|
---|
6 |
|
---|
7 | wm minsize . 900 720
|
---|
8 |
|
---|
9 | namespace eval ::mca {
|
---|
10 | namespace import ::xotcl::*
|
---|
11 |
|
---|
12 | namespace import ::blt::vector
|
---|
13 | namespace import ::blt::graph
|
---|
14 | namespace import ::blt::tabnotebook
|
---|
15 |
|
---|
16 | proc validate {value} {
|
---|
17 | if {![regexp {^[1-9][0-9]*$} $value]} {
|
---|
18 | return 0
|
---|
19 | } elseif {$value > 4095} {
|
---|
20 | return 0
|
---|
21 | } elseif {[string length $value] > 4} {
|
---|
22 | return 0
|
---|
23 | } else {
|
---|
24 | return 1
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | # -------------------------------------------------------------------------
|
---|
29 |
|
---|
30 | Class CfgDisplay -parameter {
|
---|
31 | {master}
|
---|
32 | }
|
---|
33 |
|
---|
34 | # -------------------------------------------------------------------------
|
---|
35 |
|
---|
36 | CfgDisplay instproc init {} {
|
---|
37 |
|
---|
38 | my reset
|
---|
39 |
|
---|
40 | my setup
|
---|
41 |
|
---|
42 | next
|
---|
43 | }
|
---|
44 |
|
---|
45 | # -------------------------------------------------------------------------
|
---|
46 |
|
---|
47 | CfgDisplay instproc destroy {} {
|
---|
48 | next
|
---|
49 | }
|
---|
50 |
|
---|
51 | # -------------------------------------------------------------------------
|
---|
52 |
|
---|
53 | CfgDisplay instproc reset {} {
|
---|
54 | }
|
---|
55 |
|
---|
56 | # -------------------------------------------------------------------------
|
---|
57 |
|
---|
58 | CfgDisplay instproc start {} {
|
---|
59 | my instvar config
|
---|
60 |
|
---|
61 | trace add variable [myvar dac1] write [myproc dac1_update]
|
---|
62 | trace add variable [myvar dac2] write [myproc dac2_update]
|
---|
63 | trace add variable [myvar polar] write [myproc polar_update]
|
---|
64 |
|
---|
65 | ${config(1)}.scale set 0
|
---|
66 | ${config(2)}.scale set 0
|
---|
67 |
|
---|
68 | ${config(3)}.polar1 select
|
---|
69 | ${config(3)}.polar2 select
|
---|
70 | }
|
---|
71 |
|
---|
72 | # -------------------------------------------------------------------------
|
---|
73 |
|
---|
74 | CfgDisplay instproc setup {} {
|
---|
75 | my instvar number master
|
---|
76 | my instvar config
|
---|
77 |
|
---|
78 | set config(1) [labelframe ${master}.cfg1 -text {DAC 20}]
|
---|
79 | set config(2) [labelframe ${master}.cfg2 -text {DAC 24}]
|
---|
80 | set config(3) [labelframe ${master}.cfg3 -text {polarity inversion}]
|
---|
81 |
|
---|
82 | frame ${config(1)}.limits
|
---|
83 | label ${config(1)}.limits.min -text {0V}
|
---|
84 | label ${config(1)}.limits.max -text {-3.3V}
|
---|
85 | scale ${config(1)}.scale -orient horizontal -from 0 -to 4095 -tickinterval 500 -variable [myvar dac1]
|
---|
86 |
|
---|
87 | frame ${config(2)}.limits
|
---|
88 | label ${config(2)}.limits.min -text {0V}
|
---|
89 | label ${config(2)}.limits.max -text {-3.3V}
|
---|
90 | scale ${config(2)}.scale -orient horizontal -from 0 -to 4095 -tickinterval 500 -variable [myvar dac2]
|
---|
91 |
|
---|
92 | checkbutton ${config(3)}.polar1 -text {channel 1} -variable [myvar polar(1)]
|
---|
93 | checkbutton ${config(3)}.polar2 -text {channel 2} -variable [myvar polar(2)]
|
---|
94 | checkbutton ${config(3)}.polar3 -text {channel 3} -variable [myvar polar(3)]
|
---|
95 |
|
---|
96 | pack ${config(1)} ${config(2)} -side top -expand yes -fill x -padx 10
|
---|
97 | pack ${config(3)} -side top -expand yes -fill x -padx 10
|
---|
98 |
|
---|
99 | pack ${config(1)}.limits.min -anchor w -side left -padx 13
|
---|
100 | pack ${config(1)}.limits.max -anchor e -side right -padx 5
|
---|
101 | pack ${config(1)}.limits ${config(1)}.scale -side top -expand yes -fill x
|
---|
102 |
|
---|
103 | pack ${config(2)}.limits.min -anchor w -side left -padx 13
|
---|
104 | pack ${config(2)}.limits.max -anchor e -side right -padx 5
|
---|
105 | pack ${config(2)}.limits ${config(2)}.scale -side top -expand yes -fill x
|
---|
106 |
|
---|
107 | pack ${config(3)}.polar1 -side left -expand yes -fill x -pady 10
|
---|
108 | pack ${config(3)}.polar2 -side left -expand yes -fill x -pady 10
|
---|
109 | pack ${config(3)}.polar3 -side left -expand yes -fill x -pady 10
|
---|
110 |
|
---|
111 | }
|
---|
112 |
|
---|
113 | # -------------------------------------------------------------------------
|
---|
114 |
|
---|
115 | CfgDisplay instproc dac1_update args {
|
---|
116 | my instvar dac1
|
---|
117 |
|
---|
118 | set value [format {%03x} $dac1]
|
---|
119 | set command 0005012000050030000500[string range $value 0 1]000502[string index $value 2]0
|
---|
120 |
|
---|
121 | my send_data [usb::convert $command]
|
---|
122 | }
|
---|
123 |
|
---|
124 | # -------------------------------------------------------------------------
|
---|
125 |
|
---|
126 | CfgDisplay instproc dac2_update args {
|
---|
127 | my instvar dac2
|
---|
128 |
|
---|
129 | set value [format {%03x} $dac2]
|
---|
130 | set command 0005012400050030000500[string range $value 0 1]000502[string index $value 2]0
|
---|
131 |
|
---|
132 | my send_data [usb::convert $command]
|
---|
133 | }
|
---|
134 |
|
---|
135 | # -------------------------------------------------------------------------
|
---|
136 |
|
---|
137 | CfgDisplay instproc polar_update args {
|
---|
138 | my instvar polar
|
---|
139 |
|
---|
140 | set value [format {0%x%x%x} $polar(3) $polar(2) $polar(1)]
|
---|
141 |
|
---|
142 | my send_data [usb::convert 000A${value}]
|
---|
143 | }
|
---|
144 |
|
---|
145 | # -------------------------------------------------------------------------
|
---|
146 |
|
---|
147 | CfgDisplay instproc send_data {data} {
|
---|
148 | global usb_handle
|
---|
149 |
|
---|
150 | if {[catch {$usb_handle writeRaw $data} result]} {
|
---|
151 | puts {Error during write}
|
---|
152 | puts $result
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | # -------------------------------------------------------------------------
|
---|
157 |
|
---|
158 | Class OscDisplay -parameter {
|
---|
159 | {number}
|
---|
160 | {master}
|
---|
161 | }
|
---|
162 |
|
---|
163 | # -------------------------------------------------------------------------
|
---|
164 |
|
---|
165 | OscDisplay instproc init {} {
|
---|
166 | my instvar data xvec yvec
|
---|
167 |
|
---|
168 | set xvec [vector #auto]
|
---|
169 | set yvec [vector #auto]
|
---|
170 | # fill one vector for the x axis with 1025 points
|
---|
171 | $xvec seq 0 1024
|
---|
172 |
|
---|
173 | my reset
|
---|
174 |
|
---|
175 | my setup
|
---|
176 |
|
---|
177 | next
|
---|
178 | }
|
---|
179 |
|
---|
180 | # -------------------------------------------------------------------------
|
---|
181 |
|
---|
182 | OscDisplay instproc destroy {} {
|
---|
183 | next
|
---|
184 | }
|
---|
185 |
|
---|
186 | # -------------------------------------------------------------------------
|
---|
187 |
|
---|
188 | OscDisplay instproc reset {} {
|
---|
189 | my instvar data xvec yvec
|
---|
190 |
|
---|
191 | set data {}
|
---|
192 |
|
---|
193 | $yvec set {}
|
---|
194 | }
|
---|
195 |
|
---|
196 | # -------------------------------------------------------------------------
|
---|
197 |
|
---|
198 | OscDisplay instproc start {} {
|
---|
199 | my instvar config trig_mux disp_mux
|
---|
200 |
|
---|
201 | set trig_mux 2
|
---|
202 | set disp_mux 2
|
---|
203 |
|
---|
204 | trace add variable [myvar auto] write [myproc auto_update]
|
---|
205 | trace add variable [myvar thrs] write [myproc thrs_update]
|
---|
206 | trace add variable [myvar thrs_val] write [myproc thrs_val_update]
|
---|
207 | trace add variable [myvar disp_val] write [myproc disp_val_update]
|
---|
208 | trace add variable [myvar trig_val] write [myproc trig_val_update]
|
---|
209 |
|
---|
210 | ${config}.auto_check select
|
---|
211 | ${config}.thrs_check select
|
---|
212 | ${config}.thrs_field set 60
|
---|
213 | ${config}.disp_uwt2 select
|
---|
214 | ${config}.trig_uwt2 select
|
---|
215 | }
|
---|
216 |
|
---|
217 | # -------------------------------------------------------------------------
|
---|
218 |
|
---|
219 | OscDisplay instproc setup {} {
|
---|
220 | my instvar number master
|
---|
221 | my instvar data xvec yvec
|
---|
222 | my instvar config auto thrs thrs_val disp_val trig_val
|
---|
223 |
|
---|
224 | my set restart_command [usb::convert 0001000${number}]
|
---|
225 | my set acquire_command [usb::convert 0002000${number}]
|
---|
226 |
|
---|
227 | # create a graph widget and show a grid
|
---|
228 | set graph [graph ${master}.graph -height 250 -leftmargin 80]
|
---|
229 | $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
|
---|
230 | $graph grid configure -hide no
|
---|
231 | $graph legend configure -hide yes
|
---|
232 | $graph axis configure x -min 0 -max 1024
|
---|
233 | $graph axis configure y -min 0 -max 4100
|
---|
234 |
|
---|
235 | set config [frame ${master}.config]
|
---|
236 |
|
---|
237 | checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
|
---|
238 |
|
---|
239 | frame ${config}.spc1 -width 10 -height 10
|
---|
240 |
|
---|
241 | checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
|
---|
242 | spinbox ${config}.thrs_field -from 1 -to 4095 \
|
---|
243 | -increment 5 -width 10 -textvariable [myvar thrs_val] \
|
---|
244 | -validate all -vcmd {::mca::validate %P}
|
---|
245 |
|
---|
246 | frame ${config}.spc2 -width 10 -height 10
|
---|
247 |
|
---|
248 | label ${config}.disp -text {display input}
|
---|
249 | radiobutton ${config}.disp_data -text {raw data} -variable [myvar disp_val] -value data
|
---|
250 | radiobutton ${config}.disp_uwt1 -text {filter 1} -variable [myvar disp_val] -value uwt1
|
---|
251 | radiobutton ${config}.disp_uwt2 -text {filter 2} -variable [myvar disp_val] -value uwt2
|
---|
252 | radiobutton ${config}.disp_uwt3 -text {filter 3} -variable [myvar disp_val] -value uwt3
|
---|
253 | radiobutton ${config}.disp_base -text {baseline} -variable [myvar disp_val] -value base
|
---|
254 | # radiobutton ${config}.disp_sum8 -text {sum of 8} -variable [myvar disp_val] -value sum8
|
---|
255 |
|
---|
256 | frame ${config}.spc3 -width 10 -height 10
|
---|
257 |
|
---|
258 | label ${config}.trig -text {trigger input}
|
---|
259 | radiobutton ${config}.trig_data -text {raw data} -variable [myvar trig_val] -value data
|
---|
260 | radiobutton ${config}.trig_uwt1 -text {filter 1} -variable [myvar trig_val] -value uwt1
|
---|
261 | radiobutton ${config}.trig_uwt2 -text {filter 2} -variable [myvar trig_val] -value uwt2
|
---|
262 | radiobutton ${config}.trig_uwt3 -text {filter 3} -variable [myvar trig_val] -value uwt3
|
---|
263 | radiobutton ${config}.trig_base -text {baseline} -variable [myvar trig_val] -value base
|
---|
264 | # radiobutton ${config}.trig_sum8 -text {sum of 8} -variable [myvar trig_val] -value sum8
|
---|
265 |
|
---|
266 | frame ${config}.spc4 -width 10 -height 10
|
---|
267 |
|
---|
268 | button ${config}.acquire -text Acquire \
|
---|
269 | -bg green -activebackground green -command [myproc acquire]
|
---|
270 | button ${config}.restart -text Restart \
|
---|
271 | -bg yellow -activebackground yellow -command [myproc restart]
|
---|
272 | button ${config}.register -text Register \
|
---|
273 | -bg lightblue -activebackground lightblue -command [myproc register]
|
---|
274 |
|
---|
275 | grid ${config}.auto_check -sticky w
|
---|
276 | grid ${config}.spc1
|
---|
277 | grid ${config}.thrs_check -sticky w
|
---|
278 | grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
|
---|
279 | grid ${config}.spc2
|
---|
280 | grid ${config}.disp -sticky w -pady 1 -padx 3
|
---|
281 | grid ${config}.disp_data -sticky w
|
---|
282 | grid ${config}.disp_uwt1 -sticky w
|
---|
283 | grid ${config}.disp_uwt2 -sticky w
|
---|
284 | grid ${config}.disp_uwt3 -sticky w
|
---|
285 | grid ${config}.disp_base -sticky w
|
---|
286 | # grid ${config}.disp_sum8 -sticky w
|
---|
287 | grid ${config}.spc3
|
---|
288 | grid ${config}.trig -sticky w -pady 1 -padx 3
|
---|
289 | grid ${config}.trig_data -sticky w
|
---|
290 | grid ${config}.trig_uwt1 -sticky w
|
---|
291 | grid ${config}.trig_uwt2 -sticky w
|
---|
292 | grid ${config}.trig_uwt3 -sticky w
|
---|
293 | grid ${config}.trig_base -sticky w
|
---|
294 | # grid ${config}.disp_sum8 -sticky w
|
---|
295 | grid ${config}.spc4
|
---|
296 | grid ${config}.acquire -sticky ew -pady 3 -padx 5
|
---|
297 | grid ${config}.restart -sticky ew -pady 3 -padx 5
|
---|
298 | grid ${config}.register -sticky ew -pady 3 -padx 5
|
---|
299 |
|
---|
300 | grid ${graph} -row 0 -column 0 -sticky news
|
---|
301 | grid ${config} -row 0 -column 1
|
---|
302 |
|
---|
303 | grid rowconfigure ${master} 0 -weight 1
|
---|
304 | grid columnconfigure ${master} 0 -weight 1
|
---|
305 | grid columnconfigure ${master} 1 -weight 0 -minsize 80
|
---|
306 |
|
---|
307 | # enable zooming
|
---|
308 | Blt_ZoomStack $graph
|
---|
309 |
|
---|
310 | #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
|
---|
311 |
|
---|
312 | # create one element with data for the x and y axis, no dots
|
---|
313 | $graph element create Spectrum1 -symbol none -xdata $xvec -ydata $yvec
|
---|
314 | }
|
---|
315 |
|
---|
316 | # -------------------------------------------------------------------------
|
---|
317 |
|
---|
318 | OscDisplay instproc auto_update args {
|
---|
319 | my instvar config auto after_handle
|
---|
320 |
|
---|
321 | if {$auto} {
|
---|
322 | ${config}.acquire configure -state disabled
|
---|
323 | ${config}.restart configure -state disabled
|
---|
324 | ${config}.register configure -state disabled
|
---|
325 |
|
---|
326 | my acquire_restart_loop
|
---|
327 | } else {
|
---|
328 | if {[my exists after_handle]} {
|
---|
329 | after cancel $after_handle
|
---|
330 | }
|
---|
331 | ${config}.acquire configure -state active
|
---|
332 | ${config}.restart configure -state active
|
---|
333 | ${config}.register configure -state active
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | # -------------------------------------------------------------------------
|
---|
338 |
|
---|
339 | OscDisplay instproc thrs_update args {
|
---|
340 | my instvar config number thrs thrs_val
|
---|
341 |
|
---|
342 | set val_addr [format %04x [expr {17 + ${number}}]]
|
---|
343 |
|
---|
344 | if {$thrs} {
|
---|
345 | ${config}.thrs_field configure -state normal
|
---|
346 | my thrs_val_update
|
---|
347 | } else {
|
---|
348 | ${config}.thrs_field configure -state disabled
|
---|
349 | my send_data [usb::convert ${val_addr}0000]
|
---|
350 | }
|
---|
351 | }
|
---|
352 |
|
---|
353 | # -------------------------------------------------------------------------
|
---|
354 |
|
---|
355 | OscDisplay instproc thrs_val_update args {
|
---|
356 | my instvar config number thrs_val
|
---|
357 |
|
---|
358 | set val_addr [format %04x [expr {17 + ${number}}]]
|
---|
359 | set value [format %04x $thrs_val]
|
---|
360 |
|
---|
361 | my send_data [usb::convert ${val_addr}${value}]
|
---|
362 | }
|
---|
363 |
|
---|
364 | # -------------------------------------------------------------------------
|
---|
365 |
|
---|
366 | OscDisplay instproc mux {} {
|
---|
367 | my instvar trig_mux disp_mux
|
---|
368 |
|
---|
369 | format {00%x%x} $trig_mux $disp_mux
|
---|
370 | }
|
---|
371 |
|
---|
372 | # ------------------------------------------------------------------------
|
---|
373 |
|
---|
374 | OscDisplay instproc disp_val_update args {
|
---|
375 | my instvar number disp_val disp_mux
|
---|
376 |
|
---|
377 | set mux_addr [format %04x [expr {20 + ${number}}]]
|
---|
378 |
|
---|
379 | switch -- $disp_val {
|
---|
380 | data {
|
---|
381 | set disp_mux 0
|
---|
382 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
383 | }
|
---|
384 | uwt1 {
|
---|
385 | set disp_mux 1
|
---|
386 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
387 | }
|
---|
388 | uwt2 {
|
---|
389 | set disp_mux 2
|
---|
390 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
391 | }
|
---|
392 | uwt3 {
|
---|
393 | set disp_mux 3
|
---|
394 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
395 | }
|
---|
396 | base {
|
---|
397 | set disp_mux 4
|
---|
398 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
399 | }
|
---|
400 | }
|
---|
401 | }
|
---|
402 |
|
---|
403 | # ------------------------------------------------------------------------
|
---|
404 |
|
---|
405 | OscDisplay instproc trig_val_update args {
|
---|
406 | my instvar number trig_val trig_mux
|
---|
407 |
|
---|
408 | set mux_addr [format %04x [expr {20 + ${number}}]]
|
---|
409 |
|
---|
410 | switch -- $trig_val {
|
---|
411 | data {
|
---|
412 | set trig_mux 0
|
---|
413 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
414 | }
|
---|
415 | uwt1 {
|
---|
416 | set trig_mux 1
|
---|
417 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
418 | }
|
---|
419 | uwt2 {
|
---|
420 | set trig_mux 2
|
---|
421 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
422 | }
|
---|
423 | uwt3 {
|
---|
424 | set trig_mux 3
|
---|
425 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
426 | }
|
---|
427 | base {
|
---|
428 | set trig_mux 4
|
---|
429 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
430 | }
|
---|
431 | }
|
---|
432 | }
|
---|
433 |
|
---|
434 | # -------------------------------------------------------------------------
|
---|
435 |
|
---|
436 | OscDisplay instproc save_data {data} {
|
---|
437 | set file [tk_getSaveFile]
|
---|
438 | if {[string equal $file {}]} {
|
---|
439 | return
|
---|
440 | }
|
---|
441 |
|
---|
442 | set x [catch {set fid [open $file w+]}]
|
---|
443 | set y [catch {puts $fid $data}]
|
---|
444 | set z [catch {close $fid}]
|
---|
445 |
|
---|
446 | if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
|
---|
447 | tk_messageBox -icon error \
|
---|
448 | -message "An error occurred while writing to \"$file\""
|
---|
449 | } else {
|
---|
450 | tk_messageBox -icon info \
|
---|
451 | -message "File \"$file\" written successfully"
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | # -------------------------------------------------------------------------
|
---|
456 |
|
---|
457 | OscDisplay instproc register {} {
|
---|
458 | my save_data [my set data]
|
---|
459 | }
|
---|
460 |
|
---|
461 | # -------------------------------------------------------------------------
|
---|
462 |
|
---|
463 | OscDisplay instproc send_data {data} {
|
---|
464 | global usb_handle
|
---|
465 |
|
---|
466 | if {[catch {$usb_handle writeRaw $data} result]} {
|
---|
467 | puts {Error during write}
|
---|
468 | puts $result
|
---|
469 | }
|
---|
470 | }
|
---|
471 |
|
---|
472 | # -------------------------------------------------------------------------
|
---|
473 |
|
---|
474 | OscDisplay instproc restart {} {
|
---|
475 | my instvar restart_command
|
---|
476 | my send_data $restart_command
|
---|
477 | }
|
---|
478 |
|
---|
479 | # -------------------------------------------------------------------------
|
---|
480 |
|
---|
481 | OscDisplay instproc acquire {} {
|
---|
482 | global usb_handle
|
---|
483 | my instvar xvec yvec data
|
---|
484 | my instvar acquire_command
|
---|
485 |
|
---|
486 | my send_data $acquire_command
|
---|
487 |
|
---|
488 | set usb_data {}
|
---|
489 | if {[catch {$usb_handle readHex 2 1024} usb_data]} {
|
---|
490 | puts {Error during read}
|
---|
491 | puts $usb_data
|
---|
492 | set usb_data {}
|
---|
493 | }
|
---|
494 |
|
---|
495 | set data $usb_data
|
---|
496 |
|
---|
497 | $yvec set $usb_data
|
---|
498 | }
|
---|
499 |
|
---|
500 | # -------------------------------------------------------------------------
|
---|
501 |
|
---|
502 | OscDisplay instproc acquire_restart_loop {} {
|
---|
503 | my instvar after_handle
|
---|
504 |
|
---|
505 | my acquire
|
---|
506 | my restart
|
---|
507 |
|
---|
508 | set after_handle [after 1000 [myproc acquire_restart_loop]]
|
---|
509 | }
|
---|
510 |
|
---|
511 | # -------------------------------------------------------------------------
|
---|
512 |
|
---|
513 | Class HstDisplay -parameter {
|
---|
514 | {number}
|
---|
515 | {master}
|
---|
516 | }
|
---|
517 |
|
---|
518 | # -------------------------------------------------------------------------
|
---|
519 |
|
---|
520 | HstDisplay instproc init {} {
|
---|
521 | my instvar data xvec yvec
|
---|
522 |
|
---|
523 | set xvec [vector #auto]
|
---|
524 | set yvec [vector #auto]
|
---|
525 | # fill one vector for the x axis with 4097 points
|
---|
526 | $xvec seq 0 4096
|
---|
527 |
|
---|
528 | my reset
|
---|
529 |
|
---|
530 | my setup
|
---|
531 |
|
---|
532 | next
|
---|
533 | }
|
---|
534 |
|
---|
535 | # -------------------------------------------------------------------------
|
---|
536 |
|
---|
537 | HstDisplay instproc destroy {} {
|
---|
538 | next
|
---|
539 | }
|
---|
540 |
|
---|
541 | # -------------------------------------------------------------------------
|
---|
542 |
|
---|
543 | HstDisplay instproc reset {} {
|
---|
544 | my instvar data xvec yvec
|
---|
545 |
|
---|
546 | set data {}
|
---|
547 |
|
---|
548 | $yvec set {}
|
---|
549 | }
|
---|
550 |
|
---|
551 | # -------------------------------------------------------------------------
|
---|
552 |
|
---|
553 | HstDisplay instproc start {} {
|
---|
554 | my instvar config base_mux peak_mux
|
---|
555 |
|
---|
556 | set base_mux 0
|
---|
557 | set peak_mux 1
|
---|
558 |
|
---|
559 | trace add variable [myvar auto] write [myproc auto_update]
|
---|
560 | trace add variable [myvar peak] write [myproc peak_update]
|
---|
561 | trace add variable [myvar thrs] write [myproc thrs_update]
|
---|
562 | trace add variable [myvar thrs_val] write [myproc thrs_val_update]
|
---|
563 | trace add variable [myvar base] write [myproc base_update]
|
---|
564 | trace add variable [myvar base_typ] write [myproc base_typ_update]
|
---|
565 | trace add variable [myvar base_val] write [myproc base_val_update]
|
---|
566 |
|
---|
567 | ${config}.auto_check select
|
---|
568 | ${config}.peak_check select
|
---|
569 | ${config}.thrs_check select
|
---|
570 | ${config}.thrs_field set 10
|
---|
571 | ${config}.base_check select
|
---|
572 | ${config}.base_const select
|
---|
573 | ${config}.base_field set 35
|
---|
574 | }
|
---|
575 |
|
---|
576 | # -------------------------------------------------------------------------
|
---|
577 |
|
---|
578 | HstDisplay instproc setup {} {
|
---|
579 | my instvar number master
|
---|
580 | my instvar data xvec yvec
|
---|
581 | my instvar config auto thrs thrs_val base base_typ base_val
|
---|
582 |
|
---|
583 | my set restart_command [usb::convert 0001001${number}]
|
---|
584 | my set acquire_command [usb::convert 0002001${number}]
|
---|
585 |
|
---|
586 | # create a graph widget and show a grid
|
---|
587 | set graph [graph ${master}.graph -height 250 -leftmargin 80]
|
---|
588 | $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
|
---|
589 | $graph grid configure -hide no
|
---|
590 | $graph legend configure -hide yes
|
---|
591 | $graph axis configure x -min 0 -max 4096
|
---|
592 |
|
---|
593 | set config [frame ${master}.config]
|
---|
594 |
|
---|
595 | checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
|
---|
596 |
|
---|
597 | frame ${config}.spc1 -width 10 -height 10
|
---|
598 |
|
---|
599 | checkbutton ${config}.peak_check -text {peak detect} -variable [myvar peak]
|
---|
600 |
|
---|
601 | frame ${config}.spc2 -width 10 -height 10
|
---|
602 |
|
---|
603 | checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
|
---|
604 | spinbox ${config}.thrs_field -from 1 -to 4095 \
|
---|
605 | -increment 5 -width 10 -textvariable [myvar thrs_val] \
|
---|
606 | -validate all -vcmd {::mca::validate %P}
|
---|
607 |
|
---|
608 | frame ${config}.spc3 -width 10 -height 10
|
---|
609 |
|
---|
610 | checkbutton ${config}.base_check -text baseline -variable [myvar base]
|
---|
611 | radiobutton ${config}.base_auto -text automatic -variable [myvar base_typ] -value auto
|
---|
612 | radiobutton ${config}.base_const -text constant -variable [myvar base_typ] -value const
|
---|
613 | spinbox ${config}.base_field -from 1 -to 4095 \
|
---|
614 | -increment 5 -width 10 -textvariable [myvar base_val] \
|
---|
615 | -validate all -vcmd {::mca::validate %P}
|
---|
616 |
|
---|
617 | frame ${config}.spc4 -width 10 -height 10
|
---|
618 |
|
---|
619 | button ${config}.acquire -text Acquire \
|
---|
620 | -bg green -activebackground green -command [myproc acquire]
|
---|
621 | button ${config}.restart -text Restart \
|
---|
622 | -bg yellow -activebackground yellow -command [myproc restart]
|
---|
623 | button ${config}.register -text Register \
|
---|
624 | -bg lightblue -activebackground lightblue -command [myproc register]
|
---|
625 |
|
---|
626 | grid ${config}.auto_check -sticky w
|
---|
627 | grid ${config}.spc1
|
---|
628 | grid ${config}.peak_check -sticky w
|
---|
629 | grid ${config}.spc2
|
---|
630 | grid ${config}.thrs_check -sticky w
|
---|
631 | grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
|
---|
632 | grid ${config}.spc3
|
---|
633 | grid ${config}.base_check -sticky w
|
---|
634 | grid ${config}.base_auto -sticky w
|
---|
635 | grid ${config}.base_const -sticky w
|
---|
636 | grid ${config}.base_field -sticky ew -pady 1 -padx 5
|
---|
637 | grid ${config}.spc4
|
---|
638 | grid ${config}.acquire -sticky ew -pady 3 -padx 5
|
---|
639 | grid ${config}.restart -sticky ew -pady 3 -padx 5
|
---|
640 | grid ${config}.register -sticky ew -pady 3 -padx 5
|
---|
641 |
|
---|
642 | grid ${graph} -row 0 -column 0 -sticky news
|
---|
643 | grid ${config} -row 0 -column 1
|
---|
644 |
|
---|
645 | grid rowconfigure ${master} 0 -weight 1
|
---|
646 | grid columnconfigure ${master} 0 -weight 1
|
---|
647 | grid columnconfigure ${master} 1 -weight 0 -minsize 80
|
---|
648 |
|
---|
649 | # enable zooming
|
---|
650 | Blt_ZoomStack $graph
|
---|
651 |
|
---|
652 | #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
|
---|
653 |
|
---|
654 | # create one element with data for the x and y axis, no dots
|
---|
655 | $graph element create Spectrum1 -symbol none -smooth step -xdata $xvec -ydata $yvec
|
---|
656 | }
|
---|
657 |
|
---|
658 | # -------------------------------------------------------------------------
|
---|
659 |
|
---|
660 | HstDisplay instproc auto_update args {
|
---|
661 | my instvar auto after_handle
|
---|
662 | my instvar config
|
---|
663 | if {$auto} {
|
---|
664 | ${config}.acquire configure -state disabled
|
---|
665 | ${config}.register configure -state disabled
|
---|
666 |
|
---|
667 | my acquire_loop
|
---|
668 | } else {
|
---|
669 | if {[my exists after_handle]} {
|
---|
670 | after cancel $after_handle
|
---|
671 | }
|
---|
672 | ${config}.acquire configure -state active
|
---|
673 | ${config}.register configure -state active
|
---|
674 | }
|
---|
675 | }
|
---|
676 |
|
---|
677 | # -------------------------------------------------------------------------
|
---|
678 |
|
---|
679 | HstDisplay instproc mux {} {
|
---|
680 | my instvar base_mux peak_mux
|
---|
681 |
|
---|
682 | format {00%x%x} $base_mux $peak_mux
|
---|
683 | }
|
---|
684 |
|
---|
685 | # -------------------------------------------------------------------------
|
---|
686 |
|
---|
687 | HstDisplay instproc peak_update args {
|
---|
688 | my instvar number peak peak_mux
|
---|
689 |
|
---|
690 | set mux_addr [format %04x [expr {23 + ${number}}]]
|
---|
691 |
|
---|
692 | if {$peak} {
|
---|
693 | set peak_mux 1
|
---|
694 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
695 | } else {
|
---|
696 | set peak_mux 0
|
---|
697 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
698 | }
|
---|
699 | }
|
---|
700 |
|
---|
701 | # -------------------------------------------------------------------------
|
---|
702 |
|
---|
703 | HstDisplay instproc thrs_update args {
|
---|
704 | my instvar config number thrs thrs_val
|
---|
705 |
|
---|
706 | set val_addr [format %04x [expr {14 + ${number}}]]
|
---|
707 | set value [format %04x $thrs_val]
|
---|
708 |
|
---|
709 | if {$thrs} {
|
---|
710 | ${config}.thrs_field configure -state normal
|
---|
711 | my thrs_val_update
|
---|
712 | } else {
|
---|
713 | ${config}.thrs_field configure -state disabled
|
---|
714 | my send_data [usb::convert ${val_addr}0000]
|
---|
715 | }
|
---|
716 | }
|
---|
717 |
|
---|
718 | # -------------------------------------------------------------------------
|
---|
719 |
|
---|
720 | HstDisplay instproc thrs_val_update args {
|
---|
721 | my instvar config number thrs_val
|
---|
722 |
|
---|
723 | set val_addr [format %04x [expr {14 + ${number}}]]
|
---|
724 | set value [format %04x $thrs_val]
|
---|
725 |
|
---|
726 | my send_data [usb::convert ${val_addr}${value}]
|
---|
727 | }
|
---|
728 |
|
---|
729 | # -------------------------------------------------------------------------
|
---|
730 |
|
---|
731 | HstDisplay instproc base_update args {
|
---|
732 | my instvar config number base base_val base_mux
|
---|
733 |
|
---|
734 | set mux_addr [format %04x [expr {23 + ${number}}]]
|
---|
735 | set val_addr [format %04x [expr {11 + ${number}}]]
|
---|
736 |
|
---|
737 | if {$base} {
|
---|
738 | ${config}.base_auto configure -state normal
|
---|
739 | ${config}.base_const configure -state normal
|
---|
740 | my base_typ_update
|
---|
741 | } else {
|
---|
742 | ${config}.base_auto configure -state disabled
|
---|
743 | ${config}.base_const configure -state disabled
|
---|
744 | ${config}.base_field configure -state disabled
|
---|
745 | set base_mux 0
|
---|
746 | my send_data [usb::convert ${mux_addr}[my mux]${val_addr}0000]
|
---|
747 | }
|
---|
748 | }
|
---|
749 |
|
---|
750 | # -------------------------------------------------------------------------
|
---|
751 |
|
---|
752 | HstDisplay instproc base_typ_update args {
|
---|
753 | my instvar config number base_typ base_val base_mux
|
---|
754 |
|
---|
755 | set mux_addr [format %04x [expr {23 + ${number}}]]
|
---|
756 | set val_addr [format %04x [expr {11 + ${number}}]]
|
---|
757 | set value [format %04x $base_val]
|
---|
758 |
|
---|
759 | switch -- $base_typ {
|
---|
760 | auto {
|
---|
761 | ${config}.base_field configure -state disabled
|
---|
762 | set base_mux 1
|
---|
763 | my send_data [usb::convert ${mux_addr}[my mux]]
|
---|
764 | }
|
---|
765 | const {
|
---|
766 | ${config}.base_field configure -state normal
|
---|
767 | set base_mux 0
|
---|
768 | my send_data [usb::convert ${mux_addr}[my mux]${val_addr}${value}]
|
---|
769 | }
|
---|
770 | }
|
---|
771 | }
|
---|
772 |
|
---|
773 | # -------------------------------------------------------------------------
|
---|
774 |
|
---|
775 | HstDisplay instproc base_val_update args {
|
---|
776 | my instvar number base_val
|
---|
777 |
|
---|
778 | set val_addr [format %04x [expr {11 + ${number}}]]
|
---|
779 | set value [format %04x $base_val]
|
---|
780 |
|
---|
781 | my send_data [usb::convert ${val_addr}${value}]
|
---|
782 | }
|
---|
783 |
|
---|
784 | # -------------------------------------------------------------------------
|
---|
785 |
|
---|
786 | HstDisplay instproc save_data {data} {
|
---|
787 | set file [tk_getSaveFile]
|
---|
788 | if {[string equal $file {}]} {
|
---|
789 | return
|
---|
790 | }
|
---|
791 |
|
---|
792 | set x [catch {set fid [open $file w+]}]
|
---|
793 | set y [catch {puts $fid $data}]
|
---|
794 | set z [catch {close $fid}]
|
---|
795 |
|
---|
796 | if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
|
---|
797 | tk_messageBox -icon error \
|
---|
798 | -message "An error occurred while writing to \"$file\""
|
---|
799 | } else {
|
---|
800 | tk_messageBox -icon info \
|
---|
801 | -message "File \"$file\" written successfully"
|
---|
802 | }
|
---|
803 | }
|
---|
804 |
|
---|
805 | # -------------------------------------------------------------------------
|
---|
806 |
|
---|
807 | HstDisplay instproc register {} {
|
---|
808 | my save_data [my set data]
|
---|
809 | }
|
---|
810 |
|
---|
811 | # -------------------------------------------------------------------------
|
---|
812 |
|
---|
813 | HstDisplay instproc send_data {data} {
|
---|
814 | global usb_handle
|
---|
815 |
|
---|
816 | if {[catch {$usb_handle writeRaw $data} result]} {
|
---|
817 | puts {Error during write}
|
---|
818 | puts $result
|
---|
819 | }
|
---|
820 | }
|
---|
821 |
|
---|
822 | # -------------------------------------------------------------------------
|
---|
823 |
|
---|
824 | HstDisplay instproc restart {} {
|
---|
825 | my instvar restart_command
|
---|
826 | my send_data $restart_command
|
---|
827 | }
|
---|
828 |
|
---|
829 | # -------------------------------------------------------------------------
|
---|
830 |
|
---|
831 | HstDisplay instproc acquire {} {
|
---|
832 | global usb_handle
|
---|
833 | my instvar xvec yvec data fltr_val
|
---|
834 | my instvar acquire_command
|
---|
835 |
|
---|
836 | my send_data $acquire_command
|
---|
837 |
|
---|
838 | set usb_data {}
|
---|
839 | if {[catch {$usb_handle readHex 4 4096} usb_data]} {
|
---|
840 | puts {Error during read}
|
---|
841 | puts $usb_data
|
---|
842 | set usb_data {}
|
---|
843 | }
|
---|
844 |
|
---|
845 | set data $usb_data
|
---|
846 |
|
---|
847 | $yvec set $usb_data
|
---|
848 | }
|
---|
849 |
|
---|
850 | # -------------------------------------------------------------------------
|
---|
851 |
|
---|
852 | HstDisplay instproc acquire_loop {} {
|
---|
853 | my instvar after_handle
|
---|
854 |
|
---|
855 | my acquire
|
---|
856 |
|
---|
857 | set after_handle [after 1000 [myproc acquire_loop]]
|
---|
858 | }
|
---|
859 |
|
---|
860 | # -------------------------------------------------------------------------
|
---|
861 |
|
---|
862 | namespace export HstDisplay
|
---|
863 | namespace export OscDisplay
|
---|
864 | namespace export CfgDisplay
|
---|
865 | }
|
---|
866 |
|
---|
867 | set notebook [::blt::tabnotebook .notebook -selectforeground black -side bottom]
|
---|
868 |
|
---|
869 | pack $notebook -expand 1 -fill both
|
---|
870 |
|
---|
871 | foreach i {0 1 2} {
|
---|
872 | set channel [expr $i + 1]
|
---|
873 |
|
---|
874 | set window [frame ${notebook}.hst_$i]
|
---|
875 | $notebook insert end -text "Histogram $channel" -window $window -fill both
|
---|
876 | ::mca::HstDisplay hst_$i -number $i -master $window
|
---|
877 |
|
---|
878 | set window [frame ${notebook}.osc_$i]
|
---|
879 | $notebook insert end -text "Pulse shape $channel" -window $window -fill both
|
---|
880 | ::mca::OscDisplay osc_$i -number $i -master $window
|
---|
881 | }
|
---|
882 |
|
---|
883 | set window [frame ${notebook}.cfg]
|
---|
884 | $notebook insert end -text "Configuration" -window $window -fill both
|
---|
885 | ::mca::CfgDisplay cfg -master $window
|
---|
886 |
|
---|
887 | set usb_handle {}
|
---|
888 |
|
---|
889 | while {[catch {usb::connect 0x09FB 0x6001 1 1 0} usb_handle]} {
|
---|
890 | set answer [tk_messageBox -icon error -type retrycancel \
|
---|
891 | -message {Cannot access USB device} -detail $usb_handle]
|
---|
892 | if {[string equal $answer cancel]} break
|
---|
893 | }
|
---|
894 |
|
---|
895 | # cfg reset
|
---|
896 | set reset_command [usb::convert 00000000]
|
---|
897 | if {[catch {$usb_handle writeRaw $reset_command} result]} {
|
---|
898 | puts {Error during write}
|
---|
899 | puts $result
|
---|
900 | }
|
---|
901 |
|
---|
902 | cfg start
|
---|
903 |
|
---|
904 | foreach i {0 1 2} {
|
---|
905 | hst_$i start
|
---|
906 | osc_$i start
|
---|
907 |
|
---|
908 | hst_$i restart
|
---|
909 | osc_$i restart
|
---|
910 | }
|
---|