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