Binary and Special Data
Home ] Up ] Basic Concepts ] Serial Connection ] Plotting Basics ] Logging, Saving and Printing ] Interactive Control ] Macro Basics ] Macros - Default & Events ] Macro Math Discussion ] Defined Macro Buttons/Menus ] Drawing Basics ] Media and Paths ] Drawing Coordinate Modes ] Plot Objects ] Macro Editor ] Using Templates ] External Applications ] Historical/Logged Data ] Internet ] [ Binary and Special Data ]

By default, StampPlot accepts analog values as ASCII data with multiple channel data being separated, or delimited, by commas:
100,150,85

StampPlot may also accept data as binary values with an optional checksum, or as data strings with special delimiters.  The Options Window, Data Tab allows configuration of special data as does the Plot menu, Advanced options along with StampPlot Instructions.  These features allow easier use of StampPlot with controllers in which the the use of ASCII data may be difficult, or with devices from which the string is in a special format, such as digital VOMs with serial ports, or GPS units.

bulletBinary Data:
By default, StampPlot accepts data analog such as 100 as an ASCII string of "100" ending in a carriage return.  In binary data mode, the value of 100 is sent as the binary value (or character) 100.

Multiple values may be sent by defining the total number of bytes in the data set, and whether a checksum value is used for data integrity.  Individual data is accessible using the macro values AINVAL0 and so on.

bulletConfiguring for Binary Data

For example, the example BS2 program shipped with StampPlot for testing the macro is the following:
'{$STAMP BS2}
'Plots 4 analog values and 2 digital for testing with
'StampPlot Pro Version 3.
'Copy and paste into stamp editor

x var byte
Y var Nib
Val1 var byte
Val2 var byte
Val3 var word
Val4 var word

inByte var Byte
DIRH = 255


loop:
    Y = 3
     FOR x = 0 to 250
        Pause 200
        Val1 = (Sin X + 127)/2
        Val2 = X  * Y: Val2 = (Cos Val2 + 127)/2
        Val3 = (Val1 + Val2)
        Val4 = (Val1 - Val2)
        'Plot 4 comma-separated values
        DEBUG sdec Val1,",",sdec Val2,",",sdec Val3,",",sdec Val4,CR
     'plot 2 indicated-binary values
        DEBUG IBIN2 X,CR
    NEXT
GOTO loop


This program sends back data such as:
127,120,200,100 (followed by a carriage return, ASCII13)
(it also send back digital values to be plotted which we will ignore for now).

By altering the program we can send the binary values for Val1 to Val4, plus the checksum (or the sum of Val1 +Val2+Val3+Val4):

x var byte
Y var Nib
Val1 var byte
Val2 var byte
Val3 var word
Val4 var word

inByte var Byte
DIRH = 255


loop:
    Y = 3
     FOR x = 0 to 250
        Pause 200
        Val1 = (Sin X + 127)/2
        Val2 = X  * Y: Val2 = (COS Val2 + 127)/2
        Val3 = (Val1 + Val2)
        Val4 = (Val1 - Val2)
        'Plot 4 binary values with checksum
        DEBUG Val1,Val2,Val3,Val4,Val1+val2+val3+val4
    NEXT
GOTO loop
'NOTE: values > 255 and <0 will be truncated to once byte by the BASIC Stamp.

By configuring StampPlot to use 4 Binary values with checksum, StampPlot will plot the data and ignore any data for which the checksum fails.

' Use binary data
!USEB ON
' Number of bytes 4
!NUMB 4
' Enable checksum
!CSUM ON


Note that the BS2 string DID not end with a CR.  Also, once in binary mode, instructions, binary, or other special data CANNOT be sent directly.
bulletOther processing with Binary Data

By default, Binary data used the incoming data as analog values.  To use the binary data for special uses, set StampPlot to Use Analog Data for Macro Only, then use the AINVAL values in the macro.

' Use binary data
!USEB ON
' Number of bytes 4
!NUMB 4
' Enable checksum
!CSUM ON
' Set to use analog data for macro only
!USEA ON

Once the data is coming in, some choices may be to plot the 1st byte as analog, the next 2 bytes as a 16-bit analog value (High byte, Low byte), and the 4th byte as digital.  A good place for this code would be in a data arrival object, or the default macro routine.  It may be entered directly in the CLI for testing after entering 4 comma delimited values in the CLI or sending 4 binary values from a micro.

^ACHN 0,(AINVAL0),0
^ACHN 1,[[(AINVAL1),*,256],+,(AINVAL2)],12
%[(AINVAL3),ADC]

bulletSpecially Parsed Data
By default, StampPlot accepts analog values delimited by commas for the 10 channels.  By using specially parsed data option you may assign the delimiter.  This enables data to be quickly parsed when it is not possible to change the data structure.
bulletStrings must still end with a carriage return (ASCII 13).
bulletAll strings except instruction and drawing strings (those beginning with !, ^,@,~) will be parsed.
bulletValues will automatically be plotted unless Use Analog Data for Macros is enabled (!USEA ON).
bulletData will be placed in to macro values AINVAL0 and up.  Data will also be placed in values PARSE0 and up.
bulletThe delimiter may be a single character or group of characters.

To enable special parsing:
!PARS ON/OFF
!PARS ON

To set the delimiter or parse character:
!PCHR character
!PCHR ;