Shop OBEX P1 Docs P2 Docs Learn Events
How to display data from serin in a debug screen ? — Parallax Forums

How to display data from serin in a debug screen ?

ionion Posts: 101
edited 2004-09-28 20:25 in BASIC Stamp
According with the help file for serin, if we use the line
SERIN 1, 16780, [noparse][[/noparse]DEC sData]The program wait until it will get a non numeric value then store the data in the variable sData.What method to use to see in a debug screen what data you type, because until you press any non numeric key , the program just wait to the serin command and it will not advance to the Debug line ?Second question is related to the number of variable. Can we use a serin command like thisSERIN 1, 16780, [noparse][[/noparse]DEC4 sData, DEC4 pData]Ion

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-28 12:29
    The first example in your post waits for a single byte -- it doesn't care what it is.· Once you have the byte, you can display it in any format you like:

    DEBUG sData···········' display ASCII character
    DEBUG DEC sData······ ' display decimal value of sData
    DEBUG HEX sData······ ' display hex value of sData
    DEBUG BIN sData······ ' display binary value of sData

    In you second example, you're using the DEC filter so only numeric characters ("0" - "9") will be accepted.· You are also limiting the number of characters per byte to four, so if your input string is:

    "01234567"

    then sData (which must be defined as a Word) will be 123, and pData (also a Word) will be 4567.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ionion Posts: 101
    edited 2004-09-28 12:53
    Thank you Jon, for the answer, but maybe I did not make myself clear.
    What I want to do, ·is to see each character on the debug screen while I type.
    As I said, for a
    SERIN 1, 16780, [noparse][[/noparse]DEC4 sData]
    I would like to see each character on the debug windows while I type them, and not the whole word after I completed the 4 digits to enter.
    So in this case I would like to see :
    1
    12
    123
    1234
    I do not want to use any ECHO to get them to the screen. I would like the DEBUG to display them
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-28 15:32
    No can do. When you're using the DEC4 modifier the value is not complete until four digits have been input or a non-digit character (terminator) has come in. Using a modifier like this, the BASIC Stamp doesn't see characters as individuals that you can deal with, it sees them as part of a larger unit. You could simulate the input in code so that you can see each character, but this would be a lot of work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ionion Posts: 101
    edited 2004-09-28 15:52
    Thank you.
    I taught so
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-28 16:35
    IMHO, a cup of Starbucks' coffee is Heaven ... and after a cup, I came up with this.· Perhaps it will help you.

    Get_Value:
    · value = 0
    · digits = 0

    Get_Char:
    · DO
    ··· DEBUGIN char······················· ' get character
    ···· SELECT char······················· ' a number?
    ····· CASE "0" TO "9"
    ······· IF (digits < numDigits) THEN
    ········· DEBUG CRSRXY,
    ··············· col + digits, row, char ' display at row, col
    ········· value = value * 10··········· ' shift value digits left
    ········· value = value + (char - "0")· ' add new digit
    ········· digits = digits + 1·········· ' update digit count
    ······· ENDIF
    ····· CASE BKSP························ ' backspace?
    ······· IF (digits > 0) THEN
    ········· value = value / 10··········· ' correct value
    ········· digits = digits - 1·········· ' update digit count
    ········· DEBUG CRSRXY,
    ············· col + digits, row, " "··· ' clear last digit
    ······· ENDIF
    ····· CASE ELSE
    ······· IF (digits > 0) THEN EXIT······ ' terminate input?
    ··· ENDSELECT
    · LOOP UNTIL (digits > numDigits)
    · RETURN

    I did in fact test this code (demo attached)·and it does what you want (with the flexibility to determine the number of digits to accept, as well as deal with a backspace character).· You must setup "row" and "col" for the display position before calling.· Note that the cursor positioning only works with the Stamp DEBUG screen, and is not applicable to external terminals like HyperTerm.· You must also have the "Echo Off" selection on the DEBUG screen checked.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 9/28/2004 4:53:25 PM GMT
  • ionion Posts: 101
    edited 2004-09-28 16:47
    Thank you very much Jon.
    Did you ever taught about cloning yourself. A small group of Jon, will make miracles for Parallax and beat Microsoft
    Thanks
    Ion
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-28 20:25
    My neighbor suggested that one Jon was quite enough for the world to bear. I think she's right.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.