|
| |
| test
This example provides a general use interface and
demonstrates BS2 code to work with many of its features.
Code is Maroon is
StampPlot Code.
Code in Blue is BS2 formatted code.
Once StampPlot is installed, run the macro either directly by opening, or
save and open.
General Use Macro
 | Links to topics:
|
 | Objects and Names
In the interface, there are a variety of plot object controls which
maybe directly controlled and read from your BS2. This is a
listing of the objects and their names. Names are important
since this how they are addressed.
|
 | General Use
StampPlot has its own instruction set to perform actions, such as
resetting the plot:
!RSET
This instruction can manually be entered in the DEBUG/Immediate window
of StampPlot, be in a text file (macro), or come through the serial
port (or even TCP/IP). For the BS2 to send these strings, the
DEBUG instruction may be used:
DEBUG "!RSET",CR
Note, StampPlot instructions must end with a carriage return.
Any of the controls can be set through:
!POBJ objName=value
or, using BS2 code:
DEBUG "!POBJ objName=", DEC
value,CR
Any of the controls values may be referenced by enclosing the object
name in parenthesis.
!STAT (objName)
DEBUG "!STAT (objName)",CR
In addition to controls, StampPlot has a variety of real
time values it maintains called Macro Value, such as the current time.
!STAT (RTIME)
DEBUG "!STAT (RTIME)",CR
Any of the controls may have their values sent back to the BS2 using
!READ, and accepted by the BS2 using SERIN:
!READ (objName)
DEBUG "!READ (objName)",CR
SERIN 16,84,[DEC x] 'Accept returning data on programming
port at 9600 baud and store in X
You may wish to add a timeout value:
DEBUG "!READ (objName)",CR
SERIN 16,84, 1000. Timeout, [DEC x] 'Accept with 1 second
timeout
Timeout:
Controls have events they respond to, such as a button being clicked,
a gauge reaching a setpoint, or a checkbox being changed.
StampPlot code for an event is set through:
!POBJ objName.C=StampPlot Instructions
DEBUG "!POBJ objName.C=Code",CR
Most controls have update values which sets a value to update the
control whenever a update instruction is called. This allows multiple
controls to be updated without having to explicitly update each.
!POBJ objName.U=Value
DEBUG "!POBJ objName.U=value",CR
DEBUG "!POBJ UPDATE",CR
|
 | Gauges - Value, Ranges, alarms
The gauges may be used to display values, and optionally allow set
points and alarms. The full set of parameters for setting a gauge is:
!POBJ objGauge=[value,min,max,alarm
min, alarm max]
The brackets indicate the parameters are optional.
 | Setting Value:
The general way to set the value of one of gauge 1 is:
!POBJ GA1=value
!POBJ GA1=50
From the BASIC Stamp, we may use code such as:
DEBUG "!POBJ GA1=50",CR
or
DEBUG "!POBJ GA1=", DEC X,CR
A simple program to plot the data and show it in the gauge:
X
VAR Byte
PAUSE 500
DEBUG "!PLOT ON",CR
'Enable plotting
DEBUG "!RSET",CR
'Reset plot
FOR X = 0 to 255
DEBUG DEC X,CR
'plot value
DEBUG "!POBJ GA1=", DEC X,CR
'update gauge 1 value
PAUSE 100
NEXT |
|
 | Setting gauge ranges.
Setting the minimum and maximum ranges may be performed by setting
those parameters. Setting the value may be omitted by leaving it
blank. You may wish to do this in a configuration section of
your code.
!POBJ GA1=,-200,200
DEBUG "!POBJ GA1=-200,200",CR
You will notice 2 red lines on your gauges because of the alarm set points.
|
 | Setting Alarm Levels.
The alarm levels may be set using those parameters.
!POBJ GA1=,,,-150,150
DEBUG "!POBJ GA1=,,,-150,150",CR
Of course, ranges and alarms may be set simultaneously:
!POBJ GA1=,-200,200,-150,150
DEBUG "!POBJ
GA1=,-200,200,-150,-150",CR
|
 | Adding Alarm Code
