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