Changeset 85


Ignore:
Timestamp:
Dec 21, 2009, 5:13:58 PM (15 years ago)
Author:
demin
Message:

add possibility to record full EPT information

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MultiChannelUSB/UserInterface.tcl

    r82 r85  
    55package require usb
    66
    7 wm minsize . 800 600
     7package require zlib
     8
     9wm minsize . 1000 700
    810
    911namespace eval ::mca {
     
    1416    namespace import ::blt::tabnotebook
    1517
    16     proc validate {value} {
    17         if {![regexp {^[1-9][0-9]*$} $value]} {
     18    proc validate {max value} {
     19        if {![regexp {^[0-9]*$} $value]} {
    1820            return 0
    19         } elseif {$value > 4095} {
     21        } elseif {$value > $max} {
    2022            return 0
    2123        } elseif {[string length $value] > 4} {
     
    2830# -------------------------------------------------------------------------
    2931
    30     Class CfgDisplay -parameter {
     32    Class Display
     33
     34# -------------------------------------------------------------------------
     35
     36    Display instproc usbCmd {command} {
     37        global usb_handle
     38
     39        if {[catch {$usb_handle writeRaw [usb::convert $command]} result]} {
     40            puts {Error during write}
     41            puts $result
     42        }
     43    }
     44
     45# -------------------------------------------------------------------------
     46
     47    Display instproc usbCmdRead {command width size} {
     48        global usb_handle
     49
     50        my usbCmd $command
     51
     52        set usb_data {}
     53        if {[catch {$usb_handle readHex $width $size} result]} {
     54            puts {Error during read}
     55            puts $result
     56            set result {}
     57        }
     58
     59        my set data $result
     60    }
     61
     62# -------------------------------------------------------------------------
     63
     64    Display instproc usbCmdReadEpt {command size} {
     65        global usb_handle
     66
     67        my usbCmd $command
     68
     69        set usb_data {}
     70        if {[catch {$usb_handle readEpt $size} result]} {
     71            puts {Error during read}
     72            puts $result
     73            set result {}
     74        }
     75
     76        my set data $result
     77    }
     78
     79# -------------------------------------------------------------------------
     80
     81    Class CfgDisplay -superclass Display -parameter {
    3182        {master}
    3283    }
     
    116167        set command 0005012000050030000500[string range $value 0 1]000502[string index $value 2]0
    117168
    118         my send_data [usb::convert $command]
     169        my usbCmd $command
    119170    }
    120171
     
    127178        set command 0005012400050030000500[string range $value 0 1]000502[string index $value 2]0
    128179
    129         my send_data [usb::convert $command]
     180        my usbCmd $command
    130181    }
    131182
     
    137188        set value [format {0%x%x%x} $polar(3) $polar(2) $polar(1)]
    138189
    139         my send_data [usb::convert 000A${value}]
    140     }
    141 
    142 # -------------------------------------------------------------------------
    143 
    144     CfgDisplay instproc send_data {data} {
    145         global usb_handle
    146 
    147         if {[catch {$usb_handle writeRaw $data} result]} {
    148             puts {Error during write}
    149             puts $result
    150         }
    151     }
    152 
    153 # -------------------------------------------------------------------------
    154 
    155     Class OscDisplay -parameter {
     190        my usbCmd 000A${value}
     191    }
     192
     193# -------------------------------------------------------------------------
     194
     195    Class OscDisplay -superclass Display -parameter {
    156196        {number}
    157197        {master}
     
    199239        set disp_mux 2
    200240
     241        trace add variable [myvar data] write [myproc data_update]
    201242        trace add variable [myvar auto] write [myproc auto_update]
    202243        trace add variable [myvar thrs] write [myproc thrs_update]
     
    207248        ${config}.auto_check select
    208249        ${config}.thrs_check select
    209         ${config}.thrs_field set 60
     250        ${config}.thrs_field set 1278
    210251        ${config}.disp_uwt2 select
    211252        ${config}.trig_uwt2 select
     
    218259        my instvar data xvec yvec
    219260        my instvar config auto thrs thrs_val disp_val trig_val
    220 
    221         my set restart_command [usb::convert 0001000${number}]
    222         my set acquire_command [usb::convert 0002000${number}]
    223261
    224262        # create a graph widget and show a grid
     
    239277        spinbox ${config}.thrs_field -from 1 -to 4095 \
    240278            -increment 5 -width 10 -textvariable [myvar thrs_val] \
    241             -validate all -vcmd {::mca::validate %P}
     279            -validate all -vcmd {::mca::validate 4095 %P}
    242280
    243281        frame ${config}.spc2 -width 10 -height 10
     
    313351# -------------------------------------------------------------------------
    314352
     353    OscDisplay instproc data_update args {
     354        my instvar data yvec
     355        $yvec set $data
     356    }
     357
     358# -------------------------------------------------------------------------
     359
    315360    OscDisplay instproc auto_update args {
    316361        my instvar config auto after_handle
     
    344389        } else {
    345390            ${config}.thrs_field configure -state disabled
    346             my send_data [usb::convert ${val_addr}0000]
     391            my usbCmd ${val_addr}0000
    347392        }
    348393    }
     
    353398        my instvar config number thrs_val
    354399
     400        if {[string equal $thrs_val {}]} {
     401            set thrs_val 0
     402        }
     403
    355404        set val_addr [format %04x [expr {17 + ${number}}]]
    356405        set value [format %04x $thrs_val]
    357406
    358         my send_data [usb::convert ${val_addr}${value}]
     407        my usbCmd ${val_addr}${value}
    359408    }
    360409
     
    377426            data {
    378427                set disp_mux 0
    379                 my send_data [usb::convert ${mux_addr}[my mux]]
     428                my usbCmd ${mux_addr}[my mux]
    380429            }
    381430            uwt1 {
    382431                set disp_mux 1
    383                 my send_data [usb::convert ${mux_addr}[my mux]]
     432                my usbCmd ${mux_addr}[my mux]
    384433            }
    385434            uwt2 {
    386435                set disp_mux 2
    387                 my send_data [usb::convert ${mux_addr}[my mux]]
     436                my usbCmd ${mux_addr}[my mux]
    388437            }
    389438            uwt3 {
    390439                set disp_mux 3
    391                 my send_data [usb::convert ${mux_addr}[my mux]]
     440                my usbCmd ${mux_addr}[my mux]
    392441            }
    393442            base {
    394443                set disp_mux 4
    395                 my send_data [usb::convert ${mux_addr}[my mux]]
     444                my usbCmd ${mux_addr}[my mux]
    396445            }
    397446        }
     
    408457            data {
    409458                set trig_mux 0
    410                 my send_data [usb::convert ${mux_addr}[my mux]]
     459                my usbCmd ${mux_addr}[my mux]
    411460            }
    412461            uwt1 {
    413462                set trig_mux 1
    414                 my send_data [usb::convert ${mux_addr}[my mux]]
     463                my usbCmd ${mux_addr}[my mux]
    415464            }
    416465            uwt2 {
    417466                set trig_mux 2
    418                 my send_data [usb::convert ${mux_addr}[my mux]]
     467                my usbCmd ${mux_addr}[my mux]
    419468            }
    420469            uwt3 {
    421470                set trig_mux 3
    422                 my send_data [usb::convert ${mux_addr}[my mux]]
     471                my usbCmd ${mux_addr}[my mux]
    423472            }
    424473            base {
    425474                set trig_mux 4
    426                 my send_data [usb::convert ${mux_addr}[my mux]]
     475                my usbCmd ${mux_addr}[my mux]
    427476            }
    428477        }
     
    452501# -------------------------------------------------------------------------
    453502
     503    OscDisplay instproc acquire {} {
     504        my instvar number
     505        my usbCmdRead 0002000${number} 2 1024
     506   }
     507
     508# -------------------------------------------------------------------------
     509
     510    OscDisplay instproc restart {} {
     511        my instvar number
     512        my usbCmd 0001000${number}
     513    }
     514
     515# -------------------------------------------------------------------------
     516
    454517    OscDisplay instproc register {} {
    455518        my save_data [my set data]
     
    458521# -------------------------------------------------------------------------
    459522
    460     OscDisplay instproc send_data {data} {
    461         global usb_handle
    462 
    463         if {[catch {$usb_handle writeRaw $data} result]} {
    464             puts {Error during write}
    465             puts $result
    466         }
    467     }
    468 
    469 # -------------------------------------------------------------------------
    470 
    471     OscDisplay instproc restart {} {
    472         my instvar restart_command
    473         my send_data $restart_command
    474     }
    475 
    476 # -------------------------------------------------------------------------
    477 
    478     OscDisplay instproc acquire {} {
    479         global usb_handle
    480         my instvar xvec yvec data
    481         my instvar acquire_command
    482 
    483         my send_data $acquire_command
    484 
    485         set usb_data {}
    486         if {[catch {$usb_handle readHex 2 1024} usb_data]} {
    487             puts {Error during read}
    488             puts $usb_data
    489             set usb_data {}
    490         }
    491 
    492         set data $usb_data
    493 
    494         $yvec set $usb_data
    495     }
    496 
    497 # -------------------------------------------------------------------------
    498 
    499523    OscDisplay instproc acquire_restart_loop {} {
    500         my instvar after_handle
     524        my instvar number after_handle
    501525
    502526        my acquire
     
    508532# -------------------------------------------------------------------------
    509533
    510     Class HstDisplay -parameter {
     534    Class HstDisplay -superclass Display -parameter {
    511535        {number}
    512536        {master}
     
    554578        set peak_mux 1
    555579
     580        trace add variable [myvar axis] write [myproc axis_update]
     581        trace add variable [myvar data] write [myproc data_update]
    556582        trace add variable [myvar auto] write [myproc auto_update]
    557583        trace add variable [myvar peak] write [myproc peak_update]
     
    562588        trace add variable [myvar base_val] write [myproc base_val_update]
    563589
     590        ${config}.axis_check deselect
    564591        ${config}.auto_check select
    565592        ${config}.peak_check select
     593
    566594        ${config}.thrs_check select
    567         ${config}.thrs_field set 10
    568         ${config}.base_check select
     595        ${config}.thrs_field set 1278
     596
    569597        ${config}.base_const select
    570598        ${config}.base_field set 35
     599        ${config}.base_check deselect
    571600    }
    572601
     
    575604    HstDisplay instproc setup {} {
    576605        my instvar number master
    577         my instvar data xvec yvec
     606        my instvar data xvec yvec graph
    578607        my instvar config auto thrs thrs_val base base_typ base_val
    579 
    580         my set restart_command [usb::convert 0001001${number}]
    581         my set acquire_command [usb::convert 0002001${number}]
    582608
    583609        # create a graph widget and show a grid
     
    590616        set config [frame ${master}.config]
    591617
     618        checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis]
     619
     620        frame ${config}.spc1 -width 10 -height 10
     621
    592622        checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
    593623
    594         frame ${config}.spc1 -width 10 -height 10
     624        frame ${config}.spc2 -width 10 -height 10
    595625
    596626        checkbutton ${config}.peak_check -text {peak detect} -variable [myvar peak]
    597627
    598         frame ${config}.spc2 -width 10 -height 10
     628        frame ${config}.spc3 -width 10 -height 10
    599629
    600630        checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
    601631        spinbox ${config}.thrs_field -from 1 -to 4095 \
    602632            -increment 5 -width 10 -textvariable [myvar thrs_val] \
    603             -validate all -vcmd {::mca::validate %P}
    604 
    605         frame ${config}.spc3 -width 10 -height 10
     633            -validate all -vcmd {::mca::validate 4095 %P}
     634
     635        frame ${config}.spc4 -width 10 -height 10
    606636
    607637        checkbutton ${config}.base_check -text baseline -variable [myvar base]
     
    610640        spinbox ${config}.base_field -from 1 -to 4095 \
    611641            -increment 5 -width 10 -textvariable [myvar base_val] \
    612             -validate all -vcmd {::mca::validate %P}
    613 
    614         frame ${config}.spc4 -width 10 -height 10
     642            -validate all -vcmd {::mca::validate 4095 %P}
     643
     644        frame ${config}.spc5 -width 10 -height 10
    615645
    616646        button ${config}.acquire -text Acquire \
     
    621651            -bg lightblue -activebackground lightblue -command [myproc register]
    622652
     653        grid ${config}.axis_check -sticky w
     654        grid ${config}.spc1
    623655        grid ${config}.auto_check -sticky w
    624         grid ${config}.spc1
     656        grid ${config}.spc2
    625657        grid ${config}.peak_check -sticky w
    626         grid ${config}.spc2
     658        grid ${config}.spc3
    627659        grid ${config}.thrs_check -sticky w
    628660        grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
    629         grid ${config}.spc3
     661        grid ${config}.spc4
    630662        grid ${config}.base_check -sticky w
    631663        grid ${config}.base_auto -sticky w
    632664        grid ${config}.base_const -sticky w
    633665        grid ${config}.base_field -sticky ew -pady 1 -padx 5
    634         grid ${config}.spc4
     666        grid ${config}.spc5
    635667        grid ${config}.acquire -sticky ew -pady 3 -padx 5
    636668        grid ${config}.restart -sticky ew -pady 3 -padx 5
     
    651683        # create one element with data for the x and y axis, no dots
    652684        $graph element create Spectrum1 -symbol none -smooth step -xdata $xvec -ydata $yvec
     685    }
     686
     687# -------------------------------------------------------------------------
     688
     689    HstDisplay instproc axis_update args {
     690        my instvar axis graph
     691        if {$axis} {
     692            $graph axis configure y -min 1 -max 1E10 -logscale yes
     693        } else {
     694            $graph axis configure y -min {} -max {} -logscale no
     695        }
     696    }
     697
     698# -------------------------------------------------------------------------
     699
     700    HstDisplay instproc data_update args {
     701        my instvar data yvec
     702        $yvec set $data
    653703    }
    654704
     
    689739        if {$peak} {
    690740            set peak_mux 1
    691             my send_data [usb::convert ${mux_addr}[my mux]]
     741            my usbCmd ${mux_addr}[my mux]
    692742        } else {
    693743            set peak_mux 0
    694             my send_data [usb::convert ${mux_addr}[my mux]]
     744            my usbCmd ${mux_addr}[my mux]
    695745        }
    696746    }
     
    702752
    703753        set val_addr [format %04x [expr {14 + ${number}}]]
    704         set value [format %04x $thrs_val]
    705754
    706755        if {$thrs} {
     
    709758        } else {
    710759            ${config}.thrs_field configure -state disabled
    711             my send_data [usb::convert ${val_addr}0000]
     760            my usbCmd ${val_addr}0000
    712761        }
    713762    }
     
    718767        my instvar config number thrs_val
    719768
     769        if {[string equal $thrs_val {}]} {
     770            set thrs_val 0
     771        }
     772
    720773        set val_addr [format %04x [expr {14 + ${number}}]]
    721774        set value [format %04x $thrs_val]
    722775
    723         my send_data [usb::convert ${val_addr}${value}]
     776        my usbCmd ${val_addr}${value}
    724777    }
    725778
     
    741794            ${config}.base_field configure -state disabled
    742795            set base_mux 0
    743             my send_data [usb::convert ${mux_addr}[my mux]${val_addr}0000]
     796            my usbCmd ${mux_addr}[my mux]${val_addr}0000
    744797        }
    745798    }
     
    758811                ${config}.base_field configure -state disabled
    759812                set base_mux 1
    760                 my send_data [usb::convert ${mux_addr}[my mux]]
     813                my usbCmd ${mux_addr}[my mux]
    761814            }
    762815            const {
    763816                ${config}.base_field configure -state normal
    764817                set base_mux 0
    765                 my send_data [usb::convert ${mux_addr}[my mux]${val_addr}${value}]
     818                my usbCmd ${mux_addr}[my mux]${val_addr}${value}
    766819            }
    767820        }
     
    773826        my instvar number base_val
    774827
     828        if {[string equal $base_val {}]} {
     829            set base_val 0
     830        }
     831
    775832        set val_addr [format %04x [expr {11 + ${number}}]]
    776833        set value [format %04x $base_val]
    777834
    778         my send_data [usb::convert ${val_addr}${value}]
     835        my usbCmd ${val_addr}${value}
     836    }
     837
     838# -------------------------------------------------------------------------
     839
     840    HstDisplay instproc acquire {} {
     841        my instvar number
     842        my usbCmdRead 0002001${number} 4 4096
     843   }
     844
     845# -------------------------------------------------------------------------
     846
     847    HstDisplay instproc restart {} {
     848        my instvar number
     849        my usbCmd 0001001${number}
    779850    }
    780851
     
    808879# -------------------------------------------------------------------------
    809880
    810     HstDisplay instproc send_data {data} {
    811         global usb_handle
    812 
    813         if {[catch {$usb_handle writeRaw $data} result]} {
    814             puts {Error during write}
    815             puts $result
    816         }
    817     }
    818 
    819 # -------------------------------------------------------------------------
    820 
    821     HstDisplay instproc restart {} {
    822         my instvar restart_command
    823         my send_data $restart_command
    824     }
    825 
    826 # -------------------------------------------------------------------------
    827 
    828     HstDisplay instproc acquire {} {
    829         global usb_handle
    830         my instvar xvec yvec data fltr_val
    831         my instvar acquire_command
    832 
    833         my send_data $acquire_command
    834 
    835         set usb_data {}
    836         if {[catch {$usb_handle readHex 4 4096} usb_data]} {
    837             puts {Error during read}
    838             puts $usb_data
    839             set usb_data {}
    840         }
    841 
    842         set data $usb_data
    843 
    844         $yvec set $usb_data
    845     }
    846 
    847 # -------------------------------------------------------------------------
    848 
    849881    HstDisplay instproc acquire_loop {} {
     882        my instvar number after_handle
     883
     884        my acquire
     885
     886        set after_handle [after 1000 [myproc acquire_loop]]
     887    }
     888
     889# -------------------------------------------------------------------------
     890
     891    Class EptDisplay -superclass Display -parameter {
     892        {number}
     893        {master}
     894    }
     895
     896# -------------------------------------------------------------------------
     897
     898    EptDisplay instproc init {} {
     899        my instvar data xvec yvec
     900
     901        set xvec [vector #auto]
     902
     903        for {set i 0} {$i < 11} {incr i} {
     904          set yvec($i) [vector #auto]
     905        }
     906
     907        # fill one vector for the x axis
     908        $xvec seq 0 10000
     909
     910        my reset
     911
     912        my setup
     913
     914        next
     915    }
     916
     917# -------------------------------------------------------------------------
     918
     919    EptDisplay instproc destroy {} {
     920        next
     921    }
     922
     923# -------------------------------------------------------------------------
     924
     925    EptDisplay instproc reset {} {
     926        my instvar data xvec yvec
     927        my instvar number_val directory
     928
     929        set data {}
     930
     931        set directory $::env(HOMEPATH)
     932        set number_val 10
     933
     934        for {set i 0} {$i < 11} {incr i} {
     935          $yvec($i) set {}
     936        }
     937    }
     938
     939# -------------------------------------------------------------------------
     940
     941    EptDisplay instproc start {} {
     942        my instvar config
     943
     944        trace add variable [myvar recs_val] write [myproc recs_val_update]
     945        trace add variable [myvar data] write [myproc data_update]
     946        trace add variable [myvar last] write [myproc data_update]
     947
     948    }
     949
     950# -------------------------------------------------------------------------
     951
     952    EptDisplay instproc setup {} {
     953        my instvar master
     954        my instvar data xvec yvec graph
     955        my instvar config number_val
     956
     957        # create a graph widget and show a grid
     958        set display [frame ${master}.display]
     959
     960        set graph(0) [graph ${display}.graph0 -height 200 -leftmargin 80]
     961        $graph(0) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
     962        $graph(0) grid configure -hide no
     963        $graph(0) legend configure -hide yes
     964        $graph(0) axis configure x -min 0 -max 10000
     965        $graph(0) axis configure y -min 0 -max 4100
     966
     967        set graph(1) [graph ${display}.graph1 -height 200 -leftmargin 80]
     968        $graph(1) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
     969        $graph(1) grid configure -hide no
     970        $graph(1) legend configure -hide yes
     971        $graph(1) axis configure x -min 0 -max 10000 -hide yes
     972        $graph(1) axis configure y -min 0 -max 4100
     973
     974        set graph(2) [graph ${display}.graph2 -height 200 -leftmargin 80]
     975        $graph(2) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
     976        $graph(2) grid configure -hide no
     977        $graph(2) legend configure -hide yes
     978        $graph(2) axis configure x -min 0 -max 10000 -hide yes
     979        $graph(2) axis configure y -min 0 -max 4100
     980
     981        set graph(3) [graph ${display}.graph3 -height 100 -leftmargin 80]
     982        $graph(3) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
     983        $graph(3) grid configure -hide no
     984        $graph(3) legend configure -hide yes
     985        $graph(3) axis configure x -min 0 -max 10000 -hide yes
     986        $graph(3) axis configure y -min 0 -max 25
     987
     988        scale ${master}.last -orient horizontal -from 1 -to 35 -tickinterval 0 -showvalue no -variable [myvar last]
     989
     990        set config [frame ${master}.config -width 120]
     991
     992        label ${config}.recs -text {number of records}
     993        spinbox ${config}.recs_field -from 5 -to 100 \
     994            -increment 5 -width 10 -textvariable [myvar recs_val] \
     995            -validate all -vcmd {::mca::validate 100 %P}
     996
     997        frame ${config}.spc1 -width 10 -height 10
     998
     999        button ${config}.sequence -text {Start Recording}  \
     1000            -bg red -activebackground red -command [myproc sequence]
     1001
     1002        frame ${config}.spc2 -width 10 -height 10
     1003
     1004        label ${config}.stat -text {}
     1005
     1006        frame ${config}.spc3 -width 10 -height 20
     1007
     1008        button ${config}.acquire -text Acquire \
     1009            -bg green -activebackground green -command [myproc acquire]
     1010        button ${config}.register -text Register \
     1011            -bg lightblue -activebackground lightblue -command [myproc register]
     1012
     1013
     1014        grid ${config}.recs -sticky w -pady 1 -padx 3
     1015        grid ${config}.recs_field -sticky ew -pady 1 -padx 5
     1016        grid ${config}.spc1
     1017        grid ${config}.sequence -sticky ew -pady 3 -padx 5
     1018        grid ${config}.spc2
     1019        grid ${config}.stat -sticky w -pady 1 -padx 3
     1020        grid ${config}.spc3
     1021        grid ${config}.acquire -sticky ew -pady 3 -padx 5
     1022        grid ${config}.register -sticky ew -pady 3 -padx 5
     1023
     1024        grid ${graph(3)} -row 0 -column 0 -sticky news
     1025        grid ${graph(2)} -row 1 -column 0 -sticky news
     1026        grid ${graph(1)} -row 2 -column 0 -sticky news
     1027        grid ${graph(0)} -row 3 -column 0 -sticky news
     1028
     1029        grid ${display} -row 0 -column 0 -sticky news
     1030        grid ${config} -row 0 -column 1
     1031
     1032        grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew
     1033
     1034        grid rowconfigure ${master} 0 -weight 1
     1035        grid columnconfigure ${master} 0 -weight 1
     1036        grid columnconfigure ${master} 1 -weight 0 -minsize 120
     1037
     1038        grid columnconfigure ${display} 0 -weight 1
     1039        grid rowconfigure ${display} 0 -weight 1
     1040        grid rowconfigure ${display} 1 -weight 1
     1041        grid rowconfigure ${display} 2 -weight 1
     1042        grid rowconfigure ${display} 3 -weight 1
     1043
     1044        # enable zooming
     1045        Blt_ZoomStack $graph(0)
     1046        Blt_ZoomStack $graph(1)
     1047        Blt_ZoomStack $graph(2)
     1048        Blt_ZoomStack $graph(3)
     1049
     1050        #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
     1051
     1052        # create one element with data for the x and y axis, no dots
     1053        $graph(0) element create Spectrum0 -symbol none -xdata $xvec -ydata $yvec(0)
     1054        $graph(1) element create Spectrum1 -symbol none -xdata $xvec -ydata $yvec(1)
     1055        $graph(2) element create Spectrum2 -symbol none -xdata $xvec -ydata $yvec(2)
     1056        for {set i 3} {$i < 11} {incr i} {
     1057          $graph(3) element create Spectrum$i -symbol none -xdata $xvec -ydata $yvec($i)
     1058        }
     1059    }
     1060
     1061# -------------------------------------------------------------------------
     1062
     1063    EptDisplay instproc recs_val_update args {
     1064        my instvar recs_val
     1065        if {[string equal $recs_val {}]} {
     1066            set number_val 0
     1067        }
     1068    }
     1069
     1070# -------------------------------------------------------------------------
     1071
     1072    EptDisplay instproc data_update args {
     1073        my instvar data xvec yvec graph last
     1074
     1075        set first [expr {$last - 1}]
     1076       
     1077        $xvec seq ${first}0000 ${last}0000
     1078        for {set i 0} {$i < 4} {incr i} {
     1079            $graph($i) axis configure x -min ${first}0000 -max ${last}0000
     1080        }
     1081
     1082        for {set i 0} {$i < 11} {incr i} {
     1083            $yvec($i) set [lrange [lindex $data $i] ${first}0000 ${last}0000]
     1084        }
     1085    }
     1086
     1087
     1088# -------------------------------------------------------------------------
     1089
     1090    EptDisplay instproc save_data {data} {
     1091        set file [tk_getSaveFile]
     1092        if {[string equal $file {}]} {
     1093            return
     1094        }
     1095
     1096        set x [catch {set fid [open $file w+]}]
     1097        set y [catch {puts $fid $data}]
     1098        set z [catch {close $fid}]
     1099
     1100        if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
     1101            tk_messageBox -icon error \
     1102                -message "An error occurred while writing to \"$file\""
     1103        } else {
     1104            tk_messageBox -icon info \
     1105                -message "File \"$file\" written successfully"
     1106        }
     1107    }
     1108
     1109# -------------------------------------------------------------------------
     1110
     1111    EptDisplay instproc acquire {} {
     1112        my usbCmdReadEpt 00060000 2097152
     1113   }
     1114
     1115# -------------------------------------------------------------------------
     1116
     1117    EptDisplay instproc register {} {
     1118        my save_data [my set data]
     1119    }
     1120
     1121# -------------------------------------------------------------------------
     1122
     1123    EptDisplay instproc sequence {} {
     1124        my instvar config recs_val directory counter
     1125
     1126        set directory [tk_chooseDirectory -initialdir $directory -title {Choose a directory}]
     1127
     1128        if {[string equal $directory {}]} {
     1129           return
     1130        }
     1131
     1132        ${config}.recs_field configure -state disabled
     1133        ${config}.sequence configure -state disabled
     1134        ${config}.acquire configure -state disabled
     1135        ${config}.register configure -state disabled
     1136       
     1137        set counter 1
     1138       
     1139        if {$counter <= $recs_val} {
     1140            ${config}.stat configure -text "record $counter of $recs_val"
     1141            set after_handle [after 100 [myproc acquire_register_loop]]
     1142        }
     1143    }
     1144
     1145# -------------------------------------------------------------------------
     1146
     1147    EptDisplay instproc acquire_register_loop {} {
    8501148        my instvar after_handle
     1149        my instvar config data recs_val directory counter
    8511150
    8521151        my acquire
    8531152
    854         set after_handle [after 1000 [myproc acquire_loop]]
    855     }
    856 
    857 # -------------------------------------------------------------------------
    858 
     1153        set file [file join $directory ept_$counter.dat.gz]
     1154
     1155        set x [catch {set fid [open $file w+]}]
     1156        fconfigure $fid -translation binary -encoding binary
     1157
     1158        set y [catch {
     1159            puts -nonewline $fid [binary format "H*iH*" "1f8b0800" [clock seconds] "0003"]
     1160            puts -nonewline $fid [zlib deflate $data]
     1161            puts -nonewline $fid [binary format i [zlib crc32 $data]]
     1162            puts -nonewline $fid [binary format i [string length $data]]
     1163        }]
     1164
     1165        set z [catch {close $fid}]
     1166
     1167        my incr counter
     1168
     1169        if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
     1170            tk_messageBox -icon error -message "An error occurred while writing to \"$file\""
     1171        } elseif {$counter <= $recs_val} {
     1172            ${config}.stat configure -text "record $counter of $recs_val"
     1173            set after_handle [after 100 [myproc acquire_register_loop]]
     1174            return
     1175        }
     1176       
     1177        ${config}.stat configure -text {}
     1178        ${config}.recs_field configure -state normal
     1179        ${config}.sequence configure -state active
     1180        ${config}.acquire configure -state active
     1181        ${config}.register configure -state active
     1182
     1183    }
     1184
     1185# -------------------------------------------------------------------------
     1186
     1187    Class MemDisplay -superclass Display -parameter {
     1188        {number}
     1189        {master}
     1190    }
     1191
     1192# -------------------------------------------------------------------------
     1193
     1194    MemDisplay instproc init {} {
     1195        my instvar data xvec yvec
     1196
     1197        set xvec [vector #auto]
     1198        set yvec [vector #auto]
     1199
     1200        # fill one vector for the x axis
     1201        $xvec seq 0 10000
     1202
     1203        my reset
     1204
     1205        my setup
     1206
     1207        next
     1208    }
     1209
     1210# -------------------------------------------------------------------------
     1211
     1212    MemDisplay instproc destroy {} {
     1213        next
     1214    }
     1215
     1216# -------------------------------------------------------------------------
     1217
     1218    MemDisplay instproc reset {} {
     1219        my instvar data xvec yvec
     1220
     1221        set data {}
     1222
     1223        $yvec set {}
     1224    }
     1225
     1226# -------------------------------------------------------------------------
     1227
     1228    MemDisplay instproc start {} {
     1229        my instvar config
     1230
     1231        trace add variable [myvar data] write [myproc data_update]
     1232        trace add variable [myvar last] write [myproc data_update]
     1233    }
     1234
     1235# -------------------------------------------------------------------------
     1236
     1237    MemDisplay instproc setup {} {
     1238        my instvar master
     1239        my instvar data xvec yvec
     1240        my instvar config auto thrs thrs_val disp_val trig_val
     1241
     1242        # create a graph widget and show a grid
     1243        set graph [graph ${master}.graph -height 250 -leftmargin 80]
     1244        $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 }
     1245        $graph grid configure -hide no
     1246        $graph legend configure -hide yes
     1247        $graph axis configure x -min 0 -max 10000
     1248#        $graph axis configure y -min 0 -max 4100
     1249
     1250        scale ${master}.last -orient horizontal -from 1 -to 105 -tickinterval 0 -variable [myvar last]
     1251
     1252        set config [frame ${master}.config]
     1253
     1254        button ${config}.acquire -text Acquire \
     1255            -bg green -activebackground green -command [myproc acquire]
     1256        button ${config}.register -text Register \
     1257            -bg lightblue -activebackground lightblue -command [myproc register]
     1258
     1259        grid ${config}.acquire -sticky ew -pady 3 -padx 5
     1260        grid ${config}.register -sticky ew -pady 3 -padx 5
     1261
     1262        grid ${graph} -row 0 -column 0 -sticky news
     1263        grid ${config} -row 0 -column 1
     1264
     1265        grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew
     1266
     1267        grid rowconfigure ${master} 0 -weight 1
     1268        grid columnconfigure ${master} 0 -weight 1
     1269        grid columnconfigure ${master} 1 -weight 0 -minsize 80
     1270
     1271        # enable zooming
     1272        Blt_ZoomStack $graph
     1273
     1274        #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
     1275
     1276        # create one element with data for the x and y axis, no dots
     1277        $graph element create Spectrum -symbol none -xdata $xvec -ydata $yvec
     1278    }
     1279
     1280# -------------------------------------------------------------------------
     1281
     1282    MemDisplay instproc data_update args {
     1283        my instvar data yvec last
     1284
     1285        set first [expr {$last - 1}]
     1286        $yvec set [lrange $data ${first}0000 ${last}0000]
     1287    }
     1288
     1289# -------------------------------------------------------------------------
     1290
     1291    MemDisplay instproc save_data {data} {
     1292        set file [tk_getSaveFile]
     1293        if {[string equal $file {}]} {
     1294            return
     1295        }
     1296
     1297        set x [catch {set fid [open $file w+]}]
     1298        set y [catch {puts $fid $data}]
     1299        set z [catch {close $fid}]
     1300
     1301        if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } {
     1302            tk_messageBox -icon error \
     1303                -message "An error occurred while writing to \"$file\""
     1304        } else {
     1305            tk_messageBox -icon info \
     1306                -message "File \"$file\" written successfully"
     1307        }
     1308    }
     1309
     1310# -------------------------------------------------------------------------
     1311
     1312    MemDisplay instproc acquire {} {
     1313        my usbCmdRead 00040000 1 524288
     1314#        my usbCmdRead 00060000 1 1048576
     1315   }
     1316
     1317# -------------------------------------------------------------------------
     1318
     1319    MemDisplay instproc register {} {
     1320        my save_data [my set data]
     1321    }
     1322
     1323# -------------------------------------------------------------------------
     1324
     1325    namespace export MemDisplay
     1326    namespace export EptDisplay
    8591327    namespace export HstDisplay
    8601328    namespace export OscDisplay
     
    8881356::mca::CfgDisplay cfg -master $config
    8891357
     1358set window [frame ${notebook}.ept]
     1359$notebook insert end -text "EPT" -window $window -fill both
     1360::mca::EptDisplay ept -master $window
     1361
     1362#set window [frame ${notebook}.mem]
     1363#$notebook insert end -text "Memory test" -window $window -fill both
     1364#::mca::MemDisplay mem -master $window
     1365
    8901366set usb_handle {}
    8911367
     
    8931369    set answer [tk_messageBox -icon error -type retrycancel \
    8941370        -message {Cannot access USB device} -detail $usb_handle]
    895     if {[string equal $answer cancel]} exit
     1371    if {[string equal $answer cancel]} break
    8961372}
    8971373
    8981374# cfg reset
    899 set reset_command [usb::convert 00000000]
    900 if {[catch {$usb_handle writeRaw $reset_command} result]} {
    901     puts {Error during write}
    902     puts $result
    903 }
     1375cfg reset
    9041376
    9051377cfg start
     
    9121384    osc_$i restart
    9131385}
     1386
     1387ept start
     1388#mem start
Note: See TracChangeset for help on using the changeset viewer.