The alarm levels may be used for visual indication, or to have
some action take place when the level is exceeded. This is performed
by writing code for the gauges event -- a high/low level.
The general means for adding event code is:
!POBJ ObjName.C=StampPlot instructions
Simple code would be to sound an alarm when the levels are
exceeded. This code will play a wav file in the media
directory.
!POBJ GA1.C=~PWAV gbell.wav
DEBUG "!POBJ GA1.C=~PWAV
gbell.wav",CR
If you don't have audio on your computer, you can ding
your bell instead:
DEBUG "!POBJ GA1.C=!BELL",CR
Now, when the gauge is set to a value greater than the alarm, the
wav file will be played sounding an alarm.
Putting it all together:
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR
'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR
'set gauge event code to play bell
DEBUG "!PLOT ON",CR
'Enable plotting
DEBUG "!RSET",CR 'Reset plot
FOR X = 0 to 255
DEBUG DEC X,CR
'plot value
DEBUG "!POBJ GA1=", DEC X,CR
'update gauge 1 value
PAUSE 100
NEXT |
|
|
 | Gauge Labels - Setting.
To set the gauge label, we simply assign it a value. This may be
the parameter being monitored (Temp), or the value (100).
!POBJ GA1L=VALUE
DEBUG "!POBJ GA1L=TEMP",CR
or
DEBUG "!POBJ GA1L=",DEC X,CR
Try adding that line in the loop above.
|
 | Automatically updating the Gauge and Label.
StampPlot has a variety of real time and constant values for access
called Macro Values. These are defined by enclosing them in parenthesis.
For example, when data is plotted using the 10 channels, the values are stored in macro
values AINVAL0-AINVAL9. We can use these values to set automatic
update values to objects so that we do not need to send so much data.
An objects update value is set using:
!POBJ objName.U=value
When a !POBJ UPDATE instruction is issued, all the objects will be
updated with their values.
In our example, the gauge and label may be set for update by the
following:
!POBJ GA1.U=(AINVAL0)
!POBJ GA1L.U=(AINVAL0)
DEBUG "!POBJ GA1.U=(AINVAL0)",CR
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR
After data is sent, they may be updated using:
DEBUG "!POBJ Update",CR
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR
'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR
'set gauge event code to play bell
DEBUG "!POBJ GA1.U=(AINVAL0)",CR
'set update value for gauge 1 to analog value 0
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR
'set gauge 1 label to analog value 0
DEBUG "!PLOT ON",CR
'Enable plotting
DEBUG "!RSET",CR
'Reset plot
FOR X = 0 to 255
DEBUG DEC X,CR
'plot value
DEBUG "!POBJ Update",CR
'update all objects with their update values
PAUSE 100
NEXT |
|
 | Sliders - Ranges, Labels, Using as settings
The sliders objects have a general set string of:
!POBJ objName=value[,min,max]
 | Setting values
A sliders range may be set with:
!POBJ SLD1=value
!POBJ SLD1=0
|
 | Setting the
range
The range of the Slider may be set with:
!POBJ SLD1=,-200,200
DEBUG "!POBJ SLD1=,-200,200",CR
|
 | Using the
Slider to set a gauge setpoint
By setting the code for the slider, one use may be to update the
gauge's upper setpoint. The lower setpoint will be set to below the minimum of the gauge lower range. The value of the
slider may be used by treating its name as a macro value.
!POBJ SLD1.C=!POBJ GA1=,,,,(SLD1)
DEBUG "!POBJ SLD1.C=!POBJ
GA1=,,,-500,(SLD1)",CR
The value of the setpoint may be used as a second channel of data
to be plotted
DEBUG DEC X, ",(SLD1)",CR
|
 | Setting The Label
Similarly, the label of the slider may be updated.
!POBJ SLD1L=Setpoint
DEBUG "!POBJ SLD1L=Setpoint",CR
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR 'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR 'set gauge event code to play bell
DEBUG "!POBJ GA1.U=(AINVAL0)",CR 'set update value for gauge 1 to analog value 0
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR
'set gauge 1 label to analog value 0
DEBUG "!POBJ
SLD1=,-200,200",CR Set ranges of slider 1
DEBUG "!POBJ SLD1.C=!POBJ
GA1=,,,-500,(SLD1)",CR
'When moved, use
slider value to set high SP
DEBUG "!POBJ SLD1L=Setpoint",CR 'Set the label for the slider
DEBUG "!PLOT ON",CR 'Enable plotting
DEBUG "!RSET",CR 'Reset plot
FOR X = 0 to 255
DEBUG DEC X, ",(SLD1)",CR 'plot value
with setpoint of slider
DEBUG "!POBJ Update",CR 'update all objects with their update values
PAUSE 100
NEXT |
|
|
 | Progress Bar - Setting, updating
