# DEBUGIN

{PBASIC 2.5}

DEBUG / DEBUGIN Example

Syntax: DEBUGIN InputData

## Function

Retrieve information from the user via the Debug Terminal window within the BASIC Stamp editor program.

- InputData is list of variables and formatters that tells DEBUGIN what to do with incoming data. DEBUGIN can store data in a variable or array, interpret numeric text (decimal, binary, or hex) and store the corresponding value in a variable, wait for a fixed or variable sequence of bytes, or ignore a specified number of bytes. These actions can be combined in any order in the InputData list.

## Quick Facts

| BS2, BS2e, BS2sx, BS2p, and BS2pe | BS2px
Serial Protocol | Asychronous 9600 baud, N, 8, 1 Inverted polarity, Raw Data | Asychronous 19.2 kBaud, N, 8, 1 Inverted polarity, Raw Data
Related Commands | DEBUG, SERIN

## Explanation

DEBUGIN provides a convenient way for your BASIC Stamp accept input from the use via the Debug Terminal. DEBUGIN can wait for, filter and convert incoming data in powerful ways, using the same techniques and modifiers as SERIN.

This simple example waits for a number from the user, then prints a message the specified number of times:

    lines   VAR     Nib
    idx     VAR     Nib

    Main:
      DEBUG CLS, "How many lines to print (1 - 5)? --> "
      DEBUGIN DEC1 lines

      IF ((lines >= 1) AND (lines <= 5)) THEN
        DEBUG CR, CR
        FOR idx = 1 TO lines                        ' print message specified times
          DEBUG DEC1 idx, ". "
          DEBUG "BASIC Stamp!", CR
        NEXT
        END                                         ' end of program
      ELSE
        DEBUG CR, "Invalid entry!"                  ' warning message
        PAUSE 2000                                  ' wait 2 seconds
        GOTO Main                                   ' get another entry
      ENDIF

After you download this program, the BASIC Stamp Editor will open a Debug Terminal on your PC screen and wait for an entry from the user. Since the DEC1 modifier is used with DEBUGIN, the program will ignore all keys except "0" - "9". If the value entered is between 1 and 5, the message will be printed, otherwise the program will display an "Invalid entry" message, then loop back and wait for another entry.

DEBUGIN is actually a special case of the SERIN instruction. It is set for inverted (RS-232-compatible) serial output through the programming connector (the SIN pin) at 9600 baud (BS2, BS2e, BS2sx, BS2p, and BS2pe) or 19.2 kBaud (BS2px), no parity, 8 data bits, and 1 stop bit. For example,

      DEBUGIN DEC1 lines

...is exactly like:

      SERIN 16, $4054, [DEC1 lines]

...in terms of function (on a BS2). The DEBUGIN line actually takes less program space, and is obviously easier to type.

The tables below list all the available conversion formatters and special formatters available to the DEBUGIN command. See the SERIN command for additional information and examples of their use.

Conversion Formatter | Type of Number | Numeric Characters Accepted | Notes
DEC{1..5} | Decimal, optionally limited to 1 - 5 digits | 0 through 9 | 1
SDEC{1..5} | Signed decimal, optionally limited to 1 - 5 digits | -, 0 through 9 | 1,2
HEX{1..4} | Hexadecimal, optionally limited to 1 - 4 digits | 0 through 9, A through F | 1,3
SHEX{1..4} | Signed hexadecimal, optionally limited to 1 - 4 digits | -, 0 through 9, A through F | 1,2,3
IHEX{1..4} | Indicated hexadecimal, optionally limited to 1 - 4 digits | $, 0 through 9, A through F | 1,3,4
ISHEX{1..4} | Signed, indicated hexadecimal, optionally limited to 1 - 4 digits | -, $, 0 through 9, A through F | 1,2,3,4
BIN{1..16} | Binary, optionally limited to 1 - 16 digits | 0, 1 | 1
SBIN{1..16} | Signed binary, optionally limited to 1 - 16 digits | -, 0, 1 | 1,2
IBIN{1..16} | Indicated binary, optionally limited to 1 - 16 digits | %, 0, 1 | 1,4
ISBIN{1..16} | Signed, indicated binary, optionally limited to 1 - 16 digits | -, %, 0, 1 | 1,2,4
NUM | Generic numeric input; hex or binary number must be indicated | $, %, 0 through 9, A through F | 1,3,4
SNUM | Similar to NUM with value treated as signed with range -32768 to +32767 | -, $, %, 0 through 9, A through F | 1,2,3,4

1. All numeric conversions will continue to accept new data until receiving either the specified number of digits (ex: three digits for DEC3) or a non-numeric character.
2. To be recognized as part of a number, the minus sign (-) must immediately precede a numeric character. The minus sign character occurring in non-numeric text is ignored and any character (including a space) between a minus and a number causes the minus to be ignored.
3. The hexadecimal formatters are not case-sensitive; "a" through "f" means the same as "A" through "F".
4. Indicated hexadecimal and binary formatters ignore all characters, even valid numerics, until they receive the appropriate prefix ($ for hexadecimal, % for binary). The indicated formatters can differentiate between text and hexadecimal (ex: ABC would be interpreted by HEX as a number but IHEX would ignore it unless expressed as $ABC). Likewise, the binary version can distinguish the decimal number 10 from the binary number %10. A prefix occurring in non-numeric text is ignored, and any character (including a space) between a prefix and a number causes the prefix to be ignored. Indicated, signed formatters require that the minus sign come before the prefix, as in -$1B45.

Special Formatter | Action
STR ByteArray \L {\E} | Input a character string of length L into an array. If specified, an end character E causes the string input to end before reaching length L. Remaining bytes are filled with 0s (zeros).
WAITSTR ByteArray {\L} | Wait for a sequence of bytes matching a string stored in an array variable, optionally limited to L characters. If the optional L argument is left off, the end of the array-string must be marked by a byte containing a zero (0).
SKIP Length | Ignore Length bytes of characters.

Special Formatter | Action
SPSTR L | Buffer length L bytes (up to 126) of serial characters to Scratchpad RAM, starting at location 0. Use GET to retrieve the characters.

    idx     VAR     Nib
    char    VAR     Byte

    Setup:
      DEBUG CLS, "Enter (4-character) passcode: "

    Main:
      DEBUGIN SPSTR 4
      DEBUG CLS, "Checking: "
      FOR idx = 0 TO 3
        GET idx, char
        DEBUG char
      NEXT
      END

The example above will redirect four characters from the Debug Terminal input to Scratchpad locations 0 - 3.

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012