source: trunk/MultiChannelUSB/UserInterface.tcl@ 151

Last change on this file since 151 was 85, checked in by demin, 15 years ago

add possibility to record full EPT information

File size: 44.4 KB
RevLine 
[73]1package require XOTcl
2
3package require BLT
4package require swt
5package require usb
6
[85]7package require zlib
[73]8
[85]9wm minsize . 1000 700
10
[73]11namespace eval ::mca {
12 namespace import ::xotcl::*
13
14 namespace import ::blt::vector
15 namespace import ::blt::graph
16 namespace import ::blt::tabnotebook
17
[85]18 proc validate {max value} {
19 if {![regexp {^[0-9]*$} $value]} {
[73]20 return 0
[85]21 } elseif {$value > $max} {
[73]22 return 0
23 } elseif {[string length $value] > 4} {
24 return 0
25 } else {
26 return 1
27 }
28 }
29
30# -------------------------------------------------------------------------
31
[85]32 Class Display
33
34# -------------------------------------------------------------------------
35
36 Display instproc usbCmd {command} {
37 global usb_handle
38
39 if {[catch {$usb_handle writeRaw [usb::convert $command]} result]} {
40 puts {Error during write}
41 puts $result
42 }
43 }
44
45# -------------------------------------------------------------------------
46
47 Display instproc usbCmdRead {command width size} {
48 global usb_handle
49
50 my usbCmd $command
51
52 set usb_data {}
53 if {[catch {$usb_handle readHex $width $size} result]} {
54 puts {Error during read}
55 puts $result
56 set result {}
57 }
58
59 my set data $result
60 }
61
62# -------------------------------------------------------------------------
63
64 Display instproc usbCmdReadEpt {command size} {
65 global usb_handle
66
67 my usbCmd $command
68
69 set usb_data {}
70 if {[catch {$usb_handle readEpt $size} result]} {
71 puts {Error during read}
72 puts $result
73 set result {}
74 }
75
76 my set data $result
77 }
78
79# -------------------------------------------------------------------------
80
81 Class CfgDisplay -superclass Display -parameter {
[77]82 {master}
83 }
84
85# -------------------------------------------------------------------------
86
87 CfgDisplay instproc init {} {
88
89 my reset
90
91 my setup
92
93 next
94 }
95
96# -------------------------------------------------------------------------
97
98 CfgDisplay instproc destroy {} {
99 next
100 }
101
102# -------------------------------------------------------------------------
103
104 CfgDisplay instproc reset {} {
105 }
106
107# -------------------------------------------------------------------------
108
109 CfgDisplay instproc start {} {
110 my instvar config
111
112 trace add variable [myvar dac1] write [myproc dac1_update]
113 trace add variable [myvar dac2] write [myproc dac2_update]
114 trace add variable [myvar polar] write [myproc polar_update]
115
[78]116 ${config(1)}.dac1 set 0
117 ${config(1)}.dac2 set 0
[77]118
[78]119 ${config(2)}.polar1 select
120 ${config(2)}.polar2 select
[82]121 ${config(2)}.polar3 select
[77]122 }
123
124# -------------------------------------------------------------------------
125
126 CfgDisplay instproc setup {} {
127 my instvar number master
128 my instvar config
129
[78]130 set config(1) [labelframe ${master}.cfg1 -borderwidth 1 -relief sunken -text {DAC}]
131 set config(2) [labelframe ${master}.cfg2 -borderwidth 1 -relief sunken -text {polarity inversion}]
[77]132
133 frame ${config(1)}.limits
[78]134 label ${config(1)}.limits.min -text {0.0V}
[77]135 label ${config(1)}.limits.max -text {-3.3V}
136
[78]137 scale ${config(1)}.dac1 -orient vertical -from 0 -to 4095 -tickinterval 500 -variable [myvar dac1]
138 scale ${config(1)}.dac2 -orient vertical -from 0 -to 4095 -tickinterval 0 -variable [myvar dac2]
[77]139
[78]140 checkbutton ${config(2)}.polar1 -text {channel 1} -variable [myvar polar(1)]
141 checkbutton ${config(2)}.polar2 -text {channel 2} -variable [myvar polar(2)]
142 checkbutton ${config(2)}.polar3 -text {channel 3} -variable [myvar polar(3)]
[77]143
[78]144 grid ${config(1)} -sticky ns
145 grid ${config(2)} -sticky ew -pady 7
[77]146
[78]147 pack ${config(1)}.limits.min -anchor n -side top -pady 10
148 pack ${config(1)}.limits.max -anchor s -side bottom -pady 9
[77]149
[78]150 grid ${config(1)}.dac1 ${config(1)}.dac2 ${config(1)}.limits -sticky ns -pady 7
[77]151
[78]152 grid ${config(2)}.polar1
153 grid ${config(2)}.polar2
154 grid ${config(2)}.polar3
[77]155
[78]156 grid rowconfigure ${master} 0 -weight 1
157 grid rowconfigure ${config(1)} 0 -weight 1
158 grid rowconfigure ${config(2)} 0 -weight 1
[77]159 }
160
161# -------------------------------------------------------------------------
162
163 CfgDisplay instproc dac1_update args {
164 my instvar dac1
165
166 set value [format {%03x} $dac1]
167 set command 0005012000050030000500[string range $value 0 1]000502[string index $value 2]0
168
[85]169 my usbCmd $command
[77]170 }
171
172# -------------------------------------------------------------------------
173
174 CfgDisplay instproc dac2_update args {
175 my instvar dac2
176
177 set value [format {%03x} $dac2]
178 set command 0005012400050030000500[string range $value 0 1]000502[string index $value 2]0
179
[85]180 my usbCmd $command
[77]181 }
182
183# -------------------------------------------------------------------------
184
185 CfgDisplay instproc polar_update args {
186 my instvar polar
187
188 set value [format {0%x%x%x} $polar(3) $polar(2) $polar(1)]
189
[85]190 my usbCmd 000A${value}
[77]191 }
192
193# -------------------------------------------------------------------------
194
[85]195 Class OscDisplay -superclass Display -parameter {
[73]196 {number}
197 {master}
198 }
199
200# -------------------------------------------------------------------------
201
202 OscDisplay instproc init {} {
203 my instvar data xvec yvec
204
205 set xvec [vector #auto]
206 set yvec [vector #auto]
207 # fill one vector for the x axis with 1025 points
208 $xvec seq 0 1024
209
210 my reset
211
212 my setup
213
214 next
215 }
216
217# -------------------------------------------------------------------------
218
219 OscDisplay instproc destroy {} {
220 next
221 }
222
223# -------------------------------------------------------------------------
224
225 OscDisplay instproc reset {} {
226 my instvar data xvec yvec
227
[74]228 set data {}
[73]229
230 $yvec set {}
231 }
232
233# -------------------------------------------------------------------------
234
235 OscDisplay instproc start {} {
[74]236 my instvar config trig_mux disp_mux
237
238 set trig_mux 2
239 set disp_mux 2
240
[85]241 trace add variable [myvar data] write [myproc data_update]
[73]242 trace add variable [myvar auto] write [myproc auto_update]
243 trace add variable [myvar thrs] write [myproc thrs_update]
[74]244 trace add variable [myvar thrs_val] write [myproc thrs_val_update]
245 trace add variable [myvar disp_val] write [myproc disp_val_update]
246 trace add variable [myvar trig_val] write [myproc trig_val_update]
[73]247
[74]248 ${config}.auto_check select
249 ${config}.thrs_check select
[85]250 ${config}.thrs_field set 1278
[74]251 ${config}.disp_uwt2 select
252 ${config}.trig_uwt2 select
[73]253 }
254
255# -------------------------------------------------------------------------
256
257 OscDisplay instproc setup {} {
258 my instvar number master
259 my instvar data xvec yvec
[74]260 my instvar config auto thrs thrs_val disp_val trig_val
[73]261
262 # create a graph widget and show a grid
263 set graph [graph ${master}.graph -height 250 -leftmargin 80]
264 $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
265 $graph grid configure -hide no
266 $graph legend configure -hide yes
267 $graph axis configure x -min 0 -max 1024
[77]268 $graph axis configure y -min 0 -max 4100
[73]269
270 set config [frame ${master}.config]
271
272 checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
273
274 frame ${config}.spc1 -width 10 -height 10
275
276 checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
277 spinbox ${config}.thrs_field -from 1 -to 4095 \
278 -increment 5 -width 10 -textvariable [myvar thrs_val] \
[85]279 -validate all -vcmd {::mca::validate 4095 %P}
[73]280
281 frame ${config}.spc2 -width 10 -height 10
282
[74]283 label ${config}.disp -text {display input}
284 radiobutton ${config}.disp_data -text {raw data} -variable [myvar disp_val] -value data
285 radiobutton ${config}.disp_uwt1 -text {filter 1} -variable [myvar disp_val] -value uwt1
286 radiobutton ${config}.disp_uwt2 -text {filter 2} -variable [myvar disp_val] -value uwt2
287 radiobutton ${config}.disp_uwt3 -text {filter 3} -variable [myvar disp_val] -value uwt3
288 radiobutton ${config}.disp_base -text {baseline} -variable [myvar disp_val] -value base
289# radiobutton ${config}.disp_sum8 -text {sum of 8} -variable [myvar disp_val] -value sum8
[73]290
291 frame ${config}.spc3 -width 10 -height 10
292
[74]293 label ${config}.trig -text {trigger input}
294 radiobutton ${config}.trig_data -text {raw data} -variable [myvar trig_val] -value data
295 radiobutton ${config}.trig_uwt1 -text {filter 1} -variable [myvar trig_val] -value uwt1
296 radiobutton ${config}.trig_uwt2 -text {filter 2} -variable [myvar trig_val] -value uwt2
297 radiobutton ${config}.trig_uwt3 -text {filter 3} -variable [myvar trig_val] -value uwt3
298 radiobutton ${config}.trig_base -text {baseline} -variable [myvar trig_val] -value base
299# radiobutton ${config}.trig_sum8 -text {sum of 8} -variable [myvar trig_val] -value sum8
300
301 frame ${config}.spc4 -width 10 -height 10
302
[73]303 button ${config}.acquire -text Acquire \
304 -bg green -activebackground green -command [myproc acquire]
305 button ${config}.restart -text Restart \
306 -bg yellow -activebackground yellow -command [myproc restart]
307 button ${config}.register -text Register \
308 -bg lightblue -activebackground lightblue -command [myproc register]
309
310 grid ${config}.auto_check -sticky w
311 grid ${config}.spc1
312 grid ${config}.thrs_check -sticky w
313 grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
314 grid ${config}.spc2
[74]315 grid ${config}.disp -sticky w -pady 1 -padx 3
316 grid ${config}.disp_data -sticky w
317 grid ${config}.disp_uwt1 -sticky w
318 grid ${config}.disp_uwt2 -sticky w
319 grid ${config}.disp_uwt3 -sticky w
320 grid ${config}.disp_base -sticky w
321# grid ${config}.disp_sum8 -sticky w
[73]322 grid ${config}.spc3
[74]323 grid ${config}.trig -sticky w -pady 1 -padx 3
324 grid ${config}.trig_data -sticky w
325 grid ${config}.trig_uwt1 -sticky w
326 grid ${config}.trig_uwt2 -sticky w
327 grid ${config}.trig_uwt3 -sticky w
328 grid ${config}.trig_base -sticky w
329# grid ${config}.disp_sum8 -sticky w
330 grid ${config}.spc4
[73]331 grid ${config}.acquire -sticky ew -pady 3 -padx 5
332 grid ${config}.restart -sticky ew -pady 3 -padx 5
333 grid ${config}.register -sticky ew -pady 3 -padx 5
334
335 grid ${graph} -row 0 -column 0 -sticky news
336 grid ${config} -row 0 -column 1
337
[77]338 grid rowconfigure ${master} 0 -weight 1
339 grid columnconfigure ${master} 0 -weight 1
340 grid columnconfigure ${master} 1 -weight 0 -minsize 80
341
[73]342 # enable zooming
343 Blt_ZoomStack $graph
344
345 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
346
347 # create one element with data for the x and y axis, no dots
348 $graph element create Spectrum1 -symbol none -xdata $xvec -ydata $yvec
349 }
350
351# -------------------------------------------------------------------------
352
[85]353 OscDisplay instproc data_update args {
354 my instvar data yvec
355 $yvec set $data
356 }
357
358# -------------------------------------------------------------------------
359
[73]360 OscDisplay instproc auto_update args {
[74]361 my instvar config auto after_handle
[73]362
363 if {$auto} {
364 ${config}.acquire configure -state disabled
365 ${config}.restart configure -state disabled
366 ${config}.register configure -state disabled
367
368 my acquire_restart_loop
369 } else {
370 if {[my exists after_handle]} {
371 after cancel $after_handle
372 }
373 ${config}.acquire configure -state active
374 ${config}.restart configure -state active
375 ${config}.register configure -state active
376 }
377 }
378
379# -------------------------------------------------------------------------
380
381 OscDisplay instproc thrs_update args {
[74]382 my instvar config number thrs thrs_val
383
384 set val_addr [format %04x [expr {17 + ${number}}]]
385
[73]386 if {$thrs} {
387 ${config}.thrs_field configure -state normal
[74]388 my thrs_val_update
[73]389 } else {
390 ${config}.thrs_field configure -state disabled
[85]391 my usbCmd ${val_addr}0000
[73]392 }
393 }
394
395# -------------------------------------------------------------------------
396
[74]397 OscDisplay instproc thrs_val_update args {
398 my instvar config number thrs_val
399
[85]400 if {[string equal $thrs_val {}]} {
401 set thrs_val 0
402 }
403
[74]404 set val_addr [format %04x [expr {17 + ${number}}]]
405 set value [format %04x $thrs_val]
406
[85]407 my usbCmd ${val_addr}${value}
[73]408 }
409
410# -------------------------------------------------------------------------
411
[74]412 OscDisplay instproc mux {} {
413 my instvar trig_mux disp_mux
414
415 format {00%x%x} $trig_mux $disp_mux
416 }
417
418# ------------------------------------------------------------------------
419
420 OscDisplay instproc disp_val_update args {
421 my instvar number disp_val disp_mux
422
423 set mux_addr [format %04x [expr {20 + ${number}}]]
424
425 switch -- $disp_val {
426 data {
427 set disp_mux 0
[85]428 my usbCmd ${mux_addr}[my mux]
[74]429 }
430 uwt1 {
431 set disp_mux 1
[85]432 my usbCmd ${mux_addr}[my mux]
[74]433 }
434 uwt2 {
435 set disp_mux 2
[85]436 my usbCmd ${mux_addr}[my mux]
[74]437 }
438 uwt3 {
439 set disp_mux 3
[85]440 my usbCmd ${mux_addr}[my mux]
[74]441 }
442 base {
443 set disp_mux 4
[85]444 my usbCmd ${mux_addr}[my mux]
[74]445 }
446 }
447 }
448
449# ------------------------------------------------------------------------
450
451 OscDisplay instproc trig_val_update args {
452 my instvar number trig_val trig_mux
453
454 set mux_addr [format %04x [expr {20 + ${number}}]]
455
456 switch -- $trig_val {
457 data {
458 set trig_mux 0
[85]459 my usbCmd ${mux_addr}[my mux]
[74]460 }
461 uwt1 {
462 set trig_mux 1
[85]463 my usbCmd ${mux_addr}[my mux]
[74]464 }
465 uwt2 {
466 set trig_mux 2
[85]467 my usbCmd ${mux_addr}[my mux]
[74]468 }
469 uwt3 {
470 set trig_mux 3
[85]471 my usbCmd ${mux_addr}[my mux]
[74]472 }
473 base {
474 set trig_mux 4
[85]475 my usbCmd ${mux_addr}[my mux]
[74]476 }
477 }
478 }
479
480# -------------------------------------------------------------------------
481
[73]482 OscDisplay instproc save_data {data} {
483 set file [tk_getSaveFile]
484 if {[string equal $file {}]} {
485 return
486 }
487
488 set x [catch {set fid [open $file w+]}]
489 set y [catch {puts $fid $data}]
490 set z [catch {close $fid}]
491
492 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
493 tk_messageBox -icon error \
494 -message "An error occurred while writing to \"$file\""
495 } else {
496 tk_messageBox -icon info \
497 -message "File \"$file\" written successfully"
498 }
499 }
500
501# -------------------------------------------------------------------------
502
[85]503 OscDisplay instproc acquire {} {
504 my instvar number
505 my usbCmdRead 0002000${number} 2 1024
506 }
[73]507
508# -------------------------------------------------------------------------
509
510 OscDisplay instproc restart {} {
[85]511 my instvar number
512 my usbCmd 0001000${number}
[73]513 }
514
515# -------------------------------------------------------------------------
516
[85]517 OscDisplay instproc register {} {
518 my save_data [my set data]
[73]519 }
520
521# -------------------------------------------------------------------------
522
523 OscDisplay instproc acquire_restart_loop {} {
[85]524 my instvar number after_handle
[73]525
526 my acquire
527 my restart
528
529 set after_handle [after 1000 [myproc acquire_restart_loop]]
530 }
531
532# -------------------------------------------------------------------------
533
[85]534 Class HstDisplay -superclass Display -parameter {
[73]535 {number}
536 {master}
537 }
538
539# -------------------------------------------------------------------------
540
541 HstDisplay instproc init {} {
542 my instvar data xvec yvec
543
544 set xvec [vector #auto]
545 set yvec [vector #auto]
546 # fill one vector for the x axis with 4097 points
547 $xvec seq 0 4096
548
549 my reset
550
551 my setup
552
553 next
554 }
555
556# -------------------------------------------------------------------------
557
558 HstDisplay instproc destroy {} {
559 next
560 }
561
562# -------------------------------------------------------------------------
563
564 HstDisplay instproc reset {} {
565 my instvar data xvec yvec
566
[74]567 set data {}
[73]568
569 $yvec set {}
570 }
571
572# -------------------------------------------------------------------------
573
574 HstDisplay instproc start {} {
[74]575 my instvar config base_mux peak_mux
[73]576
[74]577 set base_mux 0
[73]578 set peak_mux 1
579
[85]580 trace add variable [myvar axis] write [myproc axis_update]
581 trace add variable [myvar data] write [myproc data_update]
[73]582 trace add variable [myvar auto] write [myproc auto_update]
583 trace add variable [myvar peak] write [myproc peak_update]
584 trace add variable [myvar thrs] write [myproc thrs_update]
[74]585 trace add variable [myvar thrs_val] write [myproc thrs_val_update]
[73]586 trace add variable [myvar base] write [myproc base_update]
587 trace add variable [myvar base_typ] write [myproc base_typ_update]
588 trace add variable [myvar base_val] write [myproc base_val_update]
589
[85]590 ${config}.axis_check deselect
[73]591 ${config}.auto_check select
592 ${config}.peak_check select
[85]593
[73]594 ${config}.thrs_check select
[85]595 ${config}.thrs_field set 1278
596
[73]597 ${config}.base_const select
598 ${config}.base_field set 35
[85]599 ${config}.base_check deselect
[73]600 }
601
602# -------------------------------------------------------------------------
603
604 HstDisplay instproc setup {} {
605 my instvar number master
[85]606 my instvar data xvec yvec graph
[73]607 my instvar config auto thrs thrs_val base base_typ base_val
608
609 # create a graph widget and show a grid
610 set graph [graph ${master}.graph -height 250 -leftmargin 80]
611 $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
612 $graph grid configure -hide no
613 $graph legend configure -hide yes
614 $graph axis configure x -min 0 -max 4096
615
616 set config [frame ${master}.config]
617
[85]618 checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis]
[73]619
620 frame ${config}.spc1 -width 10 -height 10
621
[85]622 checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
[73]623
624 frame ${config}.spc2 -width 10 -height 10
625
[85]626 checkbutton ${config}.peak_check -text {peak detect} -variable [myvar peak]
627
628 frame ${config}.spc3 -width 10 -height 10
629
[73]630 checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
631 spinbox ${config}.thrs_field -from 1 -to 4095 \
632 -increment 5 -width 10 -textvariable [myvar thrs_val] \
[85]633 -validate all -vcmd {::mca::validate 4095 %P}
[73]634
[85]635 frame ${config}.spc4 -width 10 -height 10
[73]636
637 checkbutton ${config}.base_check -text baseline -variable [myvar base]
638 radiobutton ${config}.base_auto -text automatic -variable [myvar base_typ] -value auto
639 radiobutton ${config}.base_const -text constant -variable [myvar base_typ] -value const
640 spinbox ${config}.base_field -from 1 -to 4095 \
641 -increment 5 -width 10 -textvariable [myvar base_val] \
[85]642 -validate all -vcmd {::mca::validate 4095 %P}
[73]643
[85]644 frame ${config}.spc5 -width 10 -height 10
[73]645
646 button ${config}.acquire -text Acquire \
647 -bg green -activebackground green -command [myproc acquire]
648 button ${config}.restart -text Restart \
649 -bg yellow -activebackground yellow -command [myproc restart]
650 button ${config}.register -text Register \
651 -bg lightblue -activebackground lightblue -command [myproc register]
652
[85]653 grid ${config}.axis_check -sticky w
654 grid ${config}.spc1
[73]655 grid ${config}.auto_check -sticky w
[85]656 grid ${config}.spc2
[73]657 grid ${config}.peak_check -sticky w
[85]658 grid ${config}.spc3
[73]659 grid ${config}.thrs_check -sticky w
660 grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
[85]661 grid ${config}.spc4
[73]662 grid ${config}.base_check -sticky w
663 grid ${config}.base_auto -sticky w
664 grid ${config}.base_const -sticky w
665 grid ${config}.base_field -sticky ew -pady 1 -padx 5
[85]666 grid ${config}.spc5
[73]667 grid ${config}.acquire -sticky ew -pady 3 -padx 5
668 grid ${config}.restart -sticky ew -pady 3 -padx 5
669 grid ${config}.register -sticky ew -pady 3 -padx 5
670
671 grid ${graph} -row 0 -column 0 -sticky news
672 grid ${config} -row 0 -column 1
673
[77]674 grid rowconfigure ${master} 0 -weight 1
675 grid columnconfigure ${master} 0 -weight 1
676 grid columnconfigure ${master} 1 -weight 0 -minsize 80
677
[73]678 # enable zooming
679 Blt_ZoomStack $graph
680
681 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
682
683 # create one element with data for the x and y axis, no dots
684 $graph element create Spectrum1 -symbol none -smooth step -xdata $xvec -ydata $yvec
685 }
686
687# -------------------------------------------------------------------------
688
[85]689 HstDisplay instproc axis_update args {
690 my instvar axis graph
691 if {$axis} {
692 $graph axis configure y -min 1 -max 1E10 -logscale yes
693 } else {
694 $graph axis configure y -min {} -max {} -logscale no
695 }
696 }
697
698# -------------------------------------------------------------------------
699
700 HstDisplay instproc data_update args {
701 my instvar data yvec
702 $yvec set $data
703 }
704
705# -------------------------------------------------------------------------
706
[73]707 HstDisplay instproc auto_update args {
708 my instvar auto after_handle
709 my instvar config
710 if {$auto} {
711 ${config}.acquire configure -state disabled
712 ${config}.register configure -state disabled
713
714 my acquire_loop
715 } else {
716 if {[my exists after_handle]} {
717 after cancel $after_handle
718 }
719 ${config}.acquire configure -state active
720 ${config}.register configure -state active
721 }
722 }
723
724# -------------------------------------------------------------------------
725
726 HstDisplay instproc mux {} {
[74]727 my instvar base_mux peak_mux
[73]728
[74]729 format {00%x%x} $base_mux $peak_mux
[73]730 }
731
732# -------------------------------------------------------------------------
733
734 HstDisplay instproc peak_update args {
735 my instvar number peak peak_mux
736
[74]737 set mux_addr [format %04x [expr {23 + ${number}}]]
[73]738
739 if {$peak} {
740 set peak_mux 1
[85]741 my usbCmd ${mux_addr}[my mux]
[73]742 } else {
743 set peak_mux 0
[85]744 my usbCmd ${mux_addr}[my mux]
[73]745 }
746 }
747
748# -------------------------------------------------------------------------
749
750 HstDisplay instproc thrs_update args {
751 my instvar config number thrs thrs_val
752
753 set val_addr [format %04x [expr {14 + ${number}}]]
754
755 if {$thrs} {
756 ${config}.thrs_field configure -state normal
[74]757 my thrs_val_update
[73]758 } else {
759 ${config}.thrs_field configure -state disabled
[85]760 my usbCmd ${val_addr}0000
[73]761 }
762 }
763
764# -------------------------------------------------------------------------
765
766 HstDisplay instproc thrs_val_update args {
767 my instvar config number thrs_val
768
[85]769 if {[string equal $thrs_val {}]} {
770 set thrs_val 0
771 }
772
[73]773 set val_addr [format %04x [expr {14 + ${number}}]]
774 set value [format %04x $thrs_val]
775
[85]776 my usbCmd ${val_addr}${value}
[73]777 }
778
779# -------------------------------------------------------------------------
780
781 HstDisplay instproc base_update args {
782 my instvar config number base base_val base_mux
783
[74]784 set mux_addr [format %04x [expr {23 + ${number}}]]
[73]785 set val_addr [format %04x [expr {11 + ${number}}]]
786
787 if {$base} {
788 ${config}.base_auto configure -state normal
789 ${config}.base_const configure -state normal
790 my base_typ_update
791 } else {
792 ${config}.base_auto configure -state disabled
793 ${config}.base_const configure -state disabled
794 ${config}.base_field configure -state disabled
795 set base_mux 0
[85]796 my usbCmd ${mux_addr}[my mux]${val_addr}0000
[73]797 }
798 }
799
800# -------------------------------------------------------------------------
801
802 HstDisplay instproc base_typ_update args {
803 my instvar config number base_typ base_val base_mux
804
[74]805 set mux_addr [format %04x [expr {23 + ${number}}]]
[73]806 set val_addr [format %04x [expr {11 + ${number}}]]
807 set value [format %04x $base_val]
808
809 switch -- $base_typ {
810 auto {
811 ${config}.base_field configure -state disabled
812 set base_mux 1
[85]813 my usbCmd ${mux_addr}[my mux]
[73]814 }
815 const {
816 ${config}.base_field configure -state normal
817 set base_mux 0
[85]818 my usbCmd ${mux_addr}[my mux]${val_addr}${value}
[73]819 }
820 }
821 }
822
823# -------------------------------------------------------------------------
824
825 HstDisplay instproc base_val_update args {
826 my instvar number base_val
827
[85]828 if {[string equal $base_val {}]} {
829 set base_val 0
830 }
831
[73]832 set val_addr [format %04x [expr {11 + ${number}}]]
833 set value [format %04x $base_val]
834
[85]835 my usbCmd ${val_addr}${value}
[73]836 }
837
838# -------------------------------------------------------------------------
839
[85]840 HstDisplay instproc acquire {} {
841 my instvar number
842 my usbCmdRead 0002001${number} 4 4096
843 }
844
845# -------------------------------------------------------------------------
846
847 HstDisplay instproc restart {} {
848 my instvar number
849 my usbCmd 0001001${number}
850 }
851
852# -------------------------------------------------------------------------
853
[73]854 HstDisplay instproc save_data {data} {
855 set file [tk_getSaveFile]
856 if {[string equal $file {}]} {
857 return
858 }
859
860 set x [catch {set fid [open $file w+]}]
861 set y [catch {puts $fid $data}]
862 set z [catch {close $fid}]
863
864 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
865 tk_messageBox -icon error \
866 -message "An error occurred while writing to \"$file\""
867 } else {
868 tk_messageBox -icon info \
869 -message "File \"$file\" written successfully"
870 }
871 }
872
873# -------------------------------------------------------------------------
874
875 HstDisplay instproc register {} {
876 my save_data [my set data]
877 }
878
879# -------------------------------------------------------------------------
880
[85]881 HstDisplay instproc acquire_loop {} {
882 my instvar number after_handle
[73]883
[85]884 my acquire
885
886 set after_handle [after 1000 [myproc acquire_loop]]
887 }
888
889# -------------------------------------------------------------------------
890
891 Class EptDisplay -superclass Display -parameter {
892 {number}
893 {master}
894 }
895
896# -------------------------------------------------------------------------
897
898 EptDisplay instproc init {} {
899 my instvar data xvec yvec
900
901 set xvec [vector #auto]
902
903 for {set i 0} {$i < 11} {incr i} {
904 set yvec($i) [vector #auto]
[73]905 }
[85]906
907 # fill one vector for the x axis
908 $xvec seq 0 10000
909
910 my reset
911
912 my setup
913
914 next
[73]915 }
916
917# -------------------------------------------------------------------------
918
[85]919 EptDisplay instproc destroy {} {
920 next
[73]921 }
922
923# -------------------------------------------------------------------------
924
[85]925 EptDisplay instproc reset {} {
926 my instvar data xvec yvec
927 my instvar number_val directory
[73]928
[85]929 set data {}
[73]930
[85]931 set directory $::env(HOMEPATH)
932 set number_val 10
933
934 for {set i 0} {$i < 11} {incr i} {
935 $yvec($i) set {}
[73]936 }
[85]937 }
[73]938
[85]939# -------------------------------------------------------------------------
[73]940
[85]941 EptDisplay instproc start {} {
942 my instvar config
943
944 trace add variable [myvar recs_val] write [myproc recs_val_update]
945 trace add variable [myvar data] write [myproc data_update]
946 trace add variable [myvar last] write [myproc data_update]
947
[73]948 }
949
950# -------------------------------------------------------------------------
951
[85]952 EptDisplay instproc setup {} {
953 my instvar master
954 my instvar data xvec yvec graph
955 my instvar config number_val
956
957 # create a graph widget and show a grid
958 set display [frame ${master}.display]
959
960 set graph(0) [graph ${display}.graph0 -height 200 -leftmargin 80]
961 $graph(0) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
962 $graph(0) grid configure -hide no
963 $graph(0) legend configure -hide yes
964 $graph(0) axis configure x -min 0 -max 10000
965 $graph(0) axis configure y -min 0 -max 4100
966
967 set graph(1) [graph ${display}.graph1 -height 200 -leftmargin 80]
968 $graph(1) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
969 $graph(1) grid configure -hide no
970 $graph(1) legend configure -hide yes
971 $graph(1) axis configure x -min 0 -max 10000 -hide yes
972 $graph(1) axis configure y -min 0 -max 4100
973
974 set graph(2) [graph ${display}.graph2 -height 200 -leftmargin 80]
975 $graph(2) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
976 $graph(2) grid configure -hide no
977 $graph(2) legend configure -hide yes
978 $graph(2) axis configure x -min 0 -max 10000 -hide yes
979 $graph(2) axis configure y -min 0 -max 4100
980
981 set graph(3) [graph ${display}.graph3 -height 100 -leftmargin 80]
982 $graph(3) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
983 $graph(3) grid configure -hide no
984 $graph(3) legend configure -hide yes
985 $graph(3) axis configure x -min 0 -max 10000 -hide yes
986 $graph(3) axis configure y -min 0 -max 25
987
988 scale ${master}.last -orient horizontal -from 1 -to 35 -tickinterval 0 -showvalue no -variable [myvar last]
989
990 set config [frame ${master}.config -width 120]
991
992 label ${config}.recs -text {number of records}
993 spinbox ${config}.recs_field -from 5 -to 100 \
994 -increment 5 -width 10 -textvariable [myvar recs_val] \
995 -validate all -vcmd {::mca::validate 100 %P}
996
997 frame ${config}.spc1 -width 10 -height 10
998
999 button ${config}.sequence -text {Start Recording} \
1000 -bg red -activebackground red -command [myproc sequence]
1001
1002 frame ${config}.spc2 -width 10 -height 10
1003
1004 label ${config}.stat -text {}
1005
1006 frame ${config}.spc3 -width 10 -height 20
1007
1008 button ${config}.acquire -text Acquire \
1009 -bg green -activebackground green -command [myproc acquire]
1010 button ${config}.register -text Register \
1011 -bg lightblue -activebackground lightblue -command [myproc register]
1012
1013
1014 grid ${config}.recs -sticky w -pady 1 -padx 3
1015 grid ${config}.recs_field -sticky ew -pady 1 -padx 5
1016 grid ${config}.spc1
1017 grid ${config}.sequence -sticky ew -pady 3 -padx 5
1018 grid ${config}.spc2
1019 grid ${config}.stat -sticky w -pady 1 -padx 3
1020 grid ${config}.spc3
1021 grid ${config}.acquire -sticky ew -pady 3 -padx 5
1022 grid ${config}.register -sticky ew -pady 3 -padx 5
1023
1024 grid ${graph(3)} -row 0 -column 0 -sticky news
1025 grid ${graph(2)} -row 1 -column 0 -sticky news
1026 grid ${graph(1)} -row 2 -column 0 -sticky news
1027 grid ${graph(0)} -row 3 -column 0 -sticky news
1028
1029 grid ${display} -row 0 -column 0 -sticky news
1030 grid ${config} -row 0 -column 1
1031
1032 grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew
1033
1034 grid rowconfigure ${master} 0 -weight 1
1035 grid columnconfigure ${master} 0 -weight 1
1036 grid columnconfigure ${master} 1 -weight 0 -minsize 120
1037
1038 grid columnconfigure ${display} 0 -weight 1
1039 grid rowconfigure ${display} 0 -weight 1
1040 grid rowconfigure ${display} 1 -weight 1
1041 grid rowconfigure ${display} 2 -weight 1
1042 grid rowconfigure ${display} 3 -weight 1
1043
1044 # enable zooming
1045 Blt_ZoomStack $graph(0)
1046 Blt_ZoomStack $graph(1)
1047 Blt_ZoomStack $graph(2)
1048 Blt_ZoomStack $graph(3)
1049
1050 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
1051
1052 # create one element with data for the x and y axis, no dots
1053 $graph(0) element create Spectrum0 -symbol none -xdata $xvec -ydata $yvec(0)
1054 $graph(1) element create Spectrum1 -symbol none -xdata $xvec -ydata $yvec(1)
1055 $graph(2) element create Spectrum2 -symbol none -xdata $xvec -ydata $yvec(2)
1056 for {set i 3} {$i < 11} {incr i} {
1057 $graph(3) element create Spectrum$i -symbol none -xdata $xvec -ydata $yvec($i)
1058 }
1059 }
1060
1061# -------------------------------------------------------------------------
1062
1063 EptDisplay instproc recs_val_update args {
1064 my instvar recs_val
1065 if {[string equal $recs_val {}]} {
1066 set number_val 0
1067 }
1068 }
1069
1070# -------------------------------------------------------------------------
1071
1072 EptDisplay instproc data_update args {
1073 my instvar data xvec yvec graph last
1074
1075 set first [expr {$last - 1}]
1076
1077 $xvec seq ${first}0000 ${last}0000
1078 for {set i 0} {$i < 4} {incr i} {
1079 $graph($i) axis configure x -min ${first}0000 -max ${last}0000
1080 }
1081
1082 for {set i 0} {$i < 11} {incr i} {
1083 $yvec($i) set [lrange [lindex $data $i] ${first}0000 ${last}0000]
1084 }
1085 }
1086
1087
1088# -------------------------------------------------------------------------
1089
1090 EptDisplay instproc save_data {data} {
1091 set file [tk_getSaveFile]
1092 if {[string equal $file {}]} {
1093 return
1094 }
1095
1096 set x [catch {set fid [open $file w+]}]
1097 set y [catch {puts $fid $data}]
1098 set z [catch {close $fid}]
1099
1100 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
1101 tk_messageBox -icon error \
1102 -message "An error occurred while writing to \"$file\""
1103 } else {
1104 tk_messageBox -icon info \
1105 -message "File \"$file\" written successfully"
1106 }
1107 }
1108
1109# -------------------------------------------------------------------------
1110
1111 EptDisplay instproc acquire {} {
1112 my usbCmdReadEpt 00060000 2097152
1113 }
1114
1115# -------------------------------------------------------------------------
1116
1117 EptDisplay instproc register {} {
1118 my save_data [my set data]
1119 }
1120
1121# -------------------------------------------------------------------------
1122
1123 EptDisplay instproc sequence {} {
1124 my instvar config recs_val directory counter
1125
1126 set directory [tk_chooseDirectory -initialdir $directory -title {Choose a directory}]
1127
1128 if {[string equal $directory {}]} {
1129 return
1130 }
1131
1132 ${config}.recs_field configure -state disabled
1133 ${config}.sequence configure -state disabled
1134 ${config}.acquire configure -state disabled
1135 ${config}.register configure -state disabled
1136
1137 set counter 1
1138
1139 if {$counter <= $recs_val} {
1140 ${config}.stat configure -text "record $counter of $recs_val"
1141 set after_handle [after 100 [myproc acquire_register_loop]]
1142 }
1143 }
1144
1145# -------------------------------------------------------------------------
1146
1147 EptDisplay instproc acquire_register_loop {} {
[73]1148 my instvar after_handle
[85]1149 my instvar config data recs_val directory counter
[73]1150
1151 my acquire
1152
[85]1153 set file [file join $directory ept_$counter.dat.gz]
1154
1155 set x [catch {set fid [open $file w+]}]
1156 fconfigure $fid -translation binary -encoding binary
1157
1158 set y [catch {
1159 puts -nonewline $fid [binary format "H*iH*" "1f8b0800" [clock seconds] "0003"]
1160 puts -nonewline $fid [zlib deflate $data]
1161 puts -nonewline $fid [binary format i [zlib crc32 $data]]
1162 puts -nonewline $fid [binary format i [string length $data]]
1163 }]
1164
1165 set z [catch {close $fid}]
1166
1167 my incr counter
1168
1169 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
1170 tk_messageBox -icon error -message "An error occurred while writing to \"$file\""
1171 } elseif {$counter <= $recs_val} {
1172 ${config}.stat configure -text "record $counter of $recs_val"
1173 set after_handle [after 100 [myproc acquire_register_loop]]
1174 return
1175 }
1176
1177 ${config}.stat configure -text {}
1178 ${config}.recs_field configure -state normal
1179 ${config}.sequence configure -state active
1180 ${config}.acquire configure -state active
1181 ${config}.register configure -state active
1182
[73]1183 }
1184
1185# -------------------------------------------------------------------------
1186
[85]1187 Class MemDisplay -superclass Display -parameter {
1188 {number}
1189 {master}
1190 }
1191
1192# -------------------------------------------------------------------------
1193
1194 MemDisplay instproc init {} {
1195 my instvar data xvec yvec
1196
1197 set xvec [vector #auto]
1198 set yvec [vector #auto]
1199
1200 # fill one vector for the x axis
1201 $xvec seq 0 10000
1202
1203 my reset
1204
1205 my setup
1206
1207 next
1208 }
1209
1210# -------------------------------------------------------------------------
1211
1212 MemDisplay instproc destroy {} {
1213 next
1214 }
1215
1216# -------------------------------------------------------------------------
1217
1218 MemDisplay instproc reset {} {
1219 my instvar data xvec yvec
1220
1221 set data {}
1222
1223 $yvec set {}
1224 }
1225
1226# -------------------------------------------------------------------------
1227
1228 MemDisplay instproc start {} {
1229 my instvar config
1230
1231 trace add variable [myvar data] write [myproc data_update]
1232 trace add variable [myvar last] write [myproc data_update]
1233 }
1234
1235# -------------------------------------------------------------------------
1236
1237 MemDisplay instproc setup {} {
1238 my instvar master
1239 my instvar data xvec yvec
1240 my instvar config auto thrs thrs_val disp_val trig_val
1241
1242 # create a graph widget and show a grid
1243 set graph [graph ${master}.graph -height 250 -leftmargin 80]
1244 $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
1245 $graph grid configure -hide no
1246 $graph legend configure -hide yes
1247 $graph axis configure x -min 0 -max 10000
1248# $graph axis configure y -min 0 -max 4100
1249
1250 scale ${master}.last -orient horizontal -from 1 -to 105 -tickinterval 0 -variable [myvar last]
1251
1252 set config [frame ${master}.config]
1253
1254 button ${config}.acquire -text Acquire \
1255 -bg green -activebackground green -command [myproc acquire]
1256 button ${config}.register -text Register \
1257 -bg lightblue -activebackground lightblue -command [myproc register]
1258
1259 grid ${config}.acquire -sticky ew -pady 3 -padx 5
1260 grid ${config}.register -sticky ew -pady 3 -padx 5
1261
1262 grid ${graph} -row 0 -column 0 -sticky news
1263 grid ${config} -row 0 -column 1
1264
1265 grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew
1266
1267 grid rowconfigure ${master} 0 -weight 1
1268 grid columnconfigure ${master} 0 -weight 1
1269 grid columnconfigure ${master} 1 -weight 0 -minsize 80
1270
1271 # enable zooming
1272 Blt_ZoomStack $graph
1273
1274 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
1275
1276 # create one element with data for the x and y axis, no dots
1277 $graph element create Spectrum -symbol none -xdata $xvec -ydata $yvec
1278 }
1279
1280# -------------------------------------------------------------------------
1281
1282 MemDisplay instproc data_update args {
1283 my instvar data yvec last
1284
1285 set first [expr {$last - 1}]
1286 $yvec set [lrange $data ${first}0000 ${last}0000]
1287 }
1288
1289# -------------------------------------------------------------------------
1290
1291 MemDisplay instproc save_data {data} {
1292 set file [tk_getSaveFile]
1293 if {[string equal $file {}]} {
1294 return
1295 }
1296
1297 set x [catch {set fid [open $file w+]}]
1298 set y [catch {puts $fid $data}]
1299 set z [catch {close $fid}]
1300
1301 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
1302 tk_messageBox -icon error \
1303 -message "An error occurred while writing to \"$file\""
1304 } else {
1305 tk_messageBox -icon info \
1306 -message "File \"$file\" written successfully"
1307 }
1308 }
1309
1310# -------------------------------------------------------------------------
1311
1312 MemDisplay instproc acquire {} {
1313 my usbCmdRead 00040000 1 524288
1314# my usbCmdRead 00060000 1 1048576
1315 }
1316
1317# -------------------------------------------------------------------------
1318
1319 MemDisplay instproc register {} {
1320 my save_data [my set data]
1321 }
1322
1323# -------------------------------------------------------------------------
1324
1325 namespace export MemDisplay
1326 namespace export EptDisplay
[73]1327 namespace export HstDisplay
1328 namespace export OscDisplay
[77]1329 namespace export CfgDisplay
[73]1330}
1331
[78]1332set config [frame .config]
1333set notebook [::blt::tabnotebook .notebook -borderwidth 1 -selectforeground black -side bottom]
[73]1334
[78]1335grid ${config} -row 0 -column 0 -sticky ns -padx 3
1336grid ${notebook} -row 0 -column 1 -sticky news -pady 5
[73]1337
[78]1338grid rowconfigure . 0 -weight 1
[82]1339grid columnconfigure . 0 -weight 0 -minsize 50
[78]1340grid columnconfigure . 1 -weight 1
1341
[77]1342foreach i {0 1 2} {
1343 set channel [expr $i + 1]
[73]1344
[77]1345 set window [frame ${notebook}.hst_$i]
1346 $notebook insert end -text "Histogram $channel" -window $window -fill both
1347 ::mca::HstDisplay hst_$i -number $i -master $window
[73]1348
[77]1349 set window [frame ${notebook}.osc_$i]
1350 $notebook insert end -text "Pulse shape $channel" -window $window -fill both
1351 ::mca::OscDisplay osc_$i -number $i -master $window
1352}
[73]1353
[78]1354#set window [frame ${notebook}.cfg]
1355#$notebook insert end -text "Configuration" -window $window -fill both
1356::mca::CfgDisplay cfg -master $config
[73]1357
[85]1358set window [frame ${notebook}.ept]
1359$notebook insert end -text "EPT" -window $window -fill both
1360::mca::EptDisplay ept -master $window
1361
1362#set window [frame ${notebook}.mem]
1363#$notebook insert end -text "Memory test" -window $window -fill both
1364#::mca::MemDisplay mem -master $window
1365
[73]1366set usb_handle {}
1367
1368while {[catch {usb::connect 0x09FB 0x6001 1 1 0} usb_handle]} {
1369 set answer [tk_messageBox -icon error -type retrycancel \
1370 -message {Cannot access USB device} -detail $usb_handle]
[85]1371 if {[string equal $answer cancel]} break
[73]1372}
1373
[77]1374# cfg reset
[85]1375cfg reset
[73]1376
[77]1377cfg start
1378
1379foreach i {0 1 2} {
1380 hst_$i start
1381 osc_$i start
1382
1383 hst_$i restart
1384 osc_$i restart
1385}
[85]1386
1387ept start
1388#mem start
Note: See TracBrowser for help on using the repository browser.