The progress bar is typically used to show the progress of some value
to maximum. The progress bar's minimum value is 0.
The general setting of the bar value is:
!POBJ objName=value[,max]
For example, a use may be to indicate total number of samples
collected.
DEBUG "!POBJ BAR1=",DEC
numSample,CR
Just as with other objects, an update value may be set. For an example, StampPlot collects a
finite number of samples. The current sample number can be
accessed with (DPOINT). The progress bar may be used to indicate total percent
collect.
'Set total number of points:
DEBUG "!PNTS 500",CR
'set maximum of bar1 to 500
DEBUG "!POBJ BAR1=,500",CR
'Set update value of bar 1
DEBUG "!POBJ BAR1.U=(DPOINTS)",CR
'Set label for Bar 1
DEBUG "!POBJ BAR1L=Data Points",CR
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR 'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR 'set gauge event code to play bell
DEBUG "!POBJ GA1.U=(AINVAL0)",CR 'set update value for gauge 1 to analog value 0
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR 'set gauge 1 label to analog value
0
DEBUG "!POBJ
SLD1=,-200,200",CR 'Set ranges of slider 1
'When moved, use slider value to set high setpoint of gauge
DEBUG "!POBJ SLD1.C=!POBJ
GA1=,,,-500,(SLD1)",CR
DEBUG "!POBJ SLD1L=Setpoint",CR 'Set the label for the slider
DEBUG "!PNTS
500",CR 'Set total number of points:
DEBUG "!POBJ
BAR1=,500",CR 'set maximum of bar1 to 500
DEBUG "!POBJ BAR1.U=(DPOINT)",CR 'Set update value of bar 1 to
'number of points collected
DEBUG "!POBJ BAR1L=Data Points",CR 'Set label for Bar 1
DEBUG "!PLOT ON",CR
'Enable plotting
DEBUG "!RSET",CR 'Reset plot
FOR X = 0 to 255
DEBUG DEC X, ",(SLD1)",CR 'plot value
with setpoint of slider
DEBUG "!POBJ Update",CR 'update all objects with their update values
PAUSE 100
NEXT |
|
 | Switches - Setting, Reading, Setting a Sound
The switches are simply Image buttons with 2 images assigned, one for
the 1 state (switch up) and one for 0 state (switch down). The
state may be changed by clicking on it or through code. The
value may be read from the BS2 or used for other interface purposes.
The general format for setting an image buttons is:
!POBJ objName=value (0/1)
 | Setting a switch state
The switches state (SW1-SW4) may be set through:
!POBJ SW1=0
In code, you may set the switches in the configuration to meet
some initial condition
DEBUG "!POBJ SW1=0",CR
DEBUG "!POBJ SW1=", BIN IN8,CR
|
 | Using a switch for Interactive Control
A switch (or almost any object) may be read directly from the BS2
for interactive control. For this example, SW1 will be used
to control output on P8 of the BS2.
DEBUG "!READ
(SW1)",CR
'Request data of SW1
SERIN 16,85,500,TimeOut,[BIN OUT8] 'Accept
returning data from
'StampPlot to OUT8 with Timeout
TimeOut:
PAUSE
100
'Pause to allow echo to clear on
'programming port (P16)
DEBUG IBIN
OUT8,CR
'Plot OUT8 as binary value
|
 | Reading multiple switches at once
The entire switch bank may be read by assembling them as a nibble,
and in this example, stored into output nibble C.
DEBUG "!READ
(SW4)(SW3)(SW2)(SW1)",CR 'Request data of SW1
SERIN 16,85,500,TimeOut,[BIN OUTC]
'Accept returning data from
'StampPlot to OUTC with Timeout
TIMEOUT:
PAUSE
100
'Pause to allow echo to clear
'on programming port (P16)
DEBUG IBIN4 OUTC,CR
'Plot OUTC as binary value
|
 | Setting a Sound
