Shop OBEX P1 Docs P2 Docs Learn Events
SERIN command with Hyperterminal — Parallax Forums

SERIN command with Hyperterminal

cjkogan111cjkogan111 Posts: 20
edited 2007-05-24 03:06 in BASIC Stamp
Hello, I am having trouble using the SERIN command to read what I type in hyperterminal on the basic stamp (using the debugger to read the variable typed.)

The code is as follows:

get_ground_command:
SERIN SER_IN, 188, 10000, timeout, [noparse][[/noparse]WAIT(01,02),STR command\2]
DEBUG "MADE IT", CR
timeout:
DEBUG "CONTINUE", CR
DEBUG DEC5, command
RETURN

Iam using the MAX232 chip as a serial driver to interface between the computer and the stamp.
I have been able to successfully use the SEROUT command with the same baud rate to write an output to the computer. Also, I have shorted together pins 11 and 12 on the MAX232 and been able to perform a successful loopback with my computer (meaning what I type in hyperterminal immediately appears.) When I type in the terminal, I will type a command like 1256A, where the 1 and 2 (that is what the wait 01,02 is - I think) should initialize the transfer, and the A ends it.
I think that the problem is with my SERIN code, or what I am typing in hyperterminal. I was wondering if you can see a problem with either what I am typing or my SERIN command.
Sorry if I didn't write this very clearly, I will be able to answer questions whenever.
Thanks!
- cjkogan111

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-23 04:29
    Hello,

    One problem I see is that you’re waiting for a value of 1 then 2, but you’re typing 1 and 2, which is actually sending ASCII $31 and $32 which are different values. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Naphtali MooreNaphtali Moore Posts: 42
    edited 2007-05-23 06:22
    Yes, Try this instead:

    SERIN SER_IN, 188, 10000, timeout, [noparse][[/noparse]WAIT("12"),STR command/2]

    INPUT = RESULT

    12a3e = "a3"

    12a3 = "a3"

    12a 1 = "a "

    1x = Here the function will wait till the time out and continue to the time out function

    12 = Here the function will continue to wait till 2 more bytes are recieved and will not go to the time out function.
  • cjkogan111cjkogan111 Posts: 20
    edited 2007-05-23 15:17
    Sweet! I just took the wait command off of my code and got it to display "MADE IT" - after two key presses.

    command VAR Word

    get_ground_command:
    SERIN SER_IN, 188, 10000, timeout, [noparse][[/noparse]STR command\2]
    DEBUG "MADE IT", CR
    timeout:
    DEBUG "CONTINUE", CR
    DEBUG DEC5, command
    RETURN

    Still, however, every time that command is written out, its value is 00000.
    Is command not taking on a value of the input, or am I writing it out incorrectly? Any ideas?
    Thanks!
    - cjkogan111
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-23 15:43
    Hello,

    You’re entering the data into an array of one element (Word) of which serial can only input one byte at a time. Try this:
    SERIN SER_IN, 188, 10000, timeout, [noparse][[/noparse]DEC2 command]
    

    For more digits, change the 2 to a 3, 4 or 5.· I hope this helps.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-05-23 15:52
    Hi cj, hyperteminal is sending one byte for each keypress, change command var word to command var byte and you should see the ascii code for your key press. 1=49 2=50 etc, google ascii code.

    Also serin(STR) stores your key press's in an array (command), each key press is stored in a different element of the array, to view each key press you need to debug each element. In your code you are using two elements (STR command\2) the index starts at 0 through 1.

    Example

    DEBUG DEC command(0)

    DEBUG DEC command(1)

    Alternatively you can send the array back to hyperteminal using SEROUT SER_OUT,188,[noparse][[/noparse]STR command] and hyperterminal should display it as you typed it.

    Jeff T.
  • cjkogan111cjkogan111 Posts: 20
    edited 2007-05-23 20:59
    Thanks, changing command to a byte instead of a word did the trick:

    command VAR Byte

    Now I am able to press the keys and see there values on the debug from the stamp.

    get_ground_command:
    SERIN SER_IN, 188, 10000, timeout, [noparse][[/noparse]WAIT(49,50),STR command\2]
    DEBUG "MADE IT", CR
    timeout:
    DEBUG "CONTINUE", CR
    DEBUG DEC command(0)
    DEBUG DEC command(1)
    RETURN

    One more question, the transmission that the stamp should receive will be something like: 12AA3DA, where the 12 initiates the transfer, and the 3DA ends the transfer.
    I can use WAIT(49,50) to begin the transfer, but is there any similar way to end the transfer?
    Thanks!
    -cjkogan111
  • cjkogan111cjkogan111 Posts: 20
    edited 2007-05-23 21:37
    Nevermind, I figured it out. Just another WAIT command.
    -cjkogan111
  • skylightskylight Posts: 1,915
    edited 2007-05-23 23:09
    I noticed in the example above that Return is used, does the Serin command at timeout act like·the command·"gosub timeout" with Return bringing focus back to the Debug "Made IT" line?
    hope im not hijacking this post by asking
  • FORDFORD Posts: 221
    edited 2007-05-24 03:06
    No, the timeout doesnt act as a gosub, it simply jumps to the timeout label once the time period has expired with no data coming in.

    Be careful with the timeout function combined with WAIT, as·stray data (or electrical noise on the line) will hold the program there.
    I mean,·it will hang there until either...
    1- It receives the data specified in the·WAIT command, or
    2- It times out with no data coming in.

    Hope this helps,

    Cheers, Chris, West Oz.
Sign In or Register to comment.