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