| [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 |
|
|---|
| 30 | Class OscDisplay -parameter {
|
|---|
| 31 | {number}
|
|---|
| 32 | {master}
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | # -------------------------------------------------------------------------
|
|---|
| 36 |
|
|---|
| 37 | OscDisplay instproc init {} {
|
|---|
| 38 | my instvar data xvec yvec
|
|---|
| 39 |
|
|---|
| 40 | set xvec [vector #auto]
|
|---|
| 41 | set yvec [vector #auto]
|
|---|
| 42 | # fill one vector for the x axis with 1025 points
|
|---|
| 43 | $xvec seq 0 1024
|
|---|
| 44 |
|
|---|
| 45 | my reset
|
|---|
| 46 |
|
|---|
| 47 | my setup
|
|---|
| 48 |
|
|---|
| 49 | next
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | # -------------------------------------------------------------------------
|
|---|
| 53 |
|
|---|
| 54 | OscDisplay instproc destroy {} {
|
|---|
| 55 | next
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | # -------------------------------------------------------------------------
|
|---|
| 59 |
|
|---|
| 60 | OscDisplay instproc reset {} {
|
|---|
| 61 | my instvar data xvec yvec
|
|---|
| 62 |
|
|---|
| 63 | dict set data none {}
|
|---|
| 64 | dict set data uwt1 {}
|
|---|
| 65 | dict set data uwt2 {}
|
|---|
| 66 | dict set data uwt3 {}
|
|---|
| 67 | # dict set data sum8 {}
|
|---|
| 68 |
|
|---|
| 69 | $yvec set {}
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | # -------------------------------------------------------------------------
|
|---|
| 73 |
|
|---|
| 74 | OscDisplay instproc start {} {
|
|---|
| 75 | my instvar config
|
|---|
| 76 |
|
|---|
| 77 | trace add variable [myvar auto] write [myproc auto_update]
|
|---|
| 78 | trace add variable [myvar thrs] write [myproc thrs_update]
|
|---|
| 79 | trace add variable [myvar fltr_val] write [myproc fltr_val_update]
|
|---|
| 80 |
|
|---|
| 81 | ${config}.thrs_check deselect
|
|---|
| 82 | ${config}.thrs_field set 10
|
|---|
| 83 | ${config}.none select
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | # -------------------------------------------------------------------------
|
|---|
| 87 |
|
|---|
| 88 | OscDisplay instproc setup {} {
|
|---|
| 89 | my instvar number master
|
|---|
| 90 | my instvar data xvec yvec
|
|---|
| 91 | my instvar config auto thrs thrs_val fltr_val
|
|---|
| 92 |
|
|---|
| 93 | my set restart_command [usb::convert 0001000${number}00000000]
|
|---|
| 94 | my set acquire_command [usb::convert 0002000${number}00000000]
|
|---|
| 95 |
|
|---|
| 96 | # create a graph widget and show a grid
|
|---|
| 97 | set graph [graph ${master}.graph -height 250 -leftmargin 80]
|
|---|
| 98 | $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
|
|---|
| 99 | $graph grid configure -hide no
|
|---|
| 100 | $graph legend configure -hide yes
|
|---|
| 101 | $graph axis configure x -min 0 -max 1024
|
|---|
| 102 |
|
|---|
| 103 | set config [frame ${master}.config]
|
|---|
| 104 |
|
|---|
| 105 | checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
|
|---|
| 106 |
|
|---|
| 107 | frame ${config}.spc1 -width 10 -height 10
|
|---|
| 108 |
|
|---|
| 109 | checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
|
|---|
| 110 | spinbox ${config}.thrs_field -from 1 -to 4095 \
|
|---|
| 111 | -increment 5 -width 10 -textvariable [myvar thrs_val] \
|
|---|
| 112 | -validate all -vcmd {::mca::validate %P}
|
|---|
| 113 |
|
|---|
| 114 | frame ${config}.spc2 -width 10 -height 10
|
|---|
| 115 |
|
|---|
| 116 | label ${config}.fltr -text {low-pass filter}
|
|---|
| 117 | radiobutton ${config}.none -text none -variable [myvar fltr_val] -value none
|
|---|
| 118 | radiobutton ${config}.uwt1 -text uwt1 -variable [myvar fltr_val] -value uwt1
|
|---|
| 119 | radiobutton ${config}.uwt2 -text uwt2 -variable [myvar fltr_val] -value uwt2
|
|---|
| 120 | radiobutton ${config}.uwt3 -text uwt3 -variable [myvar fltr_val] -value uwt3
|
|---|
| 121 | # radiobutton ${config}.sum8 -text sum8 -variable [myvar fltr_val] -value sum8
|
|---|
| 122 |
|
|---|
| 123 | frame ${config}.spc3 -width 10 -height 10
|
|---|
| 124 |
|
|---|
| 125 | button ${config}.acquire -text Acquire \
|
|---|
| 126 | -bg green -activebackground green -command [myproc acquire]
|
|---|
| 127 | button ${config}.restart -text Restart \
|
|---|
| 128 | -bg yellow -activebackground yellow -command [myproc restart]
|
|---|
| 129 | button ${config}.register -text Register \
|
|---|
| 130 | -bg lightblue -activebackground lightblue -command [myproc register]
|
|---|
| 131 |
|
|---|
| 132 | grid ${config}.auto_check -sticky w
|
|---|
| 133 | grid ${config}.spc1
|
|---|
| 134 | grid ${config}.thrs_check -sticky w
|
|---|
| 135 | grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
|
|---|
| 136 | grid ${config}.spc2
|
|---|
| 137 | grid ${config}.fltr -sticky w -pady 1 -padx 3
|
|---|
| 138 | grid ${config}.none -sticky w
|
|---|
| 139 | grid ${config}.uwt1 -sticky w
|
|---|
| 140 | grid ${config}.uwt2 -sticky w
|
|---|
| 141 | grid ${config}.uwt3 -sticky w
|
|---|
| 142 | # grid ${config}.sum8 -sticky w
|
|---|
| 143 | grid ${config}.spc3
|
|---|
| 144 | grid ${config}.acquire -sticky ew -pady 3 -padx 5
|
|---|
| 145 | grid ${config}.restart -sticky ew -pady 3 -padx 5
|
|---|
| 146 | grid ${config}.register -sticky ew -pady 3 -padx 5
|
|---|
| 147 |
|
|---|
| 148 | grid ${graph} -row 0 -column 0 -sticky news
|
|---|
| 149 | grid ${config} -row 0 -column 1
|
|---|
| 150 |
|
|---|
| 151 | # enable zooming
|
|---|
| 152 | Blt_ZoomStack $graph
|
|---|
| 153 |
|
|---|
| 154 | #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
|
|---|
| 155 |
|
|---|
| 156 | # create one element with data for the x and y axis, no dots
|
|---|
| 157 | $graph element create Spectrum1 -symbol none -xdata $xvec -ydata $yvec
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | # -------------------------------------------------------------------------
|
|---|
| 161 |
|
|---|
| 162 | OscDisplay instproc auto_update args {
|
|---|
| 163 | my instvar auto after_handle
|
|---|
| 164 |
|
|---|
| 165 | if {$auto} {
|
|---|
| 166 | ${config}.acquire configure -state disabled
|
|---|
| 167 | ${config}.restart configure -state disabled
|
|---|
| 168 | ${config}.register configure -state disabled
|
|---|
| 169 |
|
|---|
| 170 | my acquire_restart_loop
|
|---|
| 171 | } else {
|
|---|
| 172 | if {[my exists after_handle]} {
|
|---|
| 173 | after cancel $after_handle
|
|---|
| 174 | }
|
|---|
| 175 | ${config}.acquire configure -state active
|
|---|
| 176 | ${config}.restart configure -state active
|
|---|
| 177 | ${config}.register configure -state active
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | # -------------------------------------------------------------------------
|
|---|
| 182 |
|
|---|
| 183 | OscDisplay instproc thrs_update args {
|
|---|
| 184 | my instvar config thrs
|
|---|
| 185 | if {$thrs} {
|
|---|
| 186 | ${config}.thrs_field configure -state normal
|
|---|
| 187 | } else {
|
|---|
| 188 | ${config}.thrs_field configure -state disabled
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | # -------------------------------------------------------------------------
|
|---|
| 193 |
|
|---|
| 194 | OscDisplay instproc fltr_val_update args {
|
|---|
| 195 | my instvar yvec data fltr_val
|
|---|
| 196 | $yvec set [dict get $data $fltr_val]
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | # -------------------------------------------------------------------------
|
|---|
| 200 |
|
|---|
| 201 | OscDisplay instproc save_data {data} {
|
|---|
| 202 | set file [tk_getSaveFile]
|
|---|
| 203 | if {[string equal $file {}]} {
|
|---|
| 204 | return
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | set x [catch {set fid [open $file w+]}]
|
|---|
| 208 | set y [catch {puts $fid $data}]
|
|---|
| 209 | set z [catch {close $fid}]
|
|---|
| 210 |
|
|---|
| 211 | if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
|
|---|
| 212 | tk_messageBox -icon error \
|
|---|
| 213 | -message "An error occurred while writing to \"$file\""
|
|---|
| 214 | } else {
|
|---|
| 215 | tk_messageBox -icon info \
|
|---|
| 216 | -message "File \"$file\" written successfully"
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | # -------------------------------------------------------------------------
|
|---|
| 221 |
|
|---|
| 222 | OscDisplay instproc register {} {
|
|---|
| 223 | my save_data [my set data]
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | # -------------------------------------------------------------------------
|
|---|
| 227 |
|
|---|
| 228 | OscDisplay instproc send_data {data} {
|
|---|
| 229 | global usb_handle
|
|---|
| 230 |
|
|---|
| 231 | if {[catch {$usb_handle writeRaw $data} result]} {
|
|---|
| 232 | puts {Error during write}
|
|---|
| 233 | puts $result
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | # -------------------------------------------------------------------------
|
|---|
| 238 |
|
|---|
| 239 | OscDisplay instproc restart {} {
|
|---|
| 240 | my instvar restart_command
|
|---|
| 241 | my send_data $restart_command
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | # -------------------------------------------------------------------------
|
|---|
| 245 |
|
|---|
| 246 | OscDisplay instproc acquire {} {
|
|---|
| 247 | global usb_handle
|
|---|
| 248 | my instvar xvec yvec data fltr_val
|
|---|
| 249 | my instvar acquire_command
|
|---|
| 250 |
|
|---|
| 251 | my send_data $acquire_command
|
|---|
| 252 |
|
|---|
| 253 | set usb_data {}
|
|---|
| 254 | if {[catch {$usb_handle readHex 2 1024} usb_data]} {
|
|---|
| 255 | puts {Error during read}
|
|---|
| 256 | puts $usb_data
|
|---|
| 257 | set usb_data {}
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | dict set data none $usb_data
|
|---|
| 261 | dict set data uwt1 [lindex [uwt 1 $usb_data] 1]
|
|---|
| 262 | dict set data uwt2 [lindex [uwt 2 $usb_data] 1]
|
|---|
| 263 | dict set data uwt3 [lindex [uwt 3 $usb_data] 1]
|
|---|
| 264 | # dict set data sum8 [sum8 $usb_data]
|
|---|
| 265 |
|
|---|
| 266 | $yvec set [dict get $data $fltr_val]
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | # -------------------------------------------------------------------------
|
|---|
| 270 |
|
|---|
| 271 | OscDisplay instproc acquire_restart_loop {} {
|
|---|
| 272 | my instvar after_handle
|
|---|
| 273 |
|
|---|
| 274 | my acquire
|
|---|
| 275 | my restart
|
|---|
| 276 |
|
|---|
| 277 | set after_handle [after 1000 [myproc acquire_restart_loop]]
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | # -------------------------------------------------------------------------
|
|---|
| 281 |
|
|---|
| 282 | Class HstDisplay -parameter {
|
|---|
| 283 | {number}
|
|---|
| 284 | {master}
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | # -------------------------------------------------------------------------
|
|---|
| 288 |
|
|---|
| 289 | HstDisplay instproc init {} {
|
|---|
| 290 | my instvar data xvec yvec
|
|---|
| 291 |
|
|---|
| 292 | set xvec [vector #auto]
|
|---|
| 293 | set yvec [vector #auto]
|
|---|
| 294 | # fill one vector for the x axis with 4097 points
|
|---|
| 295 | $xvec seq 0 4096
|
|---|
| 296 |
|
|---|
| 297 | my reset
|
|---|
| 298 |
|
|---|
| 299 | my setup
|
|---|
| 300 |
|
|---|
| 301 | next
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | # -------------------------------------------------------------------------
|
|---|
| 305 |
|
|---|
| 306 | HstDisplay instproc destroy {} {
|
|---|
| 307 | next
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | # -------------------------------------------------------------------------
|
|---|
| 311 |
|
|---|
| 312 | HstDisplay instproc reset {} {
|
|---|
| 313 | my instvar data xvec yvec
|
|---|
| 314 |
|
|---|
| 315 | dict set data none {}
|
|---|
| 316 | dict set data uwt1 {}
|
|---|
| 317 | dict set data uwt2 {}
|
|---|
| 318 | dict set data uwt3 {}
|
|---|
| 319 | # dict set data sum8 {}
|
|---|
| 320 |
|
|---|
| 321 | $yvec set {}
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | # -------------------------------------------------------------------------
|
|---|
| 325 |
|
|---|
| 326 | HstDisplay instproc start {} {
|
|---|
| 327 | my instvar config peak_mux base_mux
|
|---|
| 328 |
|
|---|
| 329 | set peak_mux 1
|
|---|
| 330 | set base_mux 0
|
|---|
| 331 |
|
|---|
| 332 | trace add variable [myvar auto] write [myproc auto_update]
|
|---|
| 333 | trace add variable [myvar peak] write [myproc peak_update]
|
|---|
| 334 | trace add variable [myvar thrs] write [myproc thrs_update]
|
|---|
| 335 | trace add variable [myvar base] write [myproc base_update]
|
|---|
| 336 | trace add variable [myvar base_typ] write [myproc base_typ_update]
|
|---|
| 337 | trace add variable [myvar base_val] write [myproc base_val_update]
|
|---|
| 338 |
|
|---|
| 339 | ${config}.auto_check select
|
|---|
| 340 | ${config}.peak_check select
|
|---|
| 341 | ${config}.thrs_check select
|
|---|
| 342 | ${config}.thrs_field set 10
|
|---|
| 343 | ${config}.base_check select
|
|---|
| 344 | ${config}.base_const select
|
|---|
| 345 | ${config}.base_field set 35
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | # -------------------------------------------------------------------------
|
|---|
| 349 |
|
|---|
| 350 | HstDisplay instproc setup {} {
|
|---|
| 351 | my instvar number master
|
|---|
| 352 | my instvar data xvec yvec
|
|---|
| 353 | my instvar config auto thrs thrs_val base base_typ base_val
|
|---|
| 354 |
|
|---|
| 355 | my set restart_command [usb::convert 0001001${number}00000000]
|
|---|
| 356 | my set acquire_command [usb::convert 0002001${number}00000000]
|
|---|
| 357 |
|
|---|
| 358 | # create a graph widget and show a grid
|
|---|
| 359 | set graph [graph ${master}.graph -height 250 -leftmargin 80]
|
|---|
| 360 | $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
|
|---|
| 361 | $graph grid configure -hide no
|
|---|
| 362 | $graph legend configure -hide yes
|
|---|
| 363 | $graph axis configure x -min 0 -max 4096
|
|---|
| 364 |
|
|---|
| 365 | set config [frame ${master}.config]
|
|---|
| 366 |
|
|---|
| 367 | checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
|
|---|
| 368 |
|
|---|
| 369 | frame ${config}.spc1 -width 10 -height 10
|
|---|
| 370 |
|
|---|
| 371 | checkbutton ${config}.peak_check -text {peak detect} -variable [myvar peak]
|
|---|
| 372 |
|
|---|
| 373 | frame ${config}.spc2 -width 10 -height 10
|
|---|
| 374 |
|
|---|
| 375 | checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
|
|---|
| 376 | spinbox ${config}.thrs_field -from 1 -to 4095 \
|
|---|
| 377 | -increment 5 -width 10 -textvariable [myvar thrs_val] \
|
|---|
| 378 | -validate all -vcmd {::mca::validate %P}
|
|---|
| 379 |
|
|---|
| 380 | frame ${config}.spc3 -width 10 -height 10
|
|---|
| 381 |
|
|---|
| 382 | checkbutton ${config}.base_check -text baseline -variable [myvar base]
|
|---|
| 383 | radiobutton ${config}.base_auto -text automatic -variable [myvar base_typ] -value auto
|
|---|
| 384 | radiobutton ${config}.base_const -text constant -variable [myvar base_typ] -value const
|
|---|
| 385 | spinbox ${config}.base_field -from 1 -to 4095 \
|
|---|
| 386 | -increment 5 -width 10 -textvariable [myvar base_val] \
|
|---|
| 387 | -validate all -vcmd {::mca::validate %P}
|
|---|
| 388 |
|
|---|
| 389 | frame ${config}.spc4 -width 10 -height 10
|
|---|
| 390 |
|
|---|
| 391 | button ${config}.acquire -text Acquire \
|
|---|
| 392 | -bg green -activebackground green -command [myproc acquire]
|
|---|
| 393 | button ${config}.restart -text Restart \
|
|---|
| 394 | -bg yellow -activebackground yellow -command [myproc restart]
|
|---|
| 395 | button ${config}.register -text Register \
|
|---|
| 396 | -bg lightblue -activebackground lightblue -command [myproc register]
|
|---|
| 397 |
|
|---|
| 398 | grid ${config}.auto_check -sticky w
|
|---|
| 399 | grid ${config}.spc1
|
|---|
| 400 | grid ${config}.peak_check -sticky w
|
|---|
| 401 | grid ${config}.spc2
|
|---|
| 402 | grid ${config}.thrs_check -sticky w
|
|---|
| 403 | grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
|
|---|
| 404 | grid ${config}.spc3
|
|---|
| 405 | grid ${config}.base_check -sticky w
|
|---|
| 406 | grid ${config}.base_auto -sticky w
|
|---|
| 407 | grid ${config}.base_const -sticky w
|
|---|
| 408 | grid ${config}.base_field -sticky ew -pady 1 -padx 5
|
|---|
| 409 | grid ${config}.spc4
|
|---|
| 410 | grid ${config}.acquire -sticky ew -pady 3 -padx 5
|
|---|
| 411 | grid ${config}.restart -sticky ew -pady 3 -padx 5
|
|---|
| 412 | grid ${config}.register -sticky ew -pady 3 -padx 5
|
|---|
| 413 |
|
|---|
| 414 | grid ${graph} -row 0 -column 0 -sticky news
|
|---|
| 415 | grid ${config} -row 0 -column 1
|
|---|
| 416 |
|
|---|
| 417 | # enable zooming
|
|---|
| 418 | Blt_ZoomStack $graph
|
|---|
| 419 |
|
|---|
| 420 | #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
|
|---|
| 421 |
|
|---|
| 422 | # create one element with data for the x and y axis, no dots
|
|---|
| 423 | $graph element create Spectrum1 -symbol none -smooth step -xdata $xvec -ydata $yvec
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | # -------------------------------------------------------------------------
|
|---|
| 427 |
|
|---|
| 428 | HstDisplay instproc auto_update args {
|
|---|
| 429 | my instvar auto after_handle
|
|---|
| 430 | my instvar config
|
|---|
| 431 | if {$auto} {
|
|---|
| 432 | ${config}.acquire configure -state disabled
|
|---|
| 433 | ${config}.register configure -state disabled
|
|---|
| 434 |
|
|---|
| 435 | my acquire_loop
|
|---|
| 436 | } else {
|
|---|
| 437 | if {[my exists after_handle]} {
|
|---|
| 438 | after cancel $after_handle
|
|---|
| 439 | }
|
|---|
| 440 | ${config}.acquire configure -state active
|
|---|
| 441 | ${config}.register configure -state active
|
|---|
| 442 | }
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | # -------------------------------------------------------------------------
|
|---|
| 446 |
|
|---|
| 447 | HstDisplay instproc mux {} {
|
|---|
| 448 | my instvar peak_mux base_mux
|
|---|
| 449 |
|
|---|
| 450 | format {%x%x%x%x} $base_mux $peak_mux 0 0
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 | # -------------------------------------------------------------------------
|
|---|
| 454 |
|
|---|
| 455 | HstDisplay instproc peak_update args {
|
|---|
| 456 | my instvar number peak peak_mux
|
|---|
| 457 |
|
|---|
| 458 | set mux_addr [format %04x [expr {20 + ${number}}]]
|
|---|
| 459 |
|
|---|
| 460 | if {$peak} {
|
|---|
| 461 | set peak_mux 1
|
|---|
| 462 | my send_data [usb::convert ${mux_addr}[my mux]00000000]
|
|---|
| 463 | } else {
|
|---|
| 464 | set peak_mux 0
|
|---|
| 465 | my send_data [usb::convert ${mux_addr}[my mux]00000000]
|
|---|
| 466 | }
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | # -------------------------------------------------------------------------
|
|---|
| 470 |
|
|---|
| 471 | HstDisplay instproc thrs_update args {
|
|---|
| 472 | my instvar config number thrs thrs_val
|
|---|
| 473 |
|
|---|
| 474 | set val_addr [format %04x [expr {14 + ${number}}]]
|
|---|
| 475 | set value [format %04x $thrs_val]
|
|---|
| 476 |
|
|---|
| 477 | if {$thrs} {
|
|---|
| 478 | ${config}.thrs_field configure -state normal
|
|---|
| 479 | my send_data [usb::convert ${val_addr}${value}00000000]
|
|---|
| 480 | } else {
|
|---|
| 481 | ${config}.thrs_field configure -state disabled
|
|---|
| 482 | my send_data [usb::convert ${val_addr}000000000000]
|
|---|
| 483 | }
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | # -------------------------------------------------------------------------
|
|---|
| 487 |
|
|---|
| 488 | HstDisplay instproc thrs_val_update args {
|
|---|
| 489 | my instvar config number thrs_val
|
|---|
| 490 |
|
|---|
| 491 | set val_addr [format %04x [expr {14 + ${number}}]]
|
|---|
| 492 | set value [format %04x $thrs_val]
|
|---|
| 493 |
|
|---|
| 494 | ${config}.base_field configure -state normal
|
|---|
| 495 | my send_data [usb::convert ${val_addr}${value}00000000]
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | # -------------------------------------------------------------------------
|
|---|
| 499 |
|
|---|
| 500 | HstDisplay instproc base_update args {
|
|---|
| 501 | my instvar config number base base_val base_mux
|
|---|
| 502 |
|
|---|
| 503 | set mux_addr [format %04x [expr {20 + ${number}}]]
|
|---|
| 504 | set val_addr [format %04x [expr {11 + ${number}}]]
|
|---|
| 505 |
|
|---|
| 506 | if {$base} {
|
|---|
| 507 | ${config}.base_auto configure -state normal
|
|---|
| 508 | ${config}.base_const configure -state normal
|
|---|
| 509 | my base_typ_update
|
|---|
| 510 | } else {
|
|---|
| 511 | ${config}.base_auto configure -state disabled
|
|---|
| 512 | ${config}.base_const configure -state disabled
|
|---|
| 513 | ${config}.base_field configure -state disabled
|
|---|
| 514 | set base_mux 0
|
|---|
| 515 | my send_data [usb::convert ${mux_addr}[my mux]00000000${val_addr}000000000000]
|
|---|
| 516 | }
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 | # -------------------------------------------------------------------------
|
|---|
| 520 |
|
|---|
| 521 | HstDisplay instproc base_typ_update args {
|
|---|
| 522 | my instvar config number base_typ base_val base_mux
|
|---|
| 523 |
|
|---|
| 524 | set mux_addr [format %04x [expr {20 + ${number}}]]
|
|---|
| 525 | set val_addr [format %04x [expr {11 + ${number}}]]
|
|---|
| 526 | set value [format %04x $base_val]
|
|---|
| 527 |
|
|---|
| 528 | switch -- $base_typ {
|
|---|
| 529 | auto {
|
|---|
| 530 | ${config}.base_field configure -state disabled
|
|---|
| 531 | set base_mux 1
|
|---|
| 532 | my send_data [usb::convert ${mux_addr}[my mux]00000000]
|
|---|
| 533 | }
|
|---|
| 534 | const {
|
|---|
| 535 | ${config}.base_field configure -state normal
|
|---|
| 536 | set base_mux 0
|
|---|
| 537 | my send_data [usb::convert ${mux_addr}[my mux]00000000${val_addr}${value}00000000]
|
|---|
| 538 | }
|
|---|
| 539 | }
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | # -------------------------------------------------------------------------
|
|---|
| 543 |
|
|---|
| 544 | HstDisplay instproc base_val_update args {
|
|---|
| 545 | my instvar number base_val
|
|---|
| 546 |
|
|---|
| 547 | set val_addr [format %04x [expr {11 + ${number}}]]
|
|---|
| 548 | set value [format %04x $base_val]
|
|---|
| 549 |
|
|---|
| 550 | my send_data [usb::convert ${val_addr}${value}00000000]
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | # -------------------------------------------------------------------------
|
|---|
| 554 |
|
|---|
| 555 | HstDisplay instproc save_data {data} {
|
|---|
| 556 | set file [tk_getSaveFile]
|
|---|
| 557 | if {[string equal $file {}]} {
|
|---|
| 558 | return
|
|---|
| 559 | }
|
|---|
| 560 |
|
|---|
| 561 | set x [catch {set fid [open $file w+]}]
|
|---|
| 562 | set y [catch {puts $fid $data}]
|
|---|
| 563 | set z [catch {close $fid}]
|
|---|
| 564 |
|
|---|
| 565 | if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
|
|---|
| 566 | tk_messageBox -icon error \
|
|---|
| 567 | -message "An error occurred while writing to \"$file\""
|
|---|
| 568 | } else {
|
|---|
| 569 | tk_messageBox -icon info \
|
|---|
| 570 | -message "File \"$file\" written successfully"
|
|---|
| 571 | }
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | # -------------------------------------------------------------------------
|
|---|
| 575 |
|
|---|
| 576 | HstDisplay instproc register {} {
|
|---|
| 577 | my save_data [my set data]
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | # -------------------------------------------------------------------------
|
|---|
| 581 |
|
|---|
| 582 | HstDisplay instproc send_data {data} {
|
|---|
| 583 | global usb_handle
|
|---|
| 584 |
|
|---|
| 585 | if {[catch {$usb_handle writeRaw $data} result]} {
|
|---|
| 586 | puts {Error during write}
|
|---|
| 587 | puts $result
|
|---|
| 588 | }
|
|---|
| 589 | }
|
|---|
| 590 |
|
|---|
| 591 | # -------------------------------------------------------------------------
|
|---|
| 592 |
|
|---|
| 593 | HstDisplay instproc restart {} {
|
|---|
| 594 | my instvar restart_command
|
|---|
| 595 | my send_data $restart_command
|
|---|
| 596 | }
|
|---|
| 597 |
|
|---|
| 598 | # -------------------------------------------------------------------------
|
|---|
| 599 |
|
|---|
| 600 | HstDisplay instproc acquire {} {
|
|---|
| 601 | global usb_handle
|
|---|
| 602 | my instvar xvec yvec data fltr_val
|
|---|
| 603 | my instvar acquire_command
|
|---|
| 604 |
|
|---|
| 605 | my send_data $acquire_command
|
|---|
| 606 |
|
|---|
| 607 | set usb_data {}
|
|---|
| 608 | if {[catch {$usb_handle readHex 4 4096} usb_data]} {
|
|---|
| 609 | puts {Error during read}
|
|---|
| 610 | puts $usb_data
|
|---|
| 611 | set usb_data {}
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | set data $usb_data
|
|---|
| 615 |
|
|---|
| 616 | $yvec set $usb_data
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | # -------------------------------------------------------------------------
|
|---|
| 620 |
|
|---|
| 621 | HstDisplay instproc acquire_loop {} {
|
|---|
| 622 | my instvar after_handle
|
|---|
| 623 |
|
|---|
| 624 | my acquire
|
|---|
| 625 |
|
|---|
| 626 | set after_handle [after 1000 [myproc acquire_loop]]
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 | # -------------------------------------------------------------------------
|
|---|
| 630 |
|
|---|
| 631 | namespace export HstDisplay
|
|---|
| 632 | namespace export OscDisplay
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 | set notebook [::blt::tabnotebook .notebook -side bottom]
|
|---|
| 636 |
|
|---|
| 637 | pack $notebook -expand 1 -fill both
|
|---|
| 638 |
|
|---|
| 639 | set window [frame ${notebook}.hst_2]
|
|---|
| 640 | $notebook insert end -text "Histogram" -window $window -fill both
|
|---|
| 641 | ::mca::HstDisplay hst_2 -number 2 -master $window
|
|---|
| 642 |
|
|---|
| 643 | grid rowconfigure $window 0 -weight 1
|
|---|
| 644 | grid columnconfigure $window 0 -weight 1
|
|---|
| 645 | grid columnconfigure $window 1 -weight 0 -minsize 80
|
|---|
| 646 |
|
|---|
| 647 | set window [frame ${notebook}.osc_2]
|
|---|
| 648 | $notebook insert end -text "Pulse shape" -window $window -fill both
|
|---|
| 649 | ::mca::OscDisplay osc_2 -number 2 -master $window
|
|---|
| 650 |
|
|---|
| 651 | grid rowconfigure $window 0 -weight 1
|
|---|
| 652 | grid columnconfigure $window 0 -weight 1
|
|---|
| 653 | grid columnconfigure $window 1 -weight 0 -minsize 80
|
|---|
| 654 |
|
|---|
| 655 | set usb_handle {}
|
|---|
| 656 |
|
|---|
| 657 | while {[catch {usb::connect 0x09FB 0x6001 1 1 0} usb_handle]} {
|
|---|
| 658 | set answer [tk_messageBox -icon error -type retrycancel \
|
|---|
| 659 | -message {Cannot access USB device} -detail $usb_handle]
|
|---|
| 660 | if {[string equal $answer cancel]} break
|
|---|
| 661 | }
|
|---|
| 662 |
|
|---|
| 663 | hst_2 restart
|
|---|
| 664 | osc_2 restart
|
|---|
| 665 |
|
|---|
| 666 | hst_2 start
|
|---|
| 667 | osc_2 start
|
|---|
| 668 |
|
|---|
| 669 | # configure polarity
|
|---|
| 670 | # set polarity_command [usb::convert 000A011100000000]
|
|---|
| 671 | set polarity_command [usb::convert 000A001100000000]
|
|---|
| 672 | if {[catch {$usb_handle writeRaw $polarity_command} result]} {
|
|---|
| 673 | puts {Error during write}
|
|---|
| 674 | puts $result
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | hst_2 restart
|
|---|
| 678 | osc_2 restart
|
|---|