diff options
Diffstat (limited to 'lib/utilities/rs232debugger.tcl')
-rw-r--r--[-rwxr-xr-x] | lib/utilities/rs232debugger.tcl | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/lib/utilities/rs232debugger.tcl b/lib/utilities/rs232debugger.tcl index dacb8d5..af2354b 100755..100644 --- a/lib/utilities/rs232debugger.tcl +++ b/lib/utilities/rs232debugger.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _RS232DEBUGGER_TCL ] } { +set _RS232DEBUGGER_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION @@ -31,29 +36,34 @@ class RS232Debugger { ## COMMON common count 0 ;# Int: Counter of class instances # Font: Big bold font - common bold_font [font create \ - -family {helvetica} \ - -size -12 -weight {bold} \ + common bold_font [font create \ + -family {helvetica} \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight {bold} \ ] # Font: Tiny normal font - common tiny_font [font create \ - -family {helvetica} \ - -size -9 -weight {normal} \ + common tiny_font [font create \ + -family {helvetica} \ + -size [expr {int(-9 * $::font_size_factor)}] \ + -weight {normal} \ ] # Font: Tiny bold font - common tiny_font_bold [font create \ - -family {helvetica} \ - -size -9 -weight {bold} \ + common tiny_font_bold [font create \ + -family {helvetica} \ + -size [expr {int(-9 * $::font_size_factor)}] \ + -weight {bold} \ ] # Font: Normal font - common normal_font [font create \ - -family {helvetica} \ - -size -11 -weight {normal} \ + common normal_font [font create \ + -family {helvetica} \ + -size [expr {int(-11 * $::font_size_factor)}] \ + -weight {normal} \ ] # Font: Also normal font, but a bit larger - common big_font [font create \ - -family {helvetica} \ - -size -12 -weight {normal} \ + common big_font [font create \ + -family {helvetica} \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight {normal} \ ] # Int: Pool interval for selected RS232 interface common POOL_INTERVAL 50 ;# mili-seconds @@ -92,13 +102,13 @@ class RS232Debugger { private variable clear_selected_rec_button ;# Widget: Button "Clear selected" in section "Receive" private variable receive_here_button ;# Widget: Button "Receive here" private variable clear_selected_snd_button ;# Widget: Button "Clear selected" in section "Send" - private variable receive_hexeditor ;# Object: Hexeditor intented for reception - private variable send_hexeditor ;# Object: Hexeditor intented for sending + private variable receive_hexeditor ;# Object: Hex editor intented for reception + private variable send_hexeditor ;# Object: Hex editor intented for sending private variable pool_timer {} ;# Object: Pool timer object private variable channel {} ;# Channel: Opened device file private variable port_filename {} ;# String: Device file name - private variable reception_address 0 ;# Int: Address in reception hexeditor where received data are stored + private variable reception_address 0 ;# Int: Address in reception hex editor where received data are stored private variable reception_enabled 1 ;# Bool: Reception enabled private variable prev_tty_status ;# List: Previous TTY status (before any action performed by this code) @@ -130,7 +140,7 @@ class RS232Debugger { -foreground {#000000} \ -background {#DDDDDD} ttk::style map RS232Debugger_SignalAllDefault.TButton \ - -background [list active {#EEEEEE}] + -background [list active ${::COMMON_BG_COLOR}] ttk::style configure RS232Debugger_SignalTxDTrue.TButton \ -background {#AAFFAA} \ @@ -150,7 +160,7 @@ class RS232Debugger { -background {#DDDDDD} \ -foreground {#000000} ttk::style map RS232Debugger_SignalTxDFalse.TButton \ - -background [list active {#EEEEEE}] \ + -background [list active ${::COMMON_BG_COLOR}] \ -foreground [list active {#000000}] ttk::style configure RS232Debugger_SignalNormalFalse.TButton \ @@ -216,7 +226,7 @@ class RS232Debugger { create_gui set_tty_controls_state 0 - # Restore data displayed in hexeditors + # Restore data displayed in hex editors foreach idx {5 6} hexedit [list $receive_hexeditor $send_hexeditor] { set data [lindex $config_list $idx] if {![llength $data]} { @@ -228,7 +238,7 @@ class RS232Debugger { } } - # restore addresses of current cells in hexeditors + # restore addresses of current cells in hex editors $receive_hexeditor setCurrentCell [lindex $config_list 7] $send_hexeditor setCurrentCell [lindex $config_list 8] } @@ -249,7 +259,7 @@ class RS232Debugger { # Cancel pool timer catch {after cancel $pool_timer} - # Close opended channel + # Close opened channel if {$channel !={}} { catch {fileevent $channel readable {}} catch {close $channel} @@ -263,7 +273,7 @@ class RS232Debugger { # @return void private method create_gui {} { # Create window - set win [toplevel .rs232debugger$count -class [mc "RS232 Debugger"] -bg {#EEEEEE}] + set win [toplevel .rs232debugger$count -class [mc "RS232 Debugger"] -bg ${::COMMON_BG_COLOR}] # Create status bar set status_bar_label [label $win.status_bar_label -justify left -pady 0 -anchor w] @@ -381,13 +391,13 @@ class RS232Debugger { $connector_canvas bind gnd_wire <Leave> "$this wire_leave gnd" ## Write texts - $connector_canvas create text \ - [expr {$x + 10}] [expr {$y - 25}] \ - -anchor n -justify left \ + $connector_canvas create text \ + [expr {$x + 10}] [expr {$y - 30}] \ + -anchor n -justify left \ -font $big_font -text [mc "RS-232\nDTE"] - $connector_canvas create text \ + $connector_canvas create text \ [expr {$x + 10}] [expr {$y + 100}] \ - -anchor n -justify left \ + -anchor n -justify left \ -font $big_font -text [mc "DE-9"] } @@ -510,7 +520,7 @@ class RS232Debugger { bind $dtr_button <Enter> "$this wire_enter dtr" bind $dtr_button <Leave> "$this wire_leave dtr" $connector_canvas create window \ - [expr {$x + 100}] [expr {$y + 95}] \ + [expr {$x + 100}] [expr {$y + 90}] \ -anchor center -window $dtr_button $connector_canvas create line \ @@ -539,7 +549,7 @@ class RS232Debugger { bind $rts_button <Enter> "$this wire_enter rts" bind $rts_button <Leave> "$this wire_leave rts" $connector_canvas create window \ - [expr {$x + 135}] [expr {$y + 95}] \ + [expr {$x + 135}] [expr {$y + 90}] \ -anchor center -window $rts_button $connector_canvas create line \ @@ -568,7 +578,7 @@ class RS232Debugger { bind $break_button <Enter> "$this wire_enter txd" bind $break_button <Leave> "$this wire_leave txd" $connector_canvas create window \ - [expr {$x + 180}] [expr {$y + 95}] \ + [expr {$x + 180}] [expr {$y + 90}] \ -anchor center -window $break_button $connector_canvas create line \ @@ -617,10 +627,10 @@ class RS232Debugger { # Create canvas widget set connector_canvas [canvas $target_frame.canvas \ - -width 280 -height 150 -bg {#EEEEEE} \ + -width 280 -height 150 -bg ${::COMMON_BG_COLOR} \ -bd 0 -relief flat -highlightthickness 0 \ ] - pack $connector_canvas -side left -anchor sw + pack $connector_canvas -side left -padx 5 ;#-anchor sw # Fill in the connector canvas draw_connector 20 30 @@ -642,7 +652,7 @@ class RS232Debugger { -image ::ICONS::16::configure \ ] \ ] - pack $conf_frame -side left -anchor nw + pack $conf_frame -side right -anchor nw -padx 5 # - Physical port grid [label $conf_frame.port_lbl \ -text [mc "Physical port"] \ @@ -687,13 +697,16 @@ class RS232Debugger { -text [mc "Parity"] \ ] -row 4 -column 1 -sticky w set parity_cb [ttk::combobox $conf_frame.parity_cb \ - -values {none odd even mark space} \ -state readonly \ -width 6 \ -exportselection 0 \ + -values [list [mc "none"] \ + [mc "odd"] [mc "even"] \ + [mc "mark"] [mc "space"] \ + ] ] bind $parity_cb <<ComboboxSelected>> \ - "$this change_port_config p \[$conf_frame.parity_cb get\]" + "$this change_port_config p \[$conf_frame.parity_cb current\]" set_status_tip $parity_cb [mc "Parity"] grid $parity_cb -row 4 -column 2 -sticky w $conf_frame.parity_cb current [lsearch {n o e m s} $parity_conf] @@ -852,7 +865,7 @@ class RS232Debugger { if {[file exists $content]} { if {$port_filename == $content} { $port_combobox configure -style RS232Debugger_FileInUse.TCombobox - } { + } else { $port_combobox configure -style RS232Debugger_FileFound.TCombobox } # Not exiting file @@ -924,7 +937,7 @@ class RS232Debugger { -message \"[mc {Unable to open the specified file}]\n\n\${reason}\"" # -> Success } else { - # Try to configure opened channel acording to specified parameters + # Try to configure opened channel according to specified parameters if {[catch { fconfigure $channel \ -handshake none \ @@ -964,24 +977,7 @@ class RS232Debugger { set baud_conf $value } {p} { ;# Parity bit - switch -- $value { - {none} { - set value {n} - } - {odd} { - set value {o} - } - {even} { - set value {e} - } - {mark} { - set value {m} - } - {space} { - set value {s} - } - } - set parity_conf $value + set parity_conf [lindex {n o e m s} $value] } {d} { ;# Data bits set data_conf $value @@ -1004,31 +1000,31 @@ class RS232Debugger { -parent $win \ -type ok \ -icon error \ - -title [mc "Uknown failure"] \ + -title [mc "Unknown failure"] \ -message [mc "Unable to change port configuration"] } } - ## Handle selection event in hexeditor + ## Handle selection event in hex editor # @parm Char editor - Editor ID # @parm Bool anything_selected - 1 == anything selected; 0 == Nothing selected # @return void public method hexeditor_selection {editor anything_selected} { if {$anything_selected} { set state {normal} - } { + } else { set state {disabled} } if {$editor == {s}} { $send_selected_button configure -state $state $clear_selected_snd_button configure -state $state - } { + } else { $clear_selected_rec_button configure -state $state } } - ## Clear selected data in send hexeditor + ## Clear selected data in send hex editor # @return void public method clear_selected_snd {} { # Get range of text indexes determinating the selection @@ -1142,7 +1138,7 @@ class RS232Debugger { if {[winfo exists .data_lost_dialog]} { return } - set dialog [toplevel .data_lost_dialog -class [mc "Error message"] -bg {#EEEEEE}] + set dialog [toplevel .data_lost_dialog -class [mc "Error message"] -bg ${::COMMON_BG_COLOR}] pack [label $dialog.label \ -font $bold_font -compound left -padx 5 \ @@ -1181,7 +1177,7 @@ class RS232Debugger { tkwait window $dialog } - ## Clear selected data in receive hexeditor + ## Clear selected data in receive hex editor # @return void public method clear_selected_rec {} { set rangeofselection [$receive_hexeditor getRangeOfSelection] @@ -1200,7 +1196,7 @@ class RS232Debugger { ## Enable/Disable reception # @return void public method reception_ena_dis {} { - set reception_enabled [subst "\$::RS232Debugger::enable_reception${obj_idx}"] + set reception_enabled [subst -nocommands "\$::RS232Debugger::enable_reception${obj_idx}"] } ## Read TTY status from the interface and update GUI accordingly @@ -1212,15 +1208,15 @@ class RS232Debugger { # Read TTY status if {[catch { set ttystatus [fconfigure $channel -ttystatus] - }]} { + }]} then { unknown_port_io_error return } - # Check whether any change occured + # Check whether any change occurred if {$prev_tty_status(0) == $ttystatus} { return - } { + } else { set prev_tty_status(0) $ttystatus } @@ -1256,7 +1252,7 @@ class RS232Debugger { foreach signal {cts dsr ri dcd} value $args { if {$prev_tty_status($signal) == $value} { continue - } { + } else { set prev_tty_status($signal) $value } @@ -1280,7 +1276,7 @@ class RS232Debugger { } } - ## Report an unknown IO error occured on the interface + ## Report an unknown IO error occurred on the interface # Plus disable reception and safely terminate connection # @return void private method unknown_port_io_error {} { @@ -1326,7 +1322,7 @@ class RS232Debugger { set state {normal} set state2 {readonly} set_tty_controls_to_defaults - } { + } else { set state {disabled} set state2 {disabled} set_tty_controls_to_unknown_state @@ -1382,33 +1378,33 @@ class RS232Debugger { switch -- $value { 0 { ;# Loical 0 if {$wire == {break}} { - [subst "\${${wire}_button}"] configure -text {Break} \ + [subst -nocommands "\${${wire}_button}"] configure -text {Break} \ -style RS232Debugger_SignalTxDFalse.TButton $connector_canvas itemconfigure txd_wire -fill {#0000FF} - } { - [subst "\${${wire}_button}"] configure -text {1} \ + } else { + [subst -nocommands "\${${wire}_button}"] configure -text {1} \ -style RS232Debugger_SignalNormalFalse.TButton $connector_canvas itemconfigure ${wire}_wire -fill {#FF0000} } } 1 { ;# Logical 1 if {$wire == {break}} { - [subst "\${${wire}_button}"] configure -text {BREAK} \ + [subst -nocommands "\${${wire}_button}"] configure -text {BREAK} \ -style RS232Debugger_SignalTxDTrue.TButton $connector_canvas itemconfigure txd_wire -fill {#00FF00} - } { - [subst "\${${wire}_button}"] configure -text {0} \ + } else { + [subst -nocommands "\${${wire}_button}"] configure -text {0} \ -style RS232Debugger_SignalNormalTrue.TButton $connector_canvas itemconfigure ${wire}_wire -fill {#00FF00} } } default { ;# Unknown state if {$wire == {break}} { - [subst "\${${wire}_button}"] configure -text {Break} \ + [subst -nocommands "\${${wire}_button}"] configure -text {Break} \ -style RS232Debugger_SignalAllDefault.TButton $connector_canvas itemconfigure txd_wire -fill {#0000FF} - } { - [subst "\${${wire}_button}"] configure -text {-} \ + } else { + [subst -nocommands "\${${wire}_button}"] configure -text {-} \ -style RS232Debugger_SignalAllDefault.TButton $connector_canvas itemconfigure ${wire}_wire -fill {#888888} } @@ -1418,7 +1414,7 @@ class RS232Debugger { if {[catch { fconfigure $channel -ttycontrol [list $wire $value] - }]} { + }]} then { unknown_port_io_error return } @@ -1452,9 +1448,13 @@ class RS232Debugger { # @return void public method wire_leave {wire} { $connector_canvas itemconfigure ${wire}_wire -width 1 - $connector_canvas itemconfigure ${wire}_pin -fill {#EEEEEE} + $connector_canvas itemconfigure ${wire}_pin -fill ${::COMMON_BG_COLOR} $connector_canvas itemconfigure ${wire}_num -font $tiny_font $status_bar_label configure -text {} } } + +# >>> File inclusion guard +} +# <<< File inclusion guard |