By setting the event code for the switches, they can play a WAV
file when clicked.
DEBUG "!POBJ SW1.C=~IWAV
stapler.wav",CR
Of course, we would need a line for each switch, or a wildcard may
be used to set all at once. All objects beginning with SW
will have their event code set. But this does also have an
undesirable effect of setting the labels to sound when clicked
also.
DEBUG "!POBJ SW*.C=~IWAV
stapler.WAV",CR
|
 | Putting it all together.
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR 'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR
'set gauge event code to play bell
DEBUG "!POBJ GA1.U=(AINVAL0)",CR 'set update value for gauge 1 to analog value 0
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR
'set gauge 1 label to analog value 0
DEBUG "!POBJ
SLD1=,-200,200",CR 'Set ranges of slider 1
DEBUG "!POBJ SLD1.C=!POBJ
GA1=,,,-500,(SLD1)",CR
'When moved, use slider value to set high setpoint
DEBUG "!POBJ SLD1L=Setpoint",CR
'Set the label for the slider
DEBUG "!PNTS
500",CR 'Set total number of points:
DEBUG "!POBJ
BAR1=,500",CR
'set maximum of bar1 to 500
DEBUG "!POBJ BAR1.U=(DPOINT)",CR Set update value of bar 1 to number of points
DEBUG "!POBJ BAR1L=Data Points",CR
'Set label for Bar 1
DEBUG "!POBJ SW*.C=~IWAV Stapler.wav",CR 'Set sound for switches using wildcard
DEBUG "!PLOT ON",CR 'Enable plotting
DEBUG "!RSET",CR 'Reset plot
DIRC =
%1111 'Set nibble C as outputs
Loop:
FOR X = 0 to 255
DEBUG "!READ
(SW4)(SW3)(SW2)(SW1)",CR 'Request data of
Switches as nibble
'Accept returning data from StampPlot to OUTC
SERIN 16,85,500,TimeOut,[BIN OUTC]
TIMEOUT:
PAUSE
100 'Pause to allow echo to clear on
DEBUG IBIN4 OUTC,CR 'Plot OUTC as binary value
DEBUG DEC X, ",(SLD1)",CR 'plot value
with setpoint of slider
DEBUG "!POBJ Update",CR 'update all objects with their update values
PAUSE 100
NEXT
GOTO Loop |
|
|
 | LIGHTS - Setting States.
The LED Lights are also image buttons having 2 images for the states -
Red and Green lights. By setting the value to 1 or 0 the lights
will be set to corresponding image.
 | Setting Directly
The simplest way is to set the state (value) directly.
!POBJ LT1=1
DEBUG "!POBJ LT1=1",CR
DEBUG "!POBJ LT1=",BIN OUT8,CR
all 4 Lights may be updated similarly.
|
 | Setting with plotted bits
If the switch state represents a digital trace being plotted, this
may be ready as macro value and the update value set
accordingly. This code will update LT1 with the bit in the
zero position and would be in the configuration section. Every time
!POBJ UPDATE is made, LT1 will be updated.
!POBJ LT1.U=(BIT0)
!DEBUG "!POBJ LT1.U=(BIT0)",CR
|
 | Using the user-defined macro routine
