Changeset 170 for trunk/MultiChannelUSB/UserInterface.tcl
- Timestamp:
- Oct 18, 2012, 5:52:36 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MultiChannelUSB/UserInterface.tcl
r169 r170 116 116 # ------------------------------------------------------------------------- 117 117 118 UsbController instproc init {} { 119 120 my set ignore false 121 122 next 123 } 124 125 # ------------------------------------------------------------------------- 126 118 127 UsbController instproc usbConnect {} { 119 my instvar handle 128 my instvar handle ignore 120 129 121 130 puts usbConnect … … 125 134 unset handle 126 135 } 127 if {0} { 128 while {[catch {usb::connect 0x09FB 0x6001 1 1 0} result]} { 129 set answer [tk_messageBox -icon error -type retrycancel \ 130 -message {Cannot access USB device} -detail $result] 131 # puts $result 132 if {[string equal $answer cancel]} exit 133 } 134 135 set handle $result 136 137 } 136 if {!$ignore} { 137 while {[catch {usb::connect 0x09FB 0x6001 1 1 0} result]} { 138 set answer [tk_messageBox -icon error -type abortretryignore \ 139 -message {Cannot access USB device} -detail $result] 140 if {[string equal $answer abort]} exit 141 if {[string equal $answer ignore]} { 142 set ignore true 143 return 144 } 145 } 146 147 set handle $result 148 149 } 138 150 } 139 151 … … 141 153 142 154 UsbController instproc usbHandle {} { 143 my instvar handle 155 my instvar handle ignore 144 156 145 157 if {[my exists handle]} { 146 158 return $handle 147 } else {159 } elseif {!$ignore} { 148 160 my usbConnect 149 161 } … … 458 470 my set rate_val(mean) 0.0 459 471 472 my set date_val(start) {} 473 my set date_val(stop) {} 474 460 475 ${config}.chan_frame.entr_value configure -text 0.0 461 476 … … 722 737 } 723 738 724 set val_addr [format %02x[expr {7 + ${number}}]]739 set val_addr [format {%02x} [expr {7 + ${number}}]] 725 740 726 741 if {$thrs} { 727 742 ${config}.thrs_field configure -state normal 728 set value [format %03x$thrs_val]743 set value [format {%03x} $thrs_val] 729 744 } else { 730 745 ${config}.thrs_field configure -state disabled … … 803 818 my instvar controller number cntr_val 804 819 805 set word0 [format %08x[expr {${cntr_val} & 0xFFFFFFFF}]]806 set word1 [format %08x[expr {${cntr_val} >> 32}]]807 808 set prefix [format %x[expr {5 + ${number}}]]820 set word0 [format {%08x} [expr {${cntr_val} & 0xFFFFFFFF}]] 821 set word1 [format {%08x} [expr {${cntr_val} >> 32}]] 822 823 set prefix [format {%x} [expr {5 + ${number}}]] 809 824 810 825 set command {} … … 818 833 819 834 # load counter value 820 # set val_addr [format %02x[expr {12 + ${number}}]]835 # set val_addr [format {%02x} [expr {12 + ${number}}]] 821 836 # $controller usbCmd 000200${val_addr}00040001000200${val_addr}00040000 822 837 } … … 825 840 826 841 HstDisplay instproc cntr_reset {} { 827 my instvar controller config number after_handle828 my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old rate_val 842 my instvar controller config number 843 my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old rate_val date_val 829 844 830 845 my cntr_stop 831 846 832 set value [format %04x[expr {1 << (5 + ${number})}]]847 set value [format {%04x} [expr {1 << (5 + ${number})}]] 833 848 $controller usbCmd 000200000004${value}0002000000040000 834 849 … … 843 858 set rate_val(mean) 0.0 844 859 ${config}.chan_frame.entr_value configure -text 0.0 845 860 861 set date_val(start) {} 862 set date_val(stop) {} 863 846 864 my acquire 847 865 … … 869 887 my instvar config 870 888 my instvar cntr_h cntr_m cntr_s 871 my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old 889 my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old date_val 872 890 873 891 set h $cntr_h … … 883 901 if {[string equal $s {}]} { 884 902 set s 0 903 } 904 if {[string equal $date_val(start) {}]} { 905 set date_val(start) [clock format [clock seconds] -format {%d/%m/%Y %H:%M:%S}] 885 906 } 886 907 … … 920 941 921 942 HstDisplay instproc cntr_resume {} { 922 my instvar controller config number auto 923 924 set val_addr [format %02x[expr {13 + ${number}}]]943 my instvar controller config number auto after 944 945 set val_addr [format {%02x} [expr {13 + ${number}}]] 925 946 926 947 ${config}.start configure -text Pause -command [myproc cntr_pause] … … 931 952 set auto 1 932 953 933 after 100 [myproc acquire_loop]954 set after [after 100 [myproc acquire_loop]] 934 955 } 935 956 … … 937 958 938 959 HstDisplay instproc cntr_stop {} { 939 my instvar controller config number auto 940 941 set val_addr [format %02x [expr {13 + ${number}}]] 960 my instvar controller config number auto after date_val 961 962 set date_val(stop) [clock format [clock seconds] -format {%d/%m/%Y %H:%M:%S}] 963 964 set val_addr [format {%02x} [expr {13 + ${number}}]] 942 965 943 966 $controller usbCmd 000200${val_addr}00040000 944 967 945 968 set auto 0 969 970 after cancel $after 946 971 } 947 972 … … 956 981 957 982 HstDisplay instproc acquire_loop {} { 958 my instvar cntr_val auto 983 my instvar cntr_val auto after 959 984 960 985 my acquire … … 964 989 my cntr_ready 965 990 } elseif {$auto} { 966 after 1000 [myproc acquire_loop]991 set after [after 1000 [myproc acquire_loop]] 967 992 } 968 993 } … … 1006 1031 HstDisplay instproc save_data {data} { 1007 1032 my instvar number 1033 my instvar yvec_old rate_val date_val 1008 1034 1009 1035 set types { … … 1012 1038 } 1013 1039 1014 set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]1040 set stamp [clock format [clock seconds] -format {%Y%m%d_%H%M%S}] 1015 1041 set fname spectrum_[expr {$number + 1}]_${stamp}.dat 1016 1042 … … 1022 1048 set x [catch { 1023 1049 set fid [open $fname w+] 1050 puts $fid "info {" 1051 puts $fid "start date: $date_val(start)" 1052 if {[string equal $date_val(stop) {}]} { 1053 puts $fid "stop date: [clock format [clock seconds] -format {%d/%m/%Y %H:%M:%S}]" 1054 } else { 1055 puts $fid "stop date: $date_val(stop)" 1056 } 1057 puts $fid "average rate: [format {%.2e} $rate_val(mean)] counts/s" 1058 puts $fid "total counts: $yvec_old" 1059 puts $fid "}" 1060 puts $fid "data {" 1024 1061 puts $fid $data 1062 puts $fid "}" 1025 1063 close $fid 1026 1064 }] … … 1050 1088 set x [catch { 1051 1089 set fid [open $fname r+] 1052 fconfigure $fid -translation binary -encoding binary1053 [myvar yvec] set [split [read $fid] \n]1090 set content [read $fid 131072] 1091 set yvec_new [split [dict get $content data] \n] 1054 1092 close $fid 1055 1093 }] … … 1061 1099 tk_messageBox -icon info \ 1062 1100 -message "File \"$fname\" read successfully" 1101 my cntr_reset 1102 [myvar yvec] set $yvec_new 1063 1103 } 1064 1104 } … … 1285 1325 1286 1326 set number 0 1287 set val_addr [format %02x[expr {9 + ${number}}]]1327 set val_addr [format {%02x} [expr {9 + ${number}}]] 1288 1328 1289 1329 if {$thrs} { 1290 1330 ${config}.thrs_field configure -state normal 1291 set value [format %03x$thrs_val]1331 set value [format {%03x} $thrs_val] 1292 1332 } else { 1293 1333 ${config}.thrs_field configure -state disabled … … 1517 1557 } 1518 1558 1519 set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]1559 set stamp [clock format [clock seconds] -format {%Y%m%d_%H%M%S}] 1520 1560 set fname counts_${stamp}.dat 1521 1561 … … 1839 1879 if {$thrs} { 1840 1880 ${config}.thrs_field configure -state normal 1841 set value [format %03x$thrs_val]1881 set value [format {%03x} $thrs_val] 1842 1882 } else { 1843 1883 ${config}.thrs_field configure -state disabled … … 1990 2030 } 1991 2031 1992 set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]2032 set stamp [clock format [clock seconds] -format {%Y%m%d_%H%M%S}] 1993 2033 set fname oscillogram_${stamp}.dat 1994 2034
Note:
See TracChangeset
for help on using the changeset viewer.