View Full Version : Add-on to ViewPort 4.2.5 -- expands 'watch' capability of ViewPort

Bob Anderson
12-22-2009, 03:26 AM
ViewPort 4.2.5 is required.· This program will be most useful to experienced users of ViewPort.· The built-in "watch" that ViewPort provides is usually adequate.· But if one wants to "pretty print" the "watch" and format variables as binary or hex of float objects, then this add-on should be considered.· What follows is a major extract from the built-in "help file"...

This program is an extension to the basic "watch shared variable" capabilities of ViewPort.·It executes script statements that can deal with arrays and Spin floats and show variables in the following formats:

·· int· uint· float· binary· hex· bit

There is a full expression evaluator that accepts the following operators:

·· *· /· div· mod· &· |· ^· >>· <<· ~·
================================================== ====================================

Script statements available for "watching" shared variables. These are normally placed in the "Main script" text panel.

·· showInt·· ( "<label>" , <expr> )· ; Show expr as signed·· 32 bit integer
·· showUint· ( "<label>" , <expr> )· ; Show expr as unsigned 32 bit integer
·· showHex·· ( "<label>" , <expr> )· ; Show expr as $00fd_0acb
·· showBinary( "<label>" , <expr> )· ; Show expr as %1010_1000_0000_0000_1100_0011_0000_0001
·· showFloat ( "<label>" , <expr> )· ; Show expr as 3.81
·· showBit·· ( "<label>" , <expr> , <bit> )· ; Show value of bit <bit> in <expr>
·· showStr·· ( "<label>" )·········· ; Show <label>
·· :<name> = <expr>················· ; Set a local variable (this is "quiet" - no output)

There can be more than one script statement on a line, so the following is possible...

·· ; In the following line, a local variable ( :I ) is used to cycle from 0..9
·· showHex("out array = ",out[:I])· :I=(:I + 1) mod 10

If the above script is repeatedly run by clicking the "Run once" button, it would examine out[0]..out[9] in sequence and produce lines in the "Watch Window" of the form:

·· out array = [· 8] $00dd_87a0

================================================== ====================================

General notes...

·· The "Available ViewPort variable names..." text box shows arrays in the following manner...

····· io[366:2]· This is interpreted as io is a type 2 array with 366 elements -- io[0..365]

·· If a ViewPort shared variable is actually a Spin float, you must refer to that
·· variable using the· <name>.float· form to see it in float form.

·· While shared arrays can be examined, only the first element can be remotely set/modified.

·· <name> must start with a alpha character and contain only alpha characters and numbers.

·· <label> is any string that does not contain "

·· All names are case-sensitive.

·· A semi-colon (;) starts a comment field.

·· Local variables always start with a colon ( : ) and are automatically
·· initialized to zero.

·· <expr> can be arbitrarily complex.· Parentheses should be used to control
·· operator precedences.

================================================== ====================================

Examples of <expr> ...

·· ch0·· ; This will be the most common expression - references a ViewPort variable
·· io[50] ; Item 50 from the io array
·· pi.float ; A ViewPort variable that is a IEEE float
·· bias ^ %1001· ; Bitwise xor bias with $9
·· bias & %1001· ; Bitwise and bias with $9
·· bias | %1001· ; Bitwise or bias with $9
·· ((v1.float + v2.float + v3.float)/3) * :scaleFactor ; Average 3 vars and scale
·· spi << 4· ; Shift spi left 4 bits
·· (counter + index) mod 12· ; Add counter to index and take the result modulo 12
·· pi.float div 2· ; Integer divide by 2

================================================== ====================================

Below are the script statements that be used to set/modifyViewPort shared variables.· These are normally placed in the "Set
variables" text panel.

·· <name>.float = <expr>············ ; Set a ViewPort shared variable to an IEEE float
·· <name>.int·· = <expr>············ ; Set a ViewPort shared variable to a 32 bit long
·· <name>······ = <expr>············ ; Set a ViewPort shared variable to a 32 bit long
·· :<name>····· = <expr>············ ; Set a "local" variable (both ints and floats accepted)

All of the above statements are "quiet" in that they do not directly produce output in the "Watch Window".· Of course, if there is a script running that displays the affected variable, the result will be seen.

Clicking a line in the script window will automatically fill in the line number text box that is to the right of the "Execute line:" button.

Note that it is not possible to have a statement of the form...

·· io[23] = %11110111_11001100

This is a current limitation of the DDE interface that ViewPort exposes.

Add-on to ViewPort - expanded "watch" capabilies·· (link below)

Post Edited (Bob Anderson) : 12/21/2009 8:31:41 PM GMT

12-23-2009, 02:00 AM
Another very cool add-on to ViewPort- thanks Bob!
I've started playing with it and love how easy it is to "script" output which uses expressions to combine multiple Propeller variables and formats them nicely.

Co-author of the official Propeller Guide- available at Amazon (http://www.amazon.com/Programming-Customizing-Multicore-Propeller-Parallax/dp/0071664505)
Developer of ViewPort (http://hannoware.com/viewport), the premier visual debugger for the Propeller (read the review here (http://www.parallax.com/Portals/0/Downloads/docs/article/ROBOT_ViewPort.pdf), thread here (http://forums.parallax.com/showthread.php?p=760083)),
12Blocks (http://12blocks.com), the block-based programming environment (thread here (http://forums.parallax.com/showthread.php?p=819680))
and PropScope (http://hannoware.com/propscope), the multi-function USB oscilloscope/function generator/logic analyzer