In the macro file which creates the interface, there are two routines in the user-defined section which may be used to update
the lights and switches using a single decimal number.
SET_SWS
SET_LTS
These routines are passed a decimal value which is converted to a
binary string (ADC- Analog to Digital Conversion), and the 4 bit
positions are used to update the lights or switches. %m0 and
%m1 are data markers which may be used to hold values. When the
macro is called, passed values are stored beginning at %m0.
Code in brackets [ ] indicate StampPlot math is to be
performed.
This is the routine to update the Lights:
SET_LTS:
!MATH %m1=[%m0,ADC]
!POBJ LT1=[%m1,pos,1]
!POBJ LT2=[%m1,pos,2]
!POBJ LT3=[%m1,pos,3]
!POBJ LT4=[%m1,pos,4]
ENDMAC
Call the macro routine and pass a value:
!MACR .SET_LTS,10
DEBUG "!MACR .SET_LTS,10",CR
DEBUG "!MACR .SET_LTS,", DEC OUTC,CR
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR
'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR
'set gauge event code to play bell
DEBUG "!POBJ GA1.U=(AINVAL0)",CR
'set update value for gauge 1 to analog value 0
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR
'set gauge 1 label to analog value 0
DEBUG "!POBJ
SLD1=,-200,200",CR 'Set ranges of slider 1
DEBUG "!POBJ SLD1.C=!POBJ
GA1=,,,-500,(SLD1)",CR
'When moved, use slider value to set high setpoint
DEBUG "!POBJ SLD1L=Setpoint",CR Set the label for the slider
DEBUG "!PNTS
500",CR 'Set total number of points:
DEBUG "!POBJ
BAR1=,500",CR 'set maximum of bar1 to 500
'Set update value of bar 1 to number of points
DEBUG "!POBJ BAR1.U=(DPOINT)",CR
DEBUG "!POBJ BAR1L=Data Points",CR 'Set label for Bar 1
DEBUG "!POBJ SW*.C=~IWAV Stapler.wav",CR 'Set sound for switches using wildcard
DEBUG "!PLOT ON",CR 'Enable plotting
DEBUG "!RSET",CR 'Reset plot
DIRC =
%1111 'Set nibble C as outputs
Loop:
FOR X = 0 to 255
DEBUG "!READ
(SW4)(SW3)(SW2)(SW1)",CR
'Request data of Switches
'Accept returning data from StampPlot to OUTC
SERIN 16,85,500,TimeOut,[BIN OUTC]
TIMEOUT:
PAUSE
100 'Pause to allow echo to clear
DEBUG IBIN4 OUTC,CR 'Plot OUTC as binary value
DEBUG DEC X, ",(SLD1)",CR 'plot value
with setpoint of slider
DEBUG "!POBJ Update",CR 'update all objects with their update values
'Call macro routine and pass OUTC in decimal
DEBUG "!MACR .SET_LTS,", DEC OUTC,CR
PAUSE 100
NEXT
GOTO Loop |
|
|
 | Text Boxes -
Setting
 | Displaying Text
The text boxes may be used to display information or values.
The general format for setting a text box is:
!POBJ objName = [text,back color, text color, font size]
For example, this will have TXT1 read "ALARM!"
in red text.
!POBJ TXT1=ALARM!,,(RED)
DEBUG "!POBJ
TXT1=ALARM!,(RED)",CR
|
 | Updating with macro values:
The update values of the textboxes may be set to show an updates
macro value, such as the channel 0 maximum, minimum and average.
DEBUG "!POBJ TXT1.U=MAX:
(AINMAX0)",CR
DEBUG "!POBJ TXT2.U=MIN: (AINMIN0)",CR
DEBUG "!POBJ TXT3.U=AVE: (AINAVE0)",CR
Note: These values will not reset unless a !CLMM is issued,
or !CMMR ON to reset when the plot resets... see the next section.
|
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR 'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR 'set gauge event code to play bell
DEBUG "!POBJ GA1.U=(AINVAL0)",CR 'set update value for gauge 1 to analog value 0
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR
'set gauge 1 label to analog value 1
DEBUG "!POBJ
SLD1=,-200,200",CR 'Set ranges of slider 1
DEBUG "!POBJ SLD1.C=!POBJ
GA1=,,,-500,(SLD1)",CR
'When moved, use slider value to set high setpoint of gauge
DEBUG "!POBJ SLD1L=Setpoint",CR
'Set the label for the slider
DEBUG "!PNTS
500",CR
'Set total number of points:
DEBUG "!POBJ
BAR1=,500",CR
'set maximum of bar1 to 500
'Set update value of bar 1 to number of points collected
DEBUG "!POBJ BAR1.U=(DPOINT)",CR
DEBUG "!POBJ BAR1L=Data Points",CR
'Set label for Bar 1
DEBUG "!POBJ SW*.C=~IWAV Stapler.wav",CR
'Set sound for switches using wildcard
'Set update value for TXT1 -3 for max, min and average
DEBUG "!POBJ TXT1.U=MAX:
(AINMAX0)",CR
DEBUG "!POBJ TXT2.U=MIN: (AINMIN0)",CR
DEBUG "!POBJ TXT3.U=AVE: (AINAVE0)",CR
DEBUG "!PLOT ON",CR
'Enable plotting
DEBUG "!RSET",CR 'Reset plot
DIRC =
%1111 'Set nibble C as outputs
Loop:
FOR X = 0 to 255
DEBUG "!READ
(SW4)(SW3)(SW2)(SW1)",CR 'Request data of
Switches
'Accept returning data from StampPlot to OUTC with Timeout
SERIN 16,85,500,TimeOut,[BIN OUTC]
TIMEOUT:
PAUSE
100
'Pause to allow echo to clear on programming port (P16)
DEBUG IBIN4 OUTC,CR 'Plot OUT8 as binary value
DEBUG DEC X, ",(SLD1)",CR 'plot value
with setpoint of slider
DEBUG "!POBJ Update",CR
'update all objects with their update values
DEBUG "!MACR .SET_LTS,", DEC OUTC,CR 'Call macro routine and pass OUTC in decimal
PAUSE 100
NEXT
GOTO Loop |
 | Of course, you can also use !READ (TXT1) to get
