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