My Account
Shopping Cart 0 item(s)
View Cart
Facebook Google Plus LinkedIn

Viewing Message Traffic

Posted by Peter Hiscocks on 9/6/2014 to Resources
To begin with, let's assume you want to tinker with the behaviour of the code. Maybe you'd like to change the colour of some feature, or the text font -- or add some completely new feature.

In many cases, that's not terribly difficult to do. First let me clarify the structure of our software.

The software is written in the Tcl/Tk (Tcl) language. (You can find an introduction to Tcl in our application note 'Hello Button',) Tcl is an interpreted language, that is, an interpreter runs on your computer and then reads and acts on the instructions in the Tcl source code.  If you download and install our software, then you will have an executable file for your operating system (Windows, Linux or Mac) plus a series of .tcl source code files in the source code directory.  There is nothing magic about the .tcl source code files - they are pure text format and can be loaded and edited in any text editor.

The executable, which is specific to each operating system, contains any needed library files that might be called.

So: to modify the code, identify where the installation put the files. Then look in the Source subdirectory.  Find the .tcl file that contains the material of interest.  The first file to be executed is always called 'main.tcl', and it calls ('sources') the other files.  Make a backup copy of the file you want to modify, giving the file name some other extension, such as .original.  Then you can simply restore the original if the modifications go badly.
Now, whatever you change in the .tcl file will appear in the behaviour of the program when you run it.  That's it.  No compiling, no linking, no libraries to worry about.

If you are writing code to control one of our instruments - in Visual Basic, or Python or MatLab, for example - it can be really useful to see the message traffic to the hardware.

Turn on message monitoring, execute the relevant commands from the GUI (Graphical User Interface) and watch the messages that are sent to the hardware.  Then construct your program to send those same messages.

The Tcl/Tk language of the GUI comes with the capability of a *console*, a terminal screen where print statements are displayed. Under the Windows operating system, the console is enabled in the View menu as 'Debug Console'. In Linux, the console display appears in the terminal where the program was launched.

You will probably also want to raise the 'debug level' to increase the detail in these messages.  To do so, go to the directory that contains the instrument source code.  Open the file 'main.tcl' in a text editor.  Find the line that says 'set debugLevel 0'.  Change that to 'set debugLevel 1'.  The effect of this is to have all commands that are sent to the hardware echoed to the console display.  (It's normally set to zero (ie, disabled) because there is a slight performance penalty when printing.) Since commands are ASCII strings, they display intelligibly.  We document those commands in the manual for the instrument.

One of the best ways to debug a program, or understand what it's doing, is to add your own print statements to the source code. In Tcl/Tk, the print command is 'puts' (for put string). The value of a variable is preceeded by a dollar sign. So in the file usbSerial.tcl, for example, we find the line:

if $::debugLevel { puts $command }

In other words, if the debugLevel is non-zero, print the variable 'command'.  You can add your own 'puts' commands to the code.  (As always, make a copy of the original so you can back out of changes.)

Share |

 Technical Papers

 The Single Channel Oscilloscope
 Curing Circuit Oscillation
 Testing a Selenium Rectifier
 Yes, we test IGBTs
 Negative Tracking Power Supply

 September 2017
 October 2016
 June 2016
 March 2016
 January 2016
 August 2015
 July 2015
 May 2015
 February 2015
 January 2015
 October 2014
 September 2014
 June 2014
 March 2014
 February 2014
 September 2013
 July 2013
 April 2012
 February 2012
 January 2012
 October 2011
 September 2011
 June 2011
 March 2011
 January 2011
 December 2010
 October 2010
 September 2010
 May 2010
 April 2010
 December 2009
 November 2009
 April 2009
 March 2009
 December 2008
 October 2008
 September 2008
 June 2008
 May 2008
 March 2008
 February 2008
 September 2007
 August 2007
 July 2007
 June 2007
 October 2006
 September 2006
 July 2006
 May 2006
 March 2006