the value in a text box.
|
|
 | Buttons:
Setting and Coding
Buttons are typically only used to run some event code when clicked.
Setting them will change the caption they read. Let's set up a
couple buttons to reset the plot and clear the min/max values.
Configure BUT1 to reset the plot.
!POBJ BUT1=RESET
!POBJ BUT1.C=!RSET
DEBUG "!POBJ BUT1=RESET",CR
DEBUG "!POBJ BUT1.C=!RSET",CR
Configure BUT2 to clear the min/max/ave.
!POBJ BUT2=Clear Min/Max
!POBJ BUT1.C=!CLMM
DEBUG "!POBJ BUT2=Clear Min/Max",CR
DEBUG "!POBJ BUT2.C=!CLMM",CR
|
 | Checkboxes:
Setting and Using
Checkboxes, like image buttons, return a 1 or 0 (1=checked).
This value may be read, or used to configure aspects of
StampPlot. Let's configure one to show or not show real time on
the X axis. While the text of the check box cannot be changed
once created (we'll see about fixing that for the next update!) we can
set the tool text tip for it so when the mouse is over it, a box will
pop up showing the text help (or, you may edit the macro for a better
text).
Set a tool tip for the checkbox
!POBJ CHK1.Tip=Real Time
Event code when clicked, ((ME)) returns value of checkbox. This will
set to the plot to show real time or not
'real time on
!RTIM 1
'Real time off
!RTIM 0
!POBJ.C=!RTIM ((ME))
DEBUG "!POBJ CHK1.Tip=Real Time",CR
DEBUG "!POBJ CHK1.C=!RTIM ((ME))",CR
The text box may be set to a value of 1 or 0:
!POBJ CHK1=0
|
 | Banner - Setting
The banner is a scrolling text box like a ticker. One major tip
on using it is to pad with spaces to make the added text appear as it
is arriving from the far right. The general format is:
!Pobj objName=[text,back color, text color, speed]
!POBJ BAN=text
Here we will make it show the data and time, green on black, using the
update.
DEBUG "!POBJ BAN.U= ******** StampPlot (PRDT)
*********
,(BLACK),(GREEN)",CR
|
 | ListBox- Adding,
Using
The Listbox max be used to add items to the list.
!POBJ LST=value or text
We will use
buttons 3 and 4 to add an items to and to clear the list. The
items will be the current readings in the text boxes.
!POBJ BUT3=Add to list
!POBJ BUT3.C=!POBJ LST=(PRDT): (TXT1) (TXT2)
(TXT3)
!POBJ BUT4.C=Clear List
!POBJ BUT4.C=!POBJ LST Clear
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR
'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR 'set gauge event code to play bell
DEBUG "!POBJ GA1.U=(AINVAL0)",CR 'set update value for gauge 1 to analog value 0
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR 'set gauge 1 label to analog value
0
DEBUG "!POBJ
SLD1=,-200,200",CR 'Set ranges of slider 1
DEBUG "!POBJ SLD1.C=!POBJ
GA1=,,,-500,(SLD1)",CR
'When moved, use slider value to set high setpoint of gauge
DEBUG "!POBJ SLD1L=Setpoint",CR
'Set the label for the slider
DEBUG "!PNTS
500",CR 'Set total number of points:
DEBUG "!POBJ
BAR1=,500",CR 'set maximum of bar1 to 500
DEBUG "!POBJ BAR1.U=(DPOINT)",CR 'Set update value of bar 1
to points collected
DEBUG "!POBJ BAR1L=Data Points",CR 'Set label for Bar 1
DEBUG "!POBJ SW*.C=~IWAV Stapler.wav",CR
'Set sound for switches using wildcard
'Set update value for TXT1 -3 for max, min and average
DEBUG "!POBJ TXT1.U=MAX:
(AINMAX0)",CR
DEBUG "!POBJ TXT2.U=MIN: (AINMIN0)",CR
DEBUG "!POBJ TXT3.U=AVE:(AINAVE0)",CR
DEBUG "!POBJ BUT1=RESET",CR 'set buttons 1 for reset operation
DEBUG "!POBJ BUT1.C=!RSET",CR
DEBUG "!POBJ BUT2=Clear Min/Max",CR 'Set button 2 for clearing min/max
DEBUG "!POBJ BUT2.C=!CLMM",CR
'Set checkbox tip and code for showing real time
DEBUG "!POBJ CHK1.Tip=Real Time",CR
DEBUG "!POBJ CHK1.C=!RTIM ((ME))",CR
'set banner
DEBUG "!POBJ BAN.U= ******** StampPlot (PRDT)
*********
,(BLACK),(GREEN)",CR
DEBUG "!POBJ BUT3=Add to list",CR 'set button 3 to add min/max/ave to list
DEBUG "!POBJ BUT3.C=!POBJ LST=(RTIME) (TXT1) (TXT2)
(TXT3)",CR
DEBUG "!POBJ BUT4=Clear List",CR
'set button 4 to clear list box
DEBUG "!POBJ BUT4.C=!POBJ LST.Clear",CR
DEBUG "!PLOT ON",CR
'Enable plotting
DEBUG "!RSET",CR 'Reset plot
DIRC =
%1111 'Set nibble C as outputs
Loop:
FOR X = 0 to 255
DEBUG "!READ
(SW4)(SW3)(SW2)(SW1)",CR 'Request data of SW1
SERIN 16,85,500,TimeOut,[BIN OUTC] 'Accept returning data from StampPlot to OUTC
TIMEOUT:
PAUSE
100 'Pause to allow echo to clear on programming port (P16)
DEBUG IBIN4 OUTC,CR 'Plot
OUTC as binary value
DEBUG DEC X, ",(SLD1)",CR 'plot value
with setpoint of slider
DEBUG "!POBJ Update",CR 'update all objects with their update values
DEBUG "!MACR .SET_LTS,", DEC OUTC,CR
'Call macro routine and pass OUTC in decimal
PAUSE 100
NEXT
GOTO Loop |
|
 | Moving
and sizing objects, and setting visibility.
Objects may be moved by setting new coordinates for them. For
example, maybe the listbox is too big. It may be resized.
The general format is:
!POBJ objName.M=[Left,Top,Width,Height]
!POBJ LST.M=,,,10
DEBUG "!POBJ LST.M=,,,10",CR
Or, through code objects may be made non-visible.
!POBJ ObjName.V=0 or 1 (1=visible).
!POBJ SW4.V=0
A wildcard may be used to change a batch with common
names.
Let's set CHK2 to make the switches visible or not.
!POBJ CHK2.C=!POBJ SW*.V=((ME))
DEBUG "!POBJ CHK2.C=!POBJ
SW*.V=((ME))",CR
|
 | Adding another
object
Of course, your BS2 could have been used to create this interface from
scratch, but we are providing this general example for using some common
controls and to lighten the code needed in your BS2 program. We
can easily add a new text box (or any other object) through code by
creating one. Let's add a text box under the listbox.
The general format for creating a text box is:
!POBJ oText.ObjName=Left, Top [,Width, Height , text, back color,
text color, font size]
To create a new box called TXT5 at 8 over and 8 up from bottom
(background is 100x100).
!POBJ oText.TXT5=8,8
And now have it update with the maximum of the analog scale.
!POBJ TXT5.U=(AMAX)
DEBUG "!POBJ oText.TXT5=8,8",CR
DEBUG "!POBJ TXT5.U=(AMAX)",CR
X
VAR Byte
PAUSE 500
'Configure StampPlot
DEBUG "!POBJ GA1=,-200,200,-150,150",CR 'set gauge range and setpoints
DEBUG "!POBJ GA1.C=~PWAV gbell.wav",CR 'set gauge event code to play bell
DEBUG "!POBJ GA1.U=(AINVAL0)",CR 'set update value for gauge 1 to analog value 0
DEBUG "!POBJ GA1L.U=(AINVAL0)",CR 'set gauge 1 label to analog value
0
DEBUG "!POBJ
SLD1=,-200,200",CR 'Set ranges of slider 1
'When moved, use slider value to set high setpoint of gauge
DEBUG "!POBJ SLD1.C=!POBJ
GA1=,,,-500,(SLD1)",CR
DEBUG "!POBJ SLD1L=Setpoint",CR 'Set the label for the slider
DEBUG "!PNTS
500",CR 'Set total number of points:
DEBUG "!POBJ
BAR1=,500",CR 'set maximum of bar1 to 500
DEBUG "!POBJ BAR1.U=(DPOINT)",CR 'Set update value of bar 1 to number of points collected
DEBUG "!POBJ BAR1L=Data Points",CR 'Set label for Bar 1
DEBUG "!POBJ SW*.C=~IWAV Stapler.wav",CR 'Set sound for switches using wildcard
DEBUG "!POBJ TXT1.U=MAX:
(AINMAX0)",CR 'Set update value for TXT1 -3 for max, min and average
DEBUG "!POBJ TXT2.U=MIN: (AINMIN0)",CR
DEBUG "!POBJ TXT3.U=AVE:(AINAVE0)",CR
DEBUG "!POBJ BUT1=RESET",CR 'set buttons 1 for reset operation
DEBUG "!POBJ BUT1.C=!RSET",CR
DEBUG "!POBJ BUT2=Clear Min/Max",CR 'Set button 2 for clearing min/max
DEBUG "!POBJ BUT2.C=!CLMM",CR
DEBUG "!POBJ CHK1.Tip=Real Time",CR 'Set checkbox tip and code for showing real time
DEBUG "!POBJ CHK1.C=!RTIM ((ME))",CR
'set banner
DEBUG "!POBJ BAN.U= ******** StampPlot (PRDT)
*********
,(BLACK),(GREEN)",CR
DEBUG "!POBJ BUT3=Add to list",CR 'set button 3 to add min/max/ave to list
DEBUG "!POBJ BUT3.C=!POBJ LST=(RTIME) (TXT1) (TXT2)
(TXT3)",CR
DEBUG "!POBJ BUT4=Clear List",CR 'set button 4 to clear list box
DEBUG "!POBJ BUT4.C=!POBJ LST.Clear",CR
DEBUG "!POBJ
LST.M=,,,10",CR
'move listbox to height of 8
'set check box 2 to make switches visible or not
DEBUG "!POBJ CHK2.C=!POBJ
SW*.V=((ME))",CR
DEBUG "!POBJ
oText.TXT5=8,8",CR 'cerate a new text box
DEBUG "!POBJ TXT5.U=(AMAX)",CR 'update text 5 with analog scale maximum
DEBUG "!PLOT ON",CR 'Enable plotting
DEBUG "!RSET",CR
'Reset plot
DIRC =
%1111 'Set nibble C as outputs
Loop:
FOR X = 0 to 255
DEBUG "!READ
(SW4)(SW3)(SW2)(SW1)",CR 'Request data of SW1
'Accept returning data from StampPlot to OUTC with Timeout
SERIN 16,85,500,TimeOut,[BIN OUTC]
TIMEOUT:
PAUSE
100
'Pause to allow echo to clear on programming port (P16)
DEBUG IBIN4 OUTC,CR 'Plot OUT8 as binary value
DEBUG DEC X, ",(SLD1)",CR 'plot value
with setpoint of slider
DEBUG "!POBJ Update",CR 'update all objects with their update values
DEBUG "!MACR .SET_LTS,", DEC OUTC,CR 'Call macro routine and pass OUTC in decimal
PAUSE 100
NEXT
GOTO Loop
|
|
 | Minimizing code
space
All that text takes a large amount of code space in your
BS2. By taking all the configuration information and moving it
into the macro (at the end of the OBJECTS: routine -- open the macro
with Notepad) all those configurations can reside in a text file
leaving the actual BS2 code very small. Don't forget to take out
the all the DEBUG formatting (maroon code in examples above, not blue code).
|
 | Good luck and happy plotting!
|
 | File Links:
|
|
|