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