Changeset 77 for trunk/MultiChannelUSB


Ignore:
Timestamp:
Nov 29, 2009, 11:11:25 PM (15 years ago)
Author:
demin
Message:

add configuration form and activate all channels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MultiChannelUSB/UserInterface.tcl

    r74 r77  
    2828# -------------------------------------------------------------------------
    2929
     30    Class CfgDisplay -parameter {
     31        {master}
     32    }
     33
     34# -------------------------------------------------------------------------
     35
     36    CfgDisplay instproc init {} {
     37
     38        my reset
     39
     40        my setup
     41
     42        next
     43    }
     44
     45# -------------------------------------------------------------------------
     46
     47    CfgDisplay instproc destroy {} {
     48        next
     49    }
     50
     51# -------------------------------------------------------------------------
     52
     53    CfgDisplay instproc reset {} {
     54    }
     55
     56# -------------------------------------------------------------------------
     57
     58    CfgDisplay instproc start {} {
     59        my instvar config
     60
     61        trace add variable [myvar dac1] write [myproc dac1_update]
     62        trace add variable [myvar dac2] write [myproc dac2_update]
     63        trace add variable [myvar polar] write [myproc polar_update]
     64
     65        ${config(1)}.scale set 0
     66        ${config(2)}.scale set 0
     67
     68        ${config(3)}.polar1 select
     69        ${config(3)}.polar2 select
     70    }
     71
     72# -------------------------------------------------------------------------
     73
     74    CfgDisplay instproc setup {} {
     75        my instvar number master
     76        my instvar config
     77
     78        set config(1) [labelframe ${master}.cfg1 -text {DAC 20}]
     79        set config(2) [labelframe ${master}.cfg2 -text {DAC 24}]
     80        set config(3) [labelframe ${master}.cfg3 -text {polarity inversion}]
     81
     82        frame ${config(1)}.limits
     83        label ${config(1)}.limits.min -text {0V}
     84        label ${config(1)}.limits.max -text {-3.3V}
     85        scale ${config(1)}.scale -orient horizontal -from 0 -to 4095 -tickinterval 500 -variable [myvar dac1]
     86
     87        frame ${config(2)}.limits
     88        label ${config(2)}.limits.min -text {0V}
     89        label ${config(2)}.limits.max -text {-3.3V}
     90        scale ${config(2)}.scale -orient horizontal -from 0 -to 4095 -tickinterval 500 -variable [myvar dac2]
     91
     92        checkbutton ${config(3)}.polar1 -text {channel 1} -variable [myvar polar(1)]
     93        checkbutton ${config(3)}.polar2 -text {channel 2} -variable [myvar polar(2)]
     94        checkbutton ${config(3)}.polar3 -text {channel 3} -variable [myvar polar(3)]
     95
     96        pack ${config(1)} ${config(2)} -side top -expand yes -fill x -padx 10
     97        pack ${config(3)} -side top -expand yes -fill x -padx 10
     98
     99        pack ${config(1)}.limits.min -anchor w -side left -padx 13
     100        pack ${config(1)}.limits.max -anchor e -side right -padx 5
     101        pack ${config(1)}.limits ${config(1)}.scale -side top -expand yes -fill x
     102
     103        pack ${config(2)}.limits.min -anchor w -side left -padx 13
     104        pack ${config(2)}.limits.max -anchor e -side right -padx 5
     105        pack ${config(2)}.limits ${config(2)}.scale -side top -expand yes -fill x
     106
     107        pack ${config(3)}.polar1 -side left -expand yes -fill x -pady 10
     108        pack ${config(3)}.polar2 -side left -expand yes -fill x -pady 10
     109        pack ${config(3)}.polar3 -side left -expand yes -fill x -pady 10
     110
     111    }
     112
     113# -------------------------------------------------------------------------
     114
     115    CfgDisplay instproc dac1_update args {
     116        my instvar dac1
     117
     118        set value [format {%03x} $dac1]
     119        set command 0005012000050030000500[string range $value 0 1]000502[string index $value 2]0
     120
     121        my send_data [usb::convert $command]
     122    }
     123
     124# -------------------------------------------------------------------------
     125
     126    CfgDisplay instproc dac2_update args {
     127        my instvar dac2
     128
     129        set value [format {%03x} $dac2]
     130        set command 0005012400050030000500[string range $value 0 1]000502[string index $value 2]0
     131
     132        my send_data [usb::convert $command]
     133    }
     134
     135# -------------------------------------------------------------------------
     136
     137    CfgDisplay instproc polar_update args {
     138        my instvar polar
     139
     140        set value [format {0%x%x%x} $polar(3) $polar(2) $polar(1)]
     141
     142        my send_data [usb::convert 000A${value}]
     143    }
     144
     145# -------------------------------------------------------------------------
     146
     147    CfgDisplay instproc send_data {data} {
     148        global usb_handle
     149
     150        if {[catch {$usb_handle writeRaw $data} result]} {
     151            puts {Error during write}
     152            puts $result
     153        }
     154    }
     155
     156# -------------------------------------------------------------------------
     157
    30158    Class OscDisplay -parameter {
    31159        {number}
     
    94222        my instvar config auto thrs thrs_val disp_val trig_val
    95223
    96         my set restart_command [usb::convert 0001000${number}00000000]
    97         my set acquire_command [usb::convert 0002000${number}00000000]
     224        my set restart_command [usb::convert 0001000${number}]
     225        my set acquire_command [usb::convert 0002000${number}]
    98226
    99227        # create a graph widget and show a grid
     
    103231        $graph legend configure -hide yes
    104232        $graph axis configure x -min 0 -max 1024
     233        $graph axis configure y -min 0 -max 4100
    105234
    106235        set config [frame ${master}.config]
     
    172301        grid ${config} -row 0 -column 1
    173302
     303        grid rowconfigure ${master} 0 -weight 1
     304        grid columnconfigure ${master} 0 -weight 1
     305        grid columnconfigure ${master} 1 -weight 0 -minsize 80
     306
    174307        # enable zooming
    175308        Blt_ZoomStack $graph
     
    214347        } else {
    215348            ${config}.thrs_field configure -state disabled
    216             my send_data [usb::convert ${val_addr}000000000000]
     349            my send_data [usb::convert ${val_addr}0000]
    217350        }
    218351    }
     
    226359        set value [format %04x $thrs_val]
    227360
    228         my send_data [usb::convert ${val_addr}${value}00000000]
     361        my send_data [usb::convert ${val_addr}${value}]
    229362    }
    230363
     
    247380            data {
    248381                set disp_mux 0
    249                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     382                my send_data [usb::convert ${mux_addr}[my mux]]
    250383            }
    251384            uwt1 {
    252385                set disp_mux 1
    253                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     386                my send_data [usb::convert ${mux_addr}[my mux]]
    254387            }
    255388            uwt2 {
    256389                set disp_mux 2
    257                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     390                my send_data [usb::convert ${mux_addr}[my mux]]
    258391            }
    259392            uwt3 {
    260393                set disp_mux 3
    261                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     394                my send_data [usb::convert ${mux_addr}[my mux]]
    262395            }
    263396            base {
    264397                set disp_mux 4
    265                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     398                my send_data [usb::convert ${mux_addr}[my mux]]
    266399            }
    267400        }
     
    278411            data {
    279412                set trig_mux 0
    280                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     413                my send_data [usb::convert ${mux_addr}[my mux]]
    281414            }
    282415            uwt1 {
    283416                set trig_mux 1
    284                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     417                my send_data [usb::convert ${mux_addr}[my mux]]
    285418            }
    286419            uwt2 {
    287420                set trig_mux 2
    288                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     421                my send_data [usb::convert ${mux_addr}[my mux]]
    289422            }
    290423            uwt3 {
    291424                set trig_mux 3
    292                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     425                my send_data [usb::convert ${mux_addr}[my mux]]
    293426            }
    294427            base {
    295428                set trig_mux 4
    296                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     429                my send_data [usb::convert ${mux_addr}[my mux]]
    297430            }
    298431        }
     
    448581        my instvar config auto thrs thrs_val base base_typ base_val
    449582
    450         my set restart_command [usb::convert 0001001${number}00000000]
    451         my set acquire_command [usb::convert 0002001${number}00000000]
     583        my set restart_command [usb::convert 0001001${number}]
     584        my set acquire_command [usb::convert 0002001${number}]
    452585
    453586        # create a graph widget and show a grid
     
    510643        grid ${config} -row 0 -column 1
    511644
     645        grid rowconfigure ${master} 0 -weight 1
     646        grid columnconfigure ${master} 0 -weight 1
     647        grid columnconfigure ${master} 1 -weight 0 -minsize 80
     648
    512649        # enable zooming
    513650        Blt_ZoomStack $graph
     
    555692        if {$peak} {
    556693            set peak_mux 1
    557             my send_data [usb::convert ${mux_addr}[my mux]00000000]
     694            my send_data [usb::convert ${mux_addr}[my mux]]
    558695        } else {
    559696            set peak_mux 0
    560             my send_data [usb::convert ${mux_addr}[my mux]00000000]
     697            my send_data [usb::convert ${mux_addr}[my mux]]
    561698        }
    562699    }
     
    575712        } else {
    576713            ${config}.thrs_field configure -state disabled
    577             my send_data [usb::convert ${val_addr}000000000000]
     714            my send_data [usb::convert ${val_addr}0000]
    578715        }
    579716    }
     
    587724        set value [format %04x $thrs_val]
    588725
    589         my send_data [usb::convert ${val_addr}${value}00000000]
     726        my send_data [usb::convert ${val_addr}${value}]
    590727    }
    591728
     
    607744            ${config}.base_field configure -state disabled
    608745            set base_mux 0
    609             my send_data [usb::convert ${mux_addr}[my mux]00000000${val_addr}000000000000]
     746            my send_data [usb::convert ${mux_addr}[my mux]${val_addr}0000]
    610747        }
    611748    }
     
    624761                ${config}.base_field configure -state disabled
    625762                set base_mux 1
    626                 my send_data [usb::convert ${mux_addr}[my mux]00000000]
     763                my send_data [usb::convert ${mux_addr}[my mux]]
    627764            }
    628765            const {
    629766                ${config}.base_field configure -state normal
    630767                set base_mux 0
    631                 my send_data [usb::convert ${mux_addr}[my mux]00000000${val_addr}${value}00000000]
     768                my send_data [usb::convert ${mux_addr}[my mux]${val_addr}${value}]
    632769            }
    633770        }
     
    642779        set value [format %04x $base_val]
    643780
    644         my send_data [usb::convert ${val_addr}${value}00000000]
     781        my send_data [usb::convert ${val_addr}${value}]
    645782    }
    646783
     
    725862    namespace export HstDisplay
    726863    namespace export OscDisplay
     864    namespace export CfgDisplay
    727865}
    728866
    729 set notebook [::blt::tabnotebook .notebook -side bottom]
     867set notebook [::blt::tabnotebook .notebook -selectforeground black -side bottom]
    730868
    731869pack $notebook -expand 1 -fill both
    732870
    733 set window [frame ${notebook}.hst_2]
    734 $notebook insert end -text "Histogram" -window $window -fill both
    735 ::mca::HstDisplay hst_2 -number 2 -master $window
    736 
    737 grid rowconfigure $window 0 -weight 1
    738 grid columnconfigure $window 0 -weight 1
    739 grid columnconfigure $window 1 -weight 0 -minsize 80
    740 
    741 set window [frame ${notebook}.osc_2]
    742 $notebook insert end -text "Pulse shape" -window $window -fill both
    743 ::mca::OscDisplay osc_2 -number 2 -master $window
    744 
    745 grid rowconfigure $window 0 -weight 1
    746 grid columnconfigure $window 0 -weight 1
    747 grid columnconfigure $window 1 -weight 0 -minsize 80
     871foreach i {0 1 2} {
     872    set channel [expr $i + 1]
     873
     874    set window [frame ${notebook}.hst_$i]
     875    $notebook insert end -text "Histogram $channel" -window $window -fill both
     876    ::mca::HstDisplay hst_$i -number $i -master $window
     877
     878    set window [frame ${notebook}.osc_$i]
     879    $notebook insert end -text "Pulse shape $channel" -window $window -fill both
     880    ::mca::OscDisplay osc_$i -number $i -master $window
     881}
     882
     883set window [frame ${notebook}.cfg]
     884$notebook insert end -text "Configuration" -window $window -fill both
     885::mca::CfgDisplay cfg -master $window
    748886
    749887set usb_handle {}
     
    755893}
    756894
    757 hst_2 restart
    758 osc_2 restart
    759 
    760 hst_2 start
    761 osc_2 start
    762 
    763 # configure polarity
    764 # set polarity_command [usb::convert 000A011100000000]
    765 set polarity_command [usb::convert 000A001100000000]
    766 if {[catch {$usb_handle writeRaw $polarity_command} result]} {
     895# cfg reset
     896set reset_command [usb::convert 00000000]
     897if {[catch {$usb_handle writeRaw $reset_command} result]} {
    767898    puts {Error during write}
    768899    puts $result
    769900}
    770901
    771 hst_2 restart
    772 osc_2 restart
     902cfg start
     903
     904foreach i {0 1 2} {
     905    hst_$i start
     906    osc_$i start
     907
     908    hst_$i restart
     909    osc_$i restart
     910}
Note: See TracChangeset for help on using the changeset viewer.