1 | package require XOTcl
|
---|
2 |
|
---|
3 | package require BLT
|
---|
4 | package require swt
|
---|
5 | package require usb
|
---|
6 |
|
---|
7 | package require zlib
|
---|
8 |
|
---|
9 | wm minsize . 1000 700
|
---|
10 |
|
---|
11 | namespace eval ::mca {
|
---|
12 | namespace import ::xotcl::*
|
---|
13 |
|
---|
14 | namespace import ::blt::vector
|
---|
15 | namespace import ::blt::graph
|
---|
16 | namespace import ::blt::tabnotebook
|
---|
17 |
|
---|
18 | # -------------------------------------------------------------------------
|
---|
19 |
|
---|
20 | variable oscCodes
|
---|
21 | array set oscCodes {
|
---|
22 | 1 {Channel 1}
|
---|
23 | 2 {Channel 2}
|
---|
24 | 3 {Channel 3}
|
---|
25 | 4 {Channel 4}
|
---|
26 | 5 {Channel 5}
|
---|
27 | 6 {Trigger}
|
---|
28 | }
|
---|
29 |
|
---|
30 | # -------------------------------------------------------------------------
|
---|
31 |
|
---|
32 | variable adcCodes
|
---|
33 | array set adcCodes {
|
---|
34 | 1 {S1_F}
|
---|
35 | 2 {S1_S}
|
---|
36 | 3 {S2}
|
---|
37 | 4 {D1}
|
---|
38 | 5 {D2}
|
---|
39 | 6 {D3}
|
---|
40 | }
|
---|
41 |
|
---|
42 | # -------------------------------------------------------------------------
|
---|
43 |
|
---|
44 | variable cfgCodes
|
---|
45 | array set cfgCodes {
|
---|
46 | {1_0} 0
|
---|
47 | {1_1} 6
|
---|
48 | {2_0} 1
|
---|
49 | {2_1} 7
|
---|
50 | {3_0} 2
|
---|
51 | {3_1} 8
|
---|
52 | {3_2} 9
|
---|
53 | {3_3} 10
|
---|
54 | {4_0} 3
|
---|
55 | {4_1} 11
|
---|
56 | {4_2} 12
|
---|
57 | {4_3} 13
|
---|
58 | {5_0} 4
|
---|
59 | {5_1} 14
|
---|
60 | {5_2} 15
|
---|
61 | {5_3} 16
|
---|
62 | {6_0} 5
|
---|
63 | {6_1} 17
|
---|
64 | {6_2} 18
|
---|
65 | {6_3} 19
|
---|
66 | }
|
---|
67 | # -------------------------------------------------------------------------
|
---|
68 |
|
---|
69 | variable cfgThrs
|
---|
70 | array set cfgThrs {
|
---|
71 | 0 8
|
---|
72 | 6 50
|
---|
73 | 1 8
|
---|
74 | 7 50
|
---|
75 | 2 10
|
---|
76 | 8 31
|
---|
77 | 9 52
|
---|
78 | 10 79
|
---|
79 | 3 60
|
---|
80 | 11 135
|
---|
81 | 12 171
|
---|
82 | 13 233
|
---|
83 | 4 249
|
---|
84 | 14 348
|
---|
85 | 15 495
|
---|
86 | 16 693
|
---|
87 | 5 505
|
---|
88 | 17 606
|
---|
89 | 18 707
|
---|
90 | 19 808
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | # -------------------------------------------------------------------------
|
---|
95 |
|
---|
96 | variable inpCodes
|
---|
97 | array set inpCodes {
|
---|
98 | 0 {rs}
|
---|
99 | 1 {cs}
|
---|
100 | 2 {av}
|
---|
101 | 3 {af}
|
---|
102 | 4 {bn}
|
---|
103 | }
|
---|
104 |
|
---|
105 | # -------------------------------------------------------------------------
|
---|
106 |
|
---|
107 | proc validate {max size value} {
|
---|
108 | if {![regexp {^[0-9]*$} $value]} {
|
---|
109 | return 0
|
---|
110 | } elseif {[regexp {^0[0-9]+$} $value]} {
|
---|
111 | return 0
|
---|
112 | } elseif {$value > $max} {
|
---|
113 | return 0
|
---|
114 | } elseif {[string length $value] > $size} {
|
---|
115 | return 0
|
---|
116 | } else {
|
---|
117 | return 1
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | # -------------------------------------------------------------------------
|
---|
122 |
|
---|
123 | proc doublevalidate {max value} {
|
---|
124 | if {![regexp {^[0-9]{0,2}\.?[0-9]{0,3}$} $value]} {
|
---|
125 | return 0
|
---|
126 | } elseif {[regexp {^0[0-9]+$} $value]} {
|
---|
127 | return 0
|
---|
128 | } elseif {$value > $max} {
|
---|
129 | return 0
|
---|
130 | } else {
|
---|
131 | return 1
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | # -------------------------------------------------------------------------
|
---|
136 |
|
---|
137 | proc legendLabel {master row key title} {
|
---|
138 | label ${master}.${key}_label -anchor w -text ${title}
|
---|
139 | label ${master}.${key}_value -width 10 -anchor e -text {}
|
---|
140 |
|
---|
141 | grid ${master}.${key}_label -row ${row} -column 1 -sticky w
|
---|
142 | grid ${master}.${key}_value -row ${row} -column 2 -sticky ew
|
---|
143 | }
|
---|
144 |
|
---|
145 | # -------------------------------------------------------------------------
|
---|
146 |
|
---|
147 | proc legendButton {master row key title var bg {fg black}} {
|
---|
148 | checkbutton ${master}.${key}_check -variable $var
|
---|
149 | label ${master}.${key}_label -anchor w -text ${title} -bg ${bg} -fg $fg
|
---|
150 | label ${master}.${key}_value -width 10 -anchor e -text {} -bg ${bg} -fg $fg
|
---|
151 |
|
---|
152 | grid ${master}.${key}_check -row ${row} -column 0 -sticky w
|
---|
153 | grid ${master}.${key}_label -row ${row} -column 1 -sticky w
|
---|
154 | grid ${master}.${key}_value -row ${row} -column 2 -sticky ew
|
---|
155 | }
|
---|
156 |
|
---|
157 | # -------------------------------------------------------------------------
|
---|
158 |
|
---|
159 | Class UsbController
|
---|
160 |
|
---|
161 | # -------------------------------------------------------------------------
|
---|
162 |
|
---|
163 | UsbController instproc init {} {
|
---|
164 |
|
---|
165 | my set ignore false
|
---|
166 |
|
---|
167 | next
|
---|
168 | }
|
---|
169 |
|
---|
170 | # -------------------------------------------------------------------------
|
---|
171 |
|
---|
172 | UsbController instproc usbConnect {} {
|
---|
173 | my instvar handle ignore
|
---|
174 |
|
---|
175 | puts usbConnect
|
---|
176 |
|
---|
177 | if {[my exists handle]} {
|
---|
178 | $handle disconnect
|
---|
179 | unset handle
|
---|
180 | }
|
---|
181 | if {!$ignore} {
|
---|
182 | while {[catch {usb::connect 0x09FB 0x6001 1 1 0} result]} {
|
---|
183 | set answer [tk_messageBox -icon error -type abortretryignore \
|
---|
184 | -message {Cannot access USB device} -detail $result]
|
---|
185 | if {[string equal $answer abort]} exit
|
---|
186 | if {[string equal $answer ignore]} {
|
---|
187 | set ignore true
|
---|
188 | return
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | set handle $result
|
---|
193 |
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | # -------------------------------------------------------------------------
|
---|
198 |
|
---|
199 | UsbController instproc usbHandle {} {
|
---|
200 | my instvar handle ignore
|
---|
201 |
|
---|
202 | if {[my exists handle]} {
|
---|
203 | return $handle
|
---|
204 | } elseif {!$ignore} {
|
---|
205 | my usbConnect
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | # -------------------------------------------------------------------------
|
---|
210 |
|
---|
211 | UsbController instproc usbCmd {command} {
|
---|
212 | set code [catch {[my usbHandle] writeRaw [usb::convert $command]} result]
|
---|
213 | switch -- $code {
|
---|
214 | 1 {
|
---|
215 | # puts $result
|
---|
216 | my usbConnect
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | }
|
---|
221 |
|
---|
222 | # -------------------------------------------------------------------------
|
---|
223 |
|
---|
224 | UsbController instproc usbCmdReadRaw {command size data} {
|
---|
225 | my usbCmd $command
|
---|
226 |
|
---|
227 | set code [catch {[my usbHandle] readRaw $size} result]
|
---|
228 | switch -- $code {
|
---|
229 | 0 {
|
---|
230 | set $data $result
|
---|
231 | }
|
---|
232 | 1 {
|
---|
233 | # puts $result
|
---|
234 | my usbConnect
|
---|
235 | }
|
---|
236 | 5 {
|
---|
237 | # puts Busy
|
---|
238 | }
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 | # -------------------------------------------------------------------------
|
---|
243 |
|
---|
244 | UsbController instproc usbCmdReadRaw {command size data} {
|
---|
245 | my usbCmd $command
|
---|
246 |
|
---|
247 | set code [catch {[my usbHandle] readRaw $size} result]
|
---|
248 | switch -- $code {
|
---|
249 | 0 {
|
---|
250 | set $data $result
|
---|
251 | }
|
---|
252 | 1 {
|
---|
253 | # puts $result
|
---|
254 | my usbConnect
|
---|
255 | }
|
---|
256 | 5 {
|
---|
257 | # puts Busy
|
---|
258 | }
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | # -------------------------------------------------------------------------
|
---|
263 |
|
---|
264 | UsbController instproc usbCmdReadHex {command width size data} {
|
---|
265 | my usbCmd $command
|
---|
266 |
|
---|
267 | set code [catch {[my usbHandle] readHex $width $size} result]
|
---|
268 | switch -- $code {
|
---|
269 | 0 {
|
---|
270 | set $data $result
|
---|
271 | }
|
---|
272 | 1 {
|
---|
273 | # puts $result
|
---|
274 | my usbConnect
|
---|
275 | }
|
---|
276 | 5 {
|
---|
277 | # puts Busy
|
---|
278 | }
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | # -------------------------------------------------------------------------
|
---|
283 |
|
---|
284 | Class CfgDisplay -parameter {
|
---|
285 | {master}
|
---|
286 | {controller}
|
---|
287 | }
|
---|
288 |
|
---|
289 | # -------------------------------------------------------------------------
|
---|
290 |
|
---|
291 | CfgDisplay instproc init {} {
|
---|
292 |
|
---|
293 | my setup
|
---|
294 |
|
---|
295 | next
|
---|
296 | }
|
---|
297 |
|
---|
298 | # -------------------------------------------------------------------------
|
---|
299 |
|
---|
300 | CfgDisplay instproc destroy {} {
|
---|
301 | next
|
---|
302 | }
|
---|
303 |
|
---|
304 | # -------------------------------------------------------------------------
|
---|
305 |
|
---|
306 | CfgDisplay instproc start {} {
|
---|
307 | variable adcCodes
|
---|
308 | variable cfgThrs
|
---|
309 |
|
---|
310 | foreach {ch id} [array get adcCodes] {
|
---|
311 | my set delay($ch) 32
|
---|
312 | my set decay($ch) 1000
|
---|
313 | }
|
---|
314 |
|
---|
315 | foreach {i value} [array get cfgThrs] {
|
---|
316 | my set thrs($i) $value
|
---|
317 | }
|
---|
318 |
|
---|
319 | trace add variable [myvar decay] write [myproc decay_update]
|
---|
320 | trace add variable [myvar delay] write [myproc delay_update]
|
---|
321 | trace add variable [myvar thrs] write [myproc thrs_update]
|
---|
322 |
|
---|
323 | my delay_update
|
---|
324 | my thrs_update
|
---|
325 | }
|
---|
326 |
|
---|
327 | # -------------------------------------------------------------------------
|
---|
328 |
|
---|
329 | CfgDisplay instproc setup {} {
|
---|
330 | variable adcCodes
|
---|
331 | variable cfgCodes
|
---|
332 | my instvar number master
|
---|
333 | my instvar config
|
---|
334 |
|
---|
335 | set thrs [frame ${master}.thrs]
|
---|
336 | set bins [frame ${master}.bins]
|
---|
337 | set clip [frame ${master}.clip]
|
---|
338 |
|
---|
339 | set config(thrs) [labelframe ${thrs}.frame -borderwidth 1 -relief sunken -text {Thresholds}]
|
---|
340 |
|
---|
341 | set column 0
|
---|
342 | foreach {input} [list "ADC" "noise thrs" "e/p thrs"] {
|
---|
343 | label ${config(thrs)}.label_${column} -text "${input}"
|
---|
344 | grid ${config(thrs)}.label_${column} -row 0 -column ${column} -sticky ew -padx 5 -pady 7
|
---|
345 | incr column
|
---|
346 | }
|
---|
347 |
|
---|
348 | foreach {ch id} [array get adcCodes {[1-2]}] {
|
---|
349 | label ${config(thrs)}.chan_${ch} -text "${id} "
|
---|
350 | grid ${config(thrs)}.chan_${ch} -row ${ch} -column 0 -sticky ew -padx 5 -pady 7
|
---|
351 | foreach {num} [list 0 1] {
|
---|
352 | set column [expr {$num + 1}]
|
---|
353 | set value $cfgCodes(${ch}_${num})
|
---|
354 | spinbox ${config(thrs)}.thrs_${value} -from 0 -to 4095 \
|
---|
355 | -increment 10 -width 10 -textvariable [myvar thrs($value)] \
|
---|
356 | -validate all -vcmd {::mca::validate 4095 4 %P}
|
---|
357 | grid ${config(thrs)}.thrs_${value} -row ${ch} -column ${column} -sticky w -padx 5 -pady 7
|
---|
358 | }
|
---|
359 | }
|
---|
360 |
|
---|
361 | grid $config(thrs) -row 0 -column 0 -sticky news -padx 10
|
---|
362 |
|
---|
363 | set config(bins) [labelframe ${bins}.frame -borderwidth 1 -relief sunken -text {Thresholds}]
|
---|
364 |
|
---|
365 | set column 0
|
---|
366 | foreach {input} [list "ADC" "thrs 1" "thrs 2" "thrs 3" "thrs 4"] {
|
---|
367 | label ${config(bins)}.label_${column} -text "${input}"
|
---|
368 | grid ${config(bins)}.label_${column} -row 0 -column ${column} -sticky ew -padx 5 -pady 7
|
---|
369 | incr column
|
---|
370 | }
|
---|
371 |
|
---|
372 | foreach {ch id} [array get adcCodes {[3-6]}] {
|
---|
373 | label ${config(bins)}.chan_${ch} -text "${id} "
|
---|
374 | grid ${config(bins)}.chan_${ch} -row ${ch} -column 0 -sticky ew -padx 5 -pady 7
|
---|
375 | foreach {num} [list 0 1 2 3] {
|
---|
376 | set column [expr {$num + 1}]
|
---|
377 | set value $cfgCodes(${ch}_${num})
|
---|
378 | spinbox ${config(bins)}.thrs_${value} -from 0 -to 4095 \
|
---|
379 | -increment 10 -width 10 -textvariable [myvar thrs($value)] \
|
---|
380 | -validate all -vcmd {::mca::validate 4095 4 %P}
|
---|
381 | grid ${config(bins)}.thrs_${value} -row ${ch} -column ${column} -sticky w -padx 5 -pady 7
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 | grid $config(bins) -row 0 -column 0 -sticky news -padx 10
|
---|
386 |
|
---|
387 | set config(clip) [labelframe ${clip}.frame -borderwidth 1 -relief sunken -text {Signal clipping}]
|
---|
388 |
|
---|
389 | set column 0
|
---|
390 | foreach {input} [list "ADC" "delay" "decay"] {
|
---|
391 | label ${config(clip)}.label_${column} -text "${input}"
|
---|
392 | grid ${config(clip)}.label_${column} -row 0 -column ${column} -sticky ew -padx 5 -pady 7
|
---|
393 | incr column
|
---|
394 | }
|
---|
395 |
|
---|
396 | foreach {ch id} [array get adcCodes] {
|
---|
397 | label ${config(clip)}.chan_${ch} -text "${id} "
|
---|
398 | grid ${config(clip)}.chan_${ch} -row ${ch} -column 0 -sticky ew -padx 5 -pady 7
|
---|
399 | spinbox ${config(clip)}.delay_${ch} -from 0 -to 62 \
|
---|
400 | -increment 2 -width 10 -textvariable [myvar delay($ch)] \
|
---|
401 | -validate all -vcmd {::mca::validate 63 5 %P}
|
---|
402 | grid ${config(clip)}.delay_${ch} -row ${ch} -column 1 -sticky w -padx 5 -pady 7
|
---|
403 | spinbox ${config(clip)}.decay_${ch} -from 0 -to 65535 \
|
---|
404 | -increment 10 -width 10 -textvariable [myvar decay($ch)] \
|
---|
405 | -validate all -vcmd {::mca::validate 65535 5 %P}
|
---|
406 | grid ${config(clip)}.decay_${ch} -row ${ch} -column 2 -sticky w -padx 5 -pady 7
|
---|
407 | }
|
---|
408 |
|
---|
409 | grid $config(clip) -row 0 -column 0 -sticky news -padx 10
|
---|
410 |
|
---|
411 | grid ${thrs} -row 0 -column 2 -sticky news
|
---|
412 | grid ${bins} -row 0 -column 1 -sticky news
|
---|
413 | grid ${clip} -row 0 -column 0 -sticky news
|
---|
414 |
|
---|
415 | grid columnconfigure ${master} 0 -weight 1
|
---|
416 | grid columnconfigure ${master} 1 -weight 1
|
---|
417 | grid columnconfigure ${master} 2 -weight 1
|
---|
418 | grid rowconfigure ${master} 0 -weight 1
|
---|
419 |
|
---|
420 | grid rowconfigure ${thrs} 0 -weight 0
|
---|
421 | grid rowconfigure ${bins} 0 -weight 0
|
---|
422 | grid rowconfigure ${clip} 0 -weight 0
|
---|
423 | }
|
---|
424 |
|
---|
425 | # -------------------------------------------------------------------------
|
---|
426 |
|
---|
427 | CfgDisplay instproc decay_update args {
|
---|
428 | my instvar controller decay delay
|
---|
429 |
|
---|
430 | set command {}
|
---|
431 | for {set i 1} {$i <= 6} {incr i} {
|
---|
432 | set a $delay($i).0
|
---|
433 | set b $decay($i).0
|
---|
434 | set value [expr int(exp(-${a}/${b})*1024*20)]
|
---|
435 | append command [format {000200%02x0004%04x} [expr {30 + 2 * (${i} - 1)}] $value]
|
---|
436 | }
|
---|
437 |
|
---|
438 | $controller usbCmd $command
|
---|
439 | }
|
---|
440 |
|
---|
441 | # -------------------------------------------------------------------------
|
---|
442 |
|
---|
443 | CfgDisplay instproc delay_update args {
|
---|
444 | my instvar controller delay
|
---|
445 |
|
---|
446 | set command {}
|
---|
447 | for {set i 1} {$i <= 6} {incr i} {
|
---|
448 | append command [format {000200%02x0004%04x} [expr {31 + 2 * (${i} - 1)}] $delay($i)]
|
---|
449 | }
|
---|
450 |
|
---|
451 | $controller usbCmd $command
|
---|
452 |
|
---|
453 | my decay_update
|
---|
454 | }
|
---|
455 |
|
---|
456 | # -------------------------------------------------------------------------
|
---|
457 |
|
---|
458 | CfgDisplay instproc thrs_update args {
|
---|
459 | my instvar controller thrs
|
---|
460 |
|
---|
461 | set command {}
|
---|
462 | for {set i 0} {$i <= 19} {incr i} {
|
---|
463 | append command [format {000200%02x0004%04x} [expr {10 + ${i}}] $thrs($i)]
|
---|
464 | }
|
---|
465 |
|
---|
466 | $controller usbCmd $command
|
---|
467 | }
|
---|
468 |
|
---|
469 | # -------------------------------------------------------------------------
|
---|
470 |
|
---|
471 | Class MuxDisplay -parameter {
|
---|
472 | {master}
|
---|
473 | {controller}
|
---|
474 | }
|
---|
475 |
|
---|
476 | # -------------------------------------------------------------------------
|
---|
477 |
|
---|
478 | MuxDisplay instproc init {} {
|
---|
479 |
|
---|
480 | my setup
|
---|
481 |
|
---|
482 | next
|
---|
483 | }
|
---|
484 |
|
---|
485 | # -------------------------------------------------------------------------
|
---|
486 |
|
---|
487 | MuxDisplay instproc destroy {} {
|
---|
488 | next
|
---|
489 | }
|
---|
490 |
|
---|
491 | # -------------------------------------------------------------------------
|
---|
492 |
|
---|
493 | MuxDisplay instproc start {} {
|
---|
494 | variable adcCodes
|
---|
495 | my instvar config chan_val
|
---|
496 |
|
---|
497 | set chan_val(1) 0
|
---|
498 | set chan_val(2) 0
|
---|
499 | set chan_val(3) 0
|
---|
500 | set chan_val(4) 0
|
---|
501 | set chan_val(5) 0
|
---|
502 | set chan_val(6) 0
|
---|
503 |
|
---|
504 | trace add variable [myvar chan_val] write [myproc chan_val_update]
|
---|
505 | trace add variable [myvar polar] write [myproc polar_update]
|
---|
506 |
|
---|
507 | $config(1).chan_1_1 select
|
---|
508 | $config(2).chan_1_2 select
|
---|
509 | $config(3).chan_1_3 select
|
---|
510 | $config(4).chan_1_4 select
|
---|
511 | $config(5).chan_1_5 select
|
---|
512 | $config(6).chan_2_4 select
|
---|
513 |
|
---|
514 | foreach {ch dummy} [array get adcCodes] {
|
---|
515 | $config(inv).polar_${ch} deselect
|
---|
516 | }
|
---|
517 | }
|
---|
518 |
|
---|
519 | # -------------------------------------------------------------------------
|
---|
520 |
|
---|
521 | MuxDisplay instproc setup {} {
|
---|
522 | variable oscCodes
|
---|
523 | variable adcCodes
|
---|
524 | variable inpCodes
|
---|
525 | my instvar master
|
---|
526 | my instvar config
|
---|
527 |
|
---|
528 | set size [array size inpCodes]
|
---|
529 | set oscList [array get oscCodes]
|
---|
530 | set adcList [array get adcCodes]
|
---|
531 | set inpList [array get inpCodes]
|
---|
532 |
|
---|
533 | set mux [frame ${master}.mux]
|
---|
534 | set key [frame ${master}.key]
|
---|
535 | set inv [frame ${master}.inv]
|
---|
536 |
|
---|
537 | foreach {osc title} $oscList {
|
---|
538 | set config($osc) [labelframe ${mux}.$osc -borderwidth 1 -relief sunken -text $title]
|
---|
539 | foreach {code input} $inpList {
|
---|
540 | set column [expr {$code + 1}]
|
---|
541 | label $config($osc).input_${input} -text " ${input}"
|
---|
542 | grid $config($osc).input_${input} -row 0 -column ${column} -sticky w
|
---|
543 | }
|
---|
544 | foreach {ch id} $adcList {
|
---|
545 | label $config($osc).chan_${ch} -text "${id} "
|
---|
546 | grid $config($osc).chan_${ch} -row ${ch} -column 0 -sticky ew
|
---|
547 | foreach {code input} $inpList {
|
---|
548 | set column [expr {$code + 1}]
|
---|
549 | set value [expr {$size * ($ch - 1) + $code}]
|
---|
550 | radiobutton $config($osc).chan_${code}_${ch} -variable [myvar chan_val($osc)] -value ${value}
|
---|
551 | grid $config($osc).chan_${code}_${ch} -row ${ch} -column ${column} -sticky w
|
---|
552 | }
|
---|
553 | }
|
---|
554 | set column [expr {($osc - 1) % 3}]
|
---|
555 | set row [expr {($osc - 1) / 3}]
|
---|
556 | grid $config($osc) -row ${row} -column ${column} -sticky news -padx 10
|
---|
557 | }
|
---|
558 |
|
---|
559 | set config(key) [labelframe ${key}.frame -borderwidth 1 -relief sunken -text {legend}]
|
---|
560 |
|
---|
561 | label $config(key).rs -text "rs - raw signal"
|
---|
562 | grid $config(key).rs -row 0 -column 0 -sticky news
|
---|
563 |
|
---|
564 | label $config(key).cs -text "cs - filtered and clipped signal"
|
---|
565 | grid $config(key).cs -row 0 -column 1 -sticky news
|
---|
566 |
|
---|
567 | label $config(key).av -text "av - amplitude value"
|
---|
568 | grid $config(key).av -row 0 -column 2 -sticky news
|
---|
569 |
|
---|
570 | label $config(key).af -text "af - amplitude flag"
|
---|
571 | grid $config(key).af -row 0 -column 3 -sticky news
|
---|
572 |
|
---|
573 | label $config(key).bn -text "bn - bin number"
|
---|
574 | grid $config(key).bn -row 0 -column 4 -sticky news
|
---|
575 |
|
---|
576 | label $config(key).bf -text "bf - bin flag"
|
---|
577 | grid $config(key).bf -row 0 -column 5 -sticky news
|
---|
578 |
|
---|
579 | grid $config(key) -row 0 -column 0 -sticky news -padx 10
|
---|
580 |
|
---|
581 |
|
---|
582 | set config(inv) [labelframe ${inv}.frame -borderwidth 1 -relief sunken -text {polarity inversion}]
|
---|
583 | label $config(inv).chan_label -text "channel "
|
---|
584 | grid $config(inv).chan_label -row 0 -column 0 -sticky e
|
---|
585 | label $config(inv).polar_label -text "polarity"
|
---|
586 | grid $config(inv).polar_label -row 1 -column 0 -sticky e
|
---|
587 | foreach {ch dummy} $adcList {
|
---|
588 | label $config(inv).chan_${ch} -text "${ch} "
|
---|
589 | grid $config(inv).chan_${ch} -row 0 -column ${ch} -sticky ew
|
---|
590 | checkbutton $config(inv).polar_${ch} -variable [myvar polar($ch)]
|
---|
591 | grid $config(inv).polar_${ch} -row 1 -column ${ch} -sticky w
|
---|
592 | }
|
---|
593 | grid $config(inv) -row 0 -column 0 -sticky news -padx 10
|
---|
594 |
|
---|
595 | grid ${key} -row 0 -column 0 -sticky news
|
---|
596 | grid ${mux} -row 1 -column 0 -sticky news
|
---|
597 | grid ${inv} -row 2 -column 0 -sticky news
|
---|
598 |
|
---|
599 | grid columnconfigure ${master} 0 -weight 1
|
---|
600 | grid rowconfigure ${master} 0 -weight 1
|
---|
601 | grid rowconfigure ${master} 1 -weight 1
|
---|
602 | grid rowconfigure ${master} 2 -weight 1
|
---|
603 |
|
---|
604 | grid columnconfigure ${inv} 0 -weight 1
|
---|
605 |
|
---|
606 | grid columnconfigure ${key} 0 -weight 1
|
---|
607 | grid columnconfigure $config(key) 0 -weight 1
|
---|
608 | grid columnconfigure $config(key) 1 -weight 1
|
---|
609 | grid columnconfigure $config(key) 2 -weight 1
|
---|
610 | grid columnconfigure $config(key) 3 -weight 1
|
---|
611 | grid columnconfigure $config(key) 4 -weight 1
|
---|
612 | grid columnconfigure $config(key) 5 -weight 1
|
---|
613 |
|
---|
614 |
|
---|
615 | grid columnconfigure ${mux} 0 -weight 1
|
---|
616 | grid columnconfigure ${mux} 1 -weight 1
|
---|
617 | grid columnconfigure ${mux} 2 -weight 1
|
---|
618 | }
|
---|
619 |
|
---|
620 | # ------------------------------------------------------------------------
|
---|
621 |
|
---|
622 | MuxDisplay instproc chan_val_update args {
|
---|
623 | my instvar controller chan_val
|
---|
624 |
|
---|
625 | set byte1 [format {%02x%02x} $chan_val(2) $chan_val(1)]
|
---|
626 | set byte2 [format {%02x%02x} $chan_val(4) $chan_val(3)]
|
---|
627 | set byte3 [format {%02x%02x} $chan_val(6) $chan_val(5)]
|
---|
628 |
|
---|
629 | $controller usbCmd 000200020004${byte1}000200030004${byte2}000200040004${byte3}
|
---|
630 | }
|
---|
631 |
|
---|
632 | # -------------------------------------------------------------------------
|
---|
633 |
|
---|
634 | MuxDisplay instproc polar_update args {
|
---|
635 | my instvar controller polar
|
---|
636 |
|
---|
637 | set value {0b}
|
---|
638 | for {set i 6} {$i >= 1} {incr i -1} {
|
---|
639 | append value $polar($i)
|
---|
640 | }
|
---|
641 |
|
---|
642 | set value [format {%04x} $value]
|
---|
643 |
|
---|
644 | $controller usbCmd 000200010004${value}
|
---|
645 | }
|
---|
646 |
|
---|
647 | # -------------------------------------------------------------------------
|
---|
648 |
|
---|
649 | Class HstDisplay -parameter {
|
---|
650 | {number}
|
---|
651 | {master}
|
---|
652 | {controller}
|
---|
653 | }
|
---|
654 |
|
---|
655 | # -------------------------------------------------------------------------
|
---|
656 |
|
---|
657 | HstDisplay instproc init {} {
|
---|
658 |
|
---|
659 | my set data {}
|
---|
660 |
|
---|
661 | vector create [myvar xvec](64)
|
---|
662 | vector create [myvar yvec](64)
|
---|
663 |
|
---|
664 | # fill one vector for the x axis with 64 points
|
---|
665 | [myvar xvec] seq -0.5 63.5
|
---|
666 |
|
---|
667 | my setup
|
---|
668 |
|
---|
669 | next
|
---|
670 | }
|
---|
671 |
|
---|
672 | # -------------------------------------------------------------------------
|
---|
673 |
|
---|
674 | HstDisplay instproc destroy {} {
|
---|
675 | next
|
---|
676 | }
|
---|
677 |
|
---|
678 | # -------------------------------------------------------------------------
|
---|
679 |
|
---|
680 | HstDisplay instproc start {} {
|
---|
681 | my instvar config
|
---|
682 |
|
---|
683 | trace add variable [myvar data] write [myproc data_update]
|
---|
684 |
|
---|
685 | trace add variable [myvar axis] write [myproc axis_update]
|
---|
686 |
|
---|
687 | ${config}.axis_check select
|
---|
688 |
|
---|
689 | my set yvec_bak 0.0
|
---|
690 | my set yvec_old 0.0
|
---|
691 | }
|
---|
692 |
|
---|
693 | # -------------------------------------------------------------------------
|
---|
694 |
|
---|
695 | HstDisplay instproc setup {} {
|
---|
696 | my instvar number master
|
---|
697 | my instvar xvec yvec graph
|
---|
698 | my instvar config thrs thrs_val base base_typ base_val
|
---|
699 | my instvar cntr_h cntr_m cntr_s
|
---|
700 |
|
---|
701 | # create a graph widget and show a grid
|
---|
702 | set graph [graph ${master}.graph -height 250 -leftmargin 80]
|
---|
703 | $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2}
|
---|
704 | $graph grid configure -hide no
|
---|
705 | $graph legend configure -hide yes
|
---|
706 | $graph axis configure x -min 0 -max 64
|
---|
707 |
|
---|
708 | set config [frame ${master}.config -width 170]
|
---|
709 |
|
---|
710 | checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis]
|
---|
711 |
|
---|
712 | frame ${config}.spc1 -width 170 -height 30
|
---|
713 |
|
---|
714 | frame ${config}.chan_frame -borderwidth 0 -width 170
|
---|
715 | legendLabel ${config}.chan_frame 0 axisy {Bin entries}
|
---|
716 | legendLabel ${config}.chan_frame 1 axisx {Bin number}
|
---|
717 |
|
---|
718 | frame ${config}.spc2 -width 170 -height 30
|
---|
719 |
|
---|
720 | button ${config}.start -text Start \
|
---|
721 | -bg yellow -activebackground yellow -command [myproc cntr_start]
|
---|
722 | button ${config}.reset -text Reset \
|
---|
723 | -bg red -activebackground red -command [myproc cntr_reset]
|
---|
724 |
|
---|
725 | frame ${config}.spc3 -width 170 -height 30
|
---|
726 |
|
---|
727 | button ${config}.register -text Register \
|
---|
728 | -bg lightblue -activebackground lightblue -command [myproc register]
|
---|
729 |
|
---|
730 | grid ${config}.axis_check -sticky w
|
---|
731 | grid ${config}.spc1
|
---|
732 | grid ${config}.chan_frame -sticky ew -padx 5
|
---|
733 | grid ${config}.spc2
|
---|
734 | grid ${config}.start -sticky ew -pady 3 -padx 5
|
---|
735 | grid ${config}.reset -sticky ew -pady 3 -padx 5
|
---|
736 | grid ${config}.spc3
|
---|
737 | grid ${config}.register -sticky ew -pady 3 -padx 5
|
---|
738 |
|
---|
739 | grid ${graph} -row 0 -column 0 -sticky news
|
---|
740 | grid ${config} -row 0 -column 1
|
---|
741 |
|
---|
742 | grid rowconfigure ${master} 0 -weight 1
|
---|
743 | grid columnconfigure ${master} 0 -weight 1
|
---|
744 | grid columnconfigure ${master} 1 -weight 0 -minsize 80
|
---|
745 |
|
---|
746 | grid columnconfigure ${config}.chan_frame 1 -weight 1
|
---|
747 |
|
---|
748 | # enable zooming
|
---|
749 | Blt_ZoomStack $graph
|
---|
750 |
|
---|
751 | my crosshairs $graph
|
---|
752 |
|
---|
753 | #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
|
---|
754 |
|
---|
755 | # create one element with data for the x and y axis, no dots
|
---|
756 | $graph element create Spectrum1 -color blue -linewidth 2 -symbol none -smooth step -xdata [myvar xvec] -ydata [myvar yvec]
|
---|
757 | }
|
---|
758 |
|
---|
759 | # -------------------------------------------------------------------------
|
---|
760 |
|
---|
761 | HstDisplay instproc coor_update {W x y} {
|
---|
762 | my instvar config graph
|
---|
763 |
|
---|
764 | $W crosshairs configure -position @${x},${y}
|
---|
765 |
|
---|
766 | set index [$W axis invtransform x $x]
|
---|
767 | set index [::tcl::mathfunc::round $index]
|
---|
768 | catch {
|
---|
769 | ${config}.chan_frame.axisy_value configure -text [[myvar yvec] index $index]
|
---|
770 | ${config}.chan_frame.axisx_value configure -text ${index}.0
|
---|
771 | }
|
---|
772 | }
|
---|
773 | # -------------------------------------------------------------------------
|
---|
774 |
|
---|
775 | HstDisplay instproc crosshairs {graph} {
|
---|
776 | set method [myproc coor_update]
|
---|
777 | bind $graph <Motion> [list [self] coor_update %W %x %y]
|
---|
778 | bind $graph <Leave> {
|
---|
779 | %W crosshairs off
|
---|
780 | }
|
---|
781 | bind $graph <Enter> {
|
---|
782 | %W crosshairs on
|
---|
783 | }
|
---|
784 | }
|
---|
785 |
|
---|
786 | # -------------------------------------------------------------------------
|
---|
787 |
|
---|
788 | HstDisplay instproc axis_update args {
|
---|
789 | my instvar axis graph
|
---|
790 | if {$axis} {
|
---|
791 | $graph axis configure y -min 1 -max 1E10 -logscale yes
|
---|
792 | } else {
|
---|
793 | $graph axis configure y -min {} -max {} -logscale no
|
---|
794 | }
|
---|
795 | }
|
---|
796 |
|
---|
797 | # -------------------------------------------------------------------------
|
---|
798 |
|
---|
799 | HstDisplay instproc cntr_reset {} {
|
---|
800 | my instvar controller number
|
---|
801 |
|
---|
802 | my cntr_stop
|
---|
803 |
|
---|
804 | set value [format %04x [expr {1 << (5 + ${number})}]]
|
---|
805 | $controller usbCmd 000200000004${value}0002000000040000
|
---|
806 |
|
---|
807 | my acquire
|
---|
808 | }
|
---|
809 |
|
---|
810 | # -------------------------------------------------------------------------
|
---|
811 |
|
---|
812 | HstDisplay instproc cntr_start {} {
|
---|
813 | my instvar controller config number auto
|
---|
814 |
|
---|
815 | set val_addr [format %02x [expr {6 + ${number}}]]
|
---|
816 |
|
---|
817 | ${config}.start configure -text Stop -command [myproc cntr_stop]
|
---|
818 | # ${config}.reset configure -state disabled
|
---|
819 |
|
---|
820 | $controller usbCmd 000200${val_addr}00040001
|
---|
821 |
|
---|
822 | set auto 1
|
---|
823 |
|
---|
824 | after 100 [myproc acquire_loop]
|
---|
825 | }
|
---|
826 |
|
---|
827 | # -------------------------------------------------------------------------
|
---|
828 |
|
---|
829 | HstDisplay instproc cntr_stop {} {
|
---|
830 | my instvar controller config number auto
|
---|
831 |
|
---|
832 | set val_addr [format %02x [expr {6 + ${number}}]]
|
---|
833 |
|
---|
834 | ${config}.start configure -text Start -command [myproc cntr_start]
|
---|
835 |
|
---|
836 | $controller usbCmd 000200${val_addr}00040000
|
---|
837 |
|
---|
838 | set auto 0
|
---|
839 |
|
---|
840 | my acquire
|
---|
841 | }
|
---|
842 |
|
---|
843 | # -------------------------------------------------------------------------
|
---|
844 |
|
---|
845 | HstDisplay instproc data_update args {
|
---|
846 | my instvar data
|
---|
847 | usb::convertBlt $data 4 [myvar yvec]
|
---|
848 | }
|
---|
849 |
|
---|
850 | # -------------------------------------------------------------------------
|
---|
851 |
|
---|
852 | HstDisplay instproc acquire_loop {} {
|
---|
853 | my instvar cntr_val auto
|
---|
854 |
|
---|
855 | my acquire
|
---|
856 |
|
---|
857 | if {$auto} {
|
---|
858 | after 1000 [myproc acquire_loop]
|
---|
859 | }
|
---|
860 | }
|
---|
861 |
|
---|
862 | # -------------------------------------------------------------------------
|
---|
863 |
|
---|
864 | HstDisplay instproc acquire {} {
|
---|
865 | my instvar controller config number
|
---|
866 |
|
---|
867 | set size 64
|
---|
868 |
|
---|
869 | set prefix [format {%x} [expr {$number + 2}]]
|
---|
870 |
|
---|
871 | set value [format {%08x} [expr {$size * 2}]]
|
---|
872 |
|
---|
873 | set command 0001${prefix}000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000
|
---|
874 |
|
---|
875 | $controller usbCmdReadRaw $command [expr {$size * 4}] [myvar data]
|
---|
876 | }
|
---|
877 |
|
---|
878 | # -------------------------------------------------------------------------
|
---|
879 |
|
---|
880 | HstDisplay instproc save_data {data} {
|
---|
881 | my instvar number
|
---|
882 |
|
---|
883 | set types {
|
---|
884 | {{Data Files} {.dat} }
|
---|
885 | {{All Files} * }
|
---|
886 | }
|
---|
887 |
|
---|
888 | set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]
|
---|
889 | set fname spectrum_[expr {$number + 1}]_${stamp}.dat
|
---|
890 |
|
---|
891 | set fname [tk_getSaveFile -filetypes $types -initialfile $fname]
|
---|
892 | if {[string equal $fname {}]} {
|
---|
893 | return
|
---|
894 | }
|
---|
895 |
|
---|
896 | set x [catch {
|
---|
897 | set fid [open $fname w+]
|
---|
898 | puts $fid $data
|
---|
899 | close $fid
|
---|
900 | }]
|
---|
901 |
|
---|
902 | if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } {
|
---|
903 | tk_messageBox -icon error \
|
---|
904 | -message "An error occurred while writing to \"$fname\""
|
---|
905 | } else {
|
---|
906 | tk_messageBox -icon info \
|
---|
907 | -message "File \"$fname\" written successfully"
|
---|
908 | }
|
---|
909 | }
|
---|
910 |
|
---|
911 | # -------------------------------------------------------------------------
|
---|
912 |
|
---|
913 | HstDisplay instproc register {} {
|
---|
914 | my save_data [join [[myvar yvec] range 0 63] \n]
|
---|
915 | }
|
---|
916 |
|
---|
917 | # -------------------------------------------------------------------------
|
---|
918 |
|
---|
919 | Class OscDisplay -parameter {
|
---|
920 | {master}
|
---|
921 | {controller}
|
---|
922 | }
|
---|
923 |
|
---|
924 | # -------------------------------------------------------------------------
|
---|
925 |
|
---|
926 | OscDisplay instproc init {} {
|
---|
927 | my instvar sequence data xvec yvec
|
---|
928 |
|
---|
929 | set data {}
|
---|
930 |
|
---|
931 | set sequence 0
|
---|
932 |
|
---|
933 | # set xvec [vector create #auto(262144)]
|
---|
934 | # set xvec [vector create #auto(10000)]
|
---|
935 | set xvec [vector create #auto(60000)]
|
---|
936 |
|
---|
937 | for {set i 1} {$i <= 9} {incr i} {
|
---|
938 | # dict set yvec $i [vector create #auto(262144)]
|
---|
939 | # dict set yvec $i [vector create #auto(10000)]
|
---|
940 | dict set yvec $i [vector create #auto(60000)]
|
---|
941 | }
|
---|
942 |
|
---|
943 | # fill one vector for the x axis
|
---|
944 | # $xvec seq 0 262143
|
---|
945 | # $xvec seq 0 10000
|
---|
946 | $xvec seq 0 60000
|
---|
947 |
|
---|
948 | my setup
|
---|
949 |
|
---|
950 | next
|
---|
951 | }
|
---|
952 |
|
---|
953 | # -------------------------------------------------------------------------
|
---|
954 |
|
---|
955 | OscDisplay instproc destroy {} {
|
---|
956 | next
|
---|
957 | }
|
---|
958 |
|
---|
959 | # -------------------------------------------------------------------------
|
---|
960 |
|
---|
961 | OscDisplay instproc start {} {
|
---|
962 | my instvar config
|
---|
963 | my instvar recs_val directory
|
---|
964 |
|
---|
965 | set directory $::env(HOME)
|
---|
966 | set recs_val 100
|
---|
967 |
|
---|
968 | trace add variable [myvar chan] write [myproc chan_update]
|
---|
969 |
|
---|
970 | trace add variable [myvar data] write [myproc data_update]
|
---|
971 |
|
---|
972 | trace add variable [myvar auto] write [myproc auto_update]
|
---|
973 |
|
---|
974 | trace add variable [myvar thrs] write [myproc thrs_update 0]
|
---|
975 | trace add variable [myvar thrs_val] write [myproc thrs_update 0]
|
---|
976 |
|
---|
977 | trace add variable [myvar recs_val] write [myproc recs_val_update]
|
---|
978 |
|
---|
979 | trace add variable [myvar last] write [myproc last_update]
|
---|
980 |
|
---|
981 | for {set i 1} {$i <= 6} {incr i} {
|
---|
982 | ${config}.chan_frame.chan${i}_check select
|
---|
983 | ${config}.chan_frame.chan${i}_value configure -text 0.0
|
---|
984 | }
|
---|
985 | ${config}.chan_frame.axisx_value configure -text 0.0
|
---|
986 |
|
---|
987 | ${config}.thrs_check select
|
---|
988 | ${config}.thrs_field set 60
|
---|
989 | }
|
---|
990 |
|
---|
991 | # -------------------------------------------------------------------------
|
---|
992 |
|
---|
993 | OscDisplay instproc setup {} {
|
---|
994 | my instvar master
|
---|
995 | my instvar xvec yvec graph
|
---|
996 | my instvar config
|
---|
997 |
|
---|
998 | # create a graph widget and show a grid
|
---|
999 | set graph [graph ${master}.graph -height 250 -leftmargin 80]
|
---|
1000 | $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2}
|
---|
1001 | $graph grid configure -hide no
|
---|
1002 | $graph legend configure -hide yes
|
---|
1003 | $graph axis configure x -min 0 -max 60000
|
---|
1004 | $graph axis configure y -min 0 -max 4100
|
---|
1005 |
|
---|
1006 | # scale ${master}.last -orient horizontal -from 1 -to 27 -tickinterval 0 -showvalue no -variable [myvar last]
|
---|
1007 |
|
---|
1008 | set config [frame ${master}.config -width 170]
|
---|
1009 |
|
---|
1010 | frame ${config}.chan_frame -width 170
|
---|
1011 | legendButton ${config}.chan_frame 0 chan1 {Channel 1} [myvar chan(1)] turquoise2
|
---|
1012 | legendButton ${config}.chan_frame 1 chan2 {Channel 2} [myvar chan(2)] SpringGreen2
|
---|
1013 | legendButton ${config}.chan_frame 2 chan3 {Channel 3} [myvar chan(3)] orchid2
|
---|
1014 | legendButton ${config}.chan_frame 3 chan4 {Channel 4} [myvar chan(4)] orange2
|
---|
1015 | legendButton ${config}.chan_frame 4 chan5 {Channel 5} [myvar chan(5)] blue1 white
|
---|
1016 | legendButton ${config}.chan_frame 5 chan6 {Channel 6} [myvar chan(6)] gray65 white
|
---|
1017 | legendLabel ${config}.chan_frame 6 axisx {Time axis}
|
---|
1018 |
|
---|
1019 | frame ${config}.spc1 -width 170 -height 30
|
---|
1020 |
|
---|
1021 | checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
|
---|
1022 |
|
---|
1023 | frame ${config}.spc2 -width 170 -height 30
|
---|
1024 |
|
---|
1025 | checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
|
---|
1026 | spinbox ${config}.thrs_field -from 1 -to 4095 \
|
---|
1027 | -increment 5 -width 10 -textvariable [myvar thrs_val] \
|
---|
1028 | -validate all -vcmd {::mca::validate 4095 4 %P}
|
---|
1029 |
|
---|
1030 | frame ${config}.spc3 -width 170 -height 30
|
---|
1031 |
|
---|
1032 | button ${config}.acquire -text Acquire \
|
---|
1033 | -bg green -activebackground green -command [myproc acquire_start]
|
---|
1034 | button ${config}.register -text Register \
|
---|
1035 | -bg lightblue -activebackground lightblue -command [myproc register]
|
---|
1036 |
|
---|
1037 | frame ${config}.spc4 -width 170 -height 30
|
---|
1038 |
|
---|
1039 | label ${config}.recs -text {number of records}
|
---|
1040 | spinbox ${config}.recs_field -from 0 -to 10000 \
|
---|
1041 | -increment 10 -width 10 -textvariable [myvar recs_val] \
|
---|
1042 | -validate all -vcmd {::mca::validate 10000 5 %P}
|
---|
1043 |
|
---|
1044 | frame ${config}.spc5 -width 170 -height 10
|
---|
1045 |
|
---|
1046 | button ${config}.sequence -text {Start Recording} -command [myproc sequence_start] \
|
---|
1047 | -bg yellow -activebackground yellow
|
---|
1048 |
|
---|
1049 | frame ${config}.spc6 -width 170 -height 30
|
---|
1050 |
|
---|
1051 | button ${config}.recover -text {Read file} \
|
---|
1052 | -bg lightblue -activebackground lightblue -command [myproc recover]
|
---|
1053 |
|
---|
1054 | grid ${config}.chan_frame -sticky ew
|
---|
1055 | grid ${config}.spc1
|
---|
1056 | grid ${config}.auto_check -sticky w
|
---|
1057 | grid ${config}.spc2
|
---|
1058 | grid ${config}.thrs_check -sticky w
|
---|
1059 | grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
|
---|
1060 | grid ${config}.spc3
|
---|
1061 | grid ${config}.acquire -sticky ew -pady 3 -padx 5
|
---|
1062 | grid ${config}.register -sticky ew -pady 3 -padx 5
|
---|
1063 | grid ${config}.spc4
|
---|
1064 | grid ${config}.recs -sticky w -pady 1 -padx 3
|
---|
1065 | grid ${config}.recs_field -sticky ew -pady 1 -padx 5
|
---|
1066 | grid ${config}.spc5
|
---|
1067 | grid ${config}.sequence -sticky ew -pady 3 -padx 5
|
---|
1068 | grid ${config}.spc6
|
---|
1069 | grid ${config}.recover -sticky ew -pady 3 -padx 5
|
---|
1070 |
|
---|
1071 | grid ${graph} -row 0 -column 0 -sticky news
|
---|
1072 | grid ${config} -row 0 -column 1
|
---|
1073 |
|
---|
1074 | # grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew
|
---|
1075 |
|
---|
1076 | grid rowconfigure ${master} 0 -weight 1
|
---|
1077 | grid columnconfigure ${master} 0 -weight 1
|
---|
1078 | grid columnconfigure ${master} 1 -weight 0 -minsize 120
|
---|
1079 |
|
---|
1080 | grid columnconfigure ${config}.chan_frame 2 -weight 1
|
---|
1081 |
|
---|
1082 | # enable zooming
|
---|
1083 | Blt_ZoomStack $graph
|
---|
1084 |
|
---|
1085 | my crosshairs $graph
|
---|
1086 |
|
---|
1087 | # create one element with data for the x and y axis, no dots
|
---|
1088 | $graph pen create pen1 -color turquoise3 -linewidth 2 -symbol none
|
---|
1089 | $graph pen create pen2 -color SpringGreen3 -linewidth 2 -symbol none
|
---|
1090 | $graph pen create pen3 -color orchid3 -linewidth 2 -symbol none
|
---|
1091 | $graph pen create pen4 -color orange3 -linewidth 2 -symbol none
|
---|
1092 | $graph pen create pen5 -color blue2 -linewidth 2 -symbol none
|
---|
1093 | $graph pen create pen6 -color gray55 -linewidth 2 -symbol none
|
---|
1094 |
|
---|
1095 | $graph element create Spectrum1 -pen pen1 -xdata $xvec -ydata [dict get $yvec 1]
|
---|
1096 | $graph element create Spectrum2 -pen pen2 -xdata $xvec -ydata [dict get $yvec 2]
|
---|
1097 | $graph element create Spectrum3 -pen pen3 -xdata $xvec -ydata [dict get $yvec 3]
|
---|
1098 | $graph element create Spectrum4 -pen pen4 -xdata $xvec -ydata [dict get $yvec 4]
|
---|
1099 | $graph element create Spectrum5 -pen pen5 -xdata $xvec -ydata [dict get $yvec 5]
|
---|
1100 | $graph element create Spectrum6 -pen pen6 -xdata $xvec -ydata [dict get $yvec 6]
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | # -------------------------------------------------------------------------
|
---|
1104 |
|
---|
1105 | OscDisplay instproc coor_update {W x y} {
|
---|
1106 | my instvar xvec yvec graph
|
---|
1107 | my instvar config
|
---|
1108 |
|
---|
1109 | $W crosshairs configure -position @${x},${y}
|
---|
1110 |
|
---|
1111 | set index [$W axis invtransform x $x]
|
---|
1112 | set index [::tcl::mathfunc::round $index]
|
---|
1113 | catch {
|
---|
1114 | ${config}.chan_frame.chan1_value configure -text [[dict get $yvec 1] index $index]
|
---|
1115 | ${config}.chan_frame.chan2_value configure -text [[dict get $yvec 2] index $index]
|
---|
1116 | ${config}.chan_frame.chan3_value configure -text [[dict get $yvec 3] index $index]
|
---|
1117 | ${config}.chan_frame.chan4_value configure -text [[dict get $yvec 4] index $index]
|
---|
1118 | ${config}.chan_frame.chan5_value configure -text [[dict get $yvec 5] index $index]
|
---|
1119 | ${config}.chan_frame.chan6_value configure -text [[dict get $yvec 6] index $index]
|
---|
1120 | ${config}.chan_frame.axisx_value configure -text ${index}.0
|
---|
1121 | }
|
---|
1122 | }
|
---|
1123 | # -------------------------------------------------------------------------
|
---|
1124 |
|
---|
1125 | OscDisplay instproc crosshairs {graph} {
|
---|
1126 | set method [myproc coor_update]
|
---|
1127 | bind $graph <Motion> [list [self] coor_update %W %x %y]
|
---|
1128 | bind $graph <Leave> {
|
---|
1129 | %W crosshairs off
|
---|
1130 | }
|
---|
1131 | bind $graph <Enter> {
|
---|
1132 | %W crosshairs on
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | # -------------------------------------------------------------------------
|
---|
1137 |
|
---|
1138 | OscDisplay instproc chan_update {name key op} {
|
---|
1139 | my instvar config graph chan
|
---|
1140 |
|
---|
1141 | if {$chan(${key})} {
|
---|
1142 | $graph pen configure pen${key} -linewidth 2
|
---|
1143 | } else {
|
---|
1144 | $graph pen configure pen${key} -linewidth 0
|
---|
1145 | }
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | # -------------------------------------------------------------------------
|
---|
1149 |
|
---|
1150 | OscDisplay instproc recs_val_update args {
|
---|
1151 | my instvar recs_val
|
---|
1152 | if {[string equal $recs_val {}]} {
|
---|
1153 | set recs_val 0
|
---|
1154 | }
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | # -------------------------------------------------------------------------
|
---|
1158 |
|
---|
1159 | OscDisplay instproc last_update args {
|
---|
1160 | my instvar graph last
|
---|
1161 |
|
---|
1162 | set first [expr {$last - 1}]
|
---|
1163 |
|
---|
1164 | $graph axis configure x -min ${first}0000 -max ${last}0000
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | # -------------------------------------------------------------------------
|
---|
1168 |
|
---|
1169 | OscDisplay instproc thrs_update {reset args} {
|
---|
1170 | my instvar controller config thrs thrs_val
|
---|
1171 |
|
---|
1172 | if {[string equal $thrs_val {}]} {
|
---|
1173 | set thrs_val 0
|
---|
1174 | }
|
---|
1175 |
|
---|
1176 | if {$thrs} {
|
---|
1177 | ${config}.thrs_field configure -state normal
|
---|
1178 | set value [format {%03x} $thrs_val]
|
---|
1179 | } else {
|
---|
1180 | ${config}.thrs_field configure -state disabled
|
---|
1181 | set value 000
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | set command {}
|
---|
1185 | if {$reset} {
|
---|
1186 | append command 0002000500041${value}
|
---|
1187 | }
|
---|
1188 | append command 0002000500040${value}
|
---|
1189 |
|
---|
1190 | $controller usbCmd $command
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | # -------------------------------------------------------------------------
|
---|
1194 |
|
---|
1195 | OscDisplay instproc data_update args {
|
---|
1196 | my instvar data yvec
|
---|
1197 | my instvar graph chan waiting sequence auto
|
---|
1198 |
|
---|
1199 | usb::convertOsc $data $yvec
|
---|
1200 |
|
---|
1201 | foreach {key value} [array get chan] {
|
---|
1202 | $graph pen configure pen${key} -dashes 0
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 | set waiting 0
|
---|
1206 |
|
---|
1207 | if {$sequence} {
|
---|
1208 | my sequence_register
|
---|
1209 | } elseif {$auto} {
|
---|
1210 | after 1000 [myproc acquire_start]
|
---|
1211 | }
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | # -------------------------------------------------------------------------
|
---|
1215 |
|
---|
1216 | OscDisplay instproc acquire_start {} {
|
---|
1217 | my instvar graph chan controller waiting
|
---|
1218 |
|
---|
1219 | foreach {key value} [array get chan] {
|
---|
1220 | $graph pen configure pen${key} -dashes dot
|
---|
1221 | }
|
---|
1222 |
|
---|
1223 | # restart
|
---|
1224 | my thrs_update 1
|
---|
1225 |
|
---|
1226 | set waiting 1
|
---|
1227 |
|
---|
1228 | after 200 [myproc acquire_loop]
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | # -------------------------------------------------------------------------
|
---|
1232 |
|
---|
1233 | OscDisplay instproc acquire_loop {} {
|
---|
1234 | my instvar controller waiting
|
---|
1235 |
|
---|
1236 | # set size 262144
|
---|
1237 | # set size 10000
|
---|
1238 | set size 60000
|
---|
1239 |
|
---|
1240 | set value [format {%08x} [expr {$size * 4}]]
|
---|
1241 |
|
---|
1242 | set command 00011000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000
|
---|
1243 |
|
---|
1244 | $controller usbCmdReadRaw $command [expr {$size * 8}] [myvar data]
|
---|
1245 |
|
---|
1246 | if {$waiting} {
|
---|
1247 | after 200 [myproc acquire_loop]
|
---|
1248 | }
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 | # -------------------------------------------------------------------------
|
---|
1252 |
|
---|
1253 | OscDisplay instproc auto_update args {
|
---|
1254 | my instvar config auto
|
---|
1255 |
|
---|
1256 | if {$auto} {
|
---|
1257 | ${config}.recs_field configure -state disabled
|
---|
1258 | ${config}.sequence configure -state disabled
|
---|
1259 | ${config}.acquire configure -state disabled
|
---|
1260 | ${config}.register configure -state disabled
|
---|
1261 | ${config}.recover configure -state disabled
|
---|
1262 |
|
---|
1263 | my acquire_start
|
---|
1264 | } else {
|
---|
1265 | ${config}.recs_field configure -state normal
|
---|
1266 | ${config}.sequence configure -state active
|
---|
1267 | ${config}.acquire configure -state active
|
---|
1268 | ${config}.register configure -state active
|
---|
1269 | ${config}.recover configure -state active
|
---|
1270 | }
|
---|
1271 | }
|
---|
1272 |
|
---|
1273 | # -------------------------------------------------------------------------
|
---|
1274 |
|
---|
1275 | OscDisplay instproc save_data {fname} {
|
---|
1276 | my instvar data
|
---|
1277 |
|
---|
1278 | set fid [open $fname w+]
|
---|
1279 | fconfigure $fid -translation binary -encoding binary
|
---|
1280 |
|
---|
1281 | # puts -nonewline $fid [binary format "H*iH*" "1f8b0800" [clock seconds] "0003"]
|
---|
1282 | # puts -nonewline $fid [zlib deflate $data]
|
---|
1283 | puts -nonewline $fid $data
|
---|
1284 | # puts -nonewline $fid [binary format i [zlib crc32 $data]]
|
---|
1285 | # puts -nonewline $fid [binary format i [string length $data]]
|
---|
1286 |
|
---|
1287 | close $fid
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | # -------------------------------------------------------------------------
|
---|
1291 |
|
---|
1292 | OscDisplay instproc open_data {} {
|
---|
1293 | set types {
|
---|
1294 | {{Data Files} {.dat} }
|
---|
1295 | {{All Files} * }
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | set fname [tk_getOpenFile -filetypes $types]
|
---|
1299 | if {[string equal $fname {}]} {
|
---|
1300 | return
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | set x [catch {
|
---|
1304 | set fid [open $fname r+]
|
---|
1305 | fconfigure $fid -translation binary -encoding binary
|
---|
1306 | # set size [file size $fname]
|
---|
1307 | # seek $fid 10
|
---|
1308 | # my set data [zlib inflate [read $fid [expr {$size - 18}]]]
|
---|
1309 | my set data [read $fid]
|
---|
1310 | close $fid
|
---|
1311 | }]
|
---|
1312 |
|
---|
1313 | if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } {
|
---|
1314 | tk_messageBox -icon error \
|
---|
1315 | -message "An error occurred while reading \"$fname\""
|
---|
1316 | } else {
|
---|
1317 | tk_messageBox -icon info \
|
---|
1318 | -message "File \"$fname\" read successfully"
|
---|
1319 | }
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | # -------------------------------------------------------------------------
|
---|
1323 |
|
---|
1324 | OscDisplay instproc register {} {
|
---|
1325 | set types {
|
---|
1326 | {{Data Files} {.dat} }
|
---|
1327 | {{All Files} * }
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | set stamp [clock format [clock seconds] -format {%Y%m%d_%H%M%S}]
|
---|
1331 | set fname oscillogram_${stamp}.dat
|
---|
1332 |
|
---|
1333 | set fname [tk_getSaveFile -filetypes $types -initialfile $fname]
|
---|
1334 | if {[string equal $fname {}]} {
|
---|
1335 | return
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | if {[catch {my save_data $fname} result]} {
|
---|
1339 | tk_messageBox -icon error \
|
---|
1340 | -message "An error occurred while writing to \"$fname\""
|
---|
1341 | } else {
|
---|
1342 | tk_messageBox -icon info \
|
---|
1343 | -message "File \"$fname\" written successfully"
|
---|
1344 | }
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | # -------------------------------------------------------------------------
|
---|
1348 |
|
---|
1349 | OscDisplay instproc recover {} {
|
---|
1350 | my open_data
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | # -------------------------------------------------------------------------
|
---|
1354 |
|
---|
1355 | OscDisplay instproc sequence_start {} {
|
---|
1356 | my instvar config recs_val recs_bak directory counter sequence
|
---|
1357 |
|
---|
1358 | set counter 1
|
---|
1359 | if {$counter > $recs_val} {
|
---|
1360 | return
|
---|
1361 | }
|
---|
1362 |
|
---|
1363 | set directory [tk_chooseDirectory -initialdir $directory -title {Choose a directory}]
|
---|
1364 |
|
---|
1365 | if {[string equal $directory {}]} {
|
---|
1366 | return
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | ${config}.recs_field configure -state disabled
|
---|
1370 | ${config}.sequence configure -text {Stop Recording} -command [myproc sequence_stop]
|
---|
1371 | ${config}.acquire configure -state disabled
|
---|
1372 | ${config}.register configure -state disabled
|
---|
1373 | ${config}.recover configure -state disabled
|
---|
1374 |
|
---|
1375 | set recs_bak $recs_val
|
---|
1376 |
|
---|
1377 | set sequence 1
|
---|
1378 |
|
---|
1379 | my acquire_start
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | # -------------------------------------------------------------------------
|
---|
1383 |
|
---|
1384 | OscDisplay instproc sequence_register {} {
|
---|
1385 | my instvar config recs_val recs_bak directory counter
|
---|
1386 |
|
---|
1387 | set fname [file join $directory oscillogram_$counter.dat]
|
---|
1388 |
|
---|
1389 | my incr counter
|
---|
1390 |
|
---|
1391 | if {[catch {my save_data $fname} result]} {
|
---|
1392 | tk_messageBox -icon error \
|
---|
1393 | -message "An error occurred while writing to \"$fname\""
|
---|
1394 | } elseif {$counter <= $recs_bak} {
|
---|
1395 | set recs_val [expr {$recs_bak - $counter}]
|
---|
1396 | my acquire_start
|
---|
1397 | return
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | my sequence_stop
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | # -------------------------------------------------------------------------
|
---|
1404 |
|
---|
1405 | OscDisplay instproc sequence_stop {} {
|
---|
1406 | my instvar config recs_val recs_bak sequence
|
---|
1407 |
|
---|
1408 | set sequence 0
|
---|
1409 |
|
---|
1410 | set recs_val $recs_bak
|
---|
1411 |
|
---|
1412 | ${config}.recs_field configure -state normal
|
---|
1413 | ${config}.sequence configure -text {Start Recording} -command [myproc sequence_start]
|
---|
1414 | ${config}.acquire configure -state active
|
---|
1415 | ${config}.register configure -state active
|
---|
1416 | ${config}.recover configure -state active
|
---|
1417 | }
|
---|
1418 |
|
---|
1419 | # -------------------------------------------------------------------------
|
---|
1420 |
|
---|
1421 | namespace export MuxDisplay
|
---|
1422 | namespace export HstDisplay
|
---|
1423 | namespace export CfgDisplay
|
---|
1424 | namespace export OscDisplay
|
---|
1425 | }
|
---|
1426 |
|
---|
1427 | set notebook [::blt::tabnotebook .notebook -borderwidth 1 -selectforeground black -side bottom]
|
---|
1428 |
|
---|
1429 | grid ${notebook} -row 0 -column 0 -sticky news -pady 5
|
---|
1430 |
|
---|
1431 | grid rowconfigure . 0 -weight 1
|
---|
1432 | grid columnconfigure . 0 -weight 1
|
---|
1433 |
|
---|
1434 | ::mca::UsbController usb
|
---|
1435 |
|
---|
1436 | set window [frame ${notebook}.mux]
|
---|
1437 | $notebook insert end -text "Interconnect" -window $window -fill both
|
---|
1438 | ::mca::MuxDisplay mux -master $window -controller usb
|
---|
1439 |
|
---|
1440 | set window [frame ${notebook}.cfg]
|
---|
1441 | $notebook insert end -text "Configuration" -window $window -fill both
|
---|
1442 | ::mca::CfgDisplay cfg -master $window -controller usb
|
---|
1443 |
|
---|
1444 | set window [frame ${notebook}.hst]
|
---|
1445 | $notebook insert end -text "Histogram" -window $window -fill both
|
---|
1446 | ::mca::HstDisplay hst -number 0 -master $window -controller usb
|
---|
1447 |
|
---|
1448 | set window [frame ${notebook}.ept]
|
---|
1449 | $notebook insert end -text "Oscilloscope" -window $window -fill both
|
---|
1450 | ::mca::OscDisplay osc -master $window -controller usb
|
---|
1451 |
|
---|
1452 | update
|
---|
1453 |
|
---|
1454 | cfg start
|
---|
1455 |
|
---|
1456 | mux start
|
---|
1457 |
|
---|
1458 | hst start
|
---|
1459 |
|
---|
1460 | osc start
|
---|