Shop OBEX P1 Docs P2 Docs Learn Events
Read string from Serial Port and convert it to numbers - Page 2 — Parallax Forums

Read string from Serial Port and convert it to numbers

2»

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-01-10 23:09
    I have found that the STAMP has trouble with decimal formatting at 9600 baud (bps).
    The HELP for SERIN/SEROUT states that this is likely.

    Anyway, I say this because I have downloaded the following program and verified my statement.
    It would not work at 9600, but it works great at 4800 bps.

    It is practically the same program that I first sent.· However, it is using SERIN 16 like you want.·
    I have an LED on P0 and another on P1 that turn on to verify the outputs·in accordance with·valid/desired SERIN,·they confirm LEFTVAL and RIGHTVAL correctness.

    I send data·to the STAMP using the first format, that is,·with the parentheses and the comma in·the middle: (###,###).

    My Conclusion --
    I think that you need to slow down your Linux or whatever is sending data to the STAMP to 4800 bps.·
    Hopefully this will not be·impossible.

    Try it, you'll like it.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' {$PORT COM1}
     
    LEFTVAL VAR Word
    RIGHTVAL VAR Word
     
    Prelims:
       DIRS = $0F        'MSB INs, LSB OUTs
       OUTL = %00000000  'preset OUTs
       INH  = %00000000
     
    LEFTVAL = 0
    RIGHTVAL = 0
     
    GetData:
      SERIN 16, 16572,[noparse][[/noparse]WAIT("("),DEC LEFTVAL,DEC RIGHTVAL]
      IF LEFTVAL = 100 THEN GOSUB LED1ON
      IF RIGHTVAL = 200 THEN GOSUB LED2ON
      PAUSE 5000
      GOTO LEDSOFF
     
    LED1ON:
      OUT0 = 1
      RETURN
     
    LED2ON:
      OUT1 = 1
      RETURN
     
    LEDSOFF:
      OUTL = %00000000
      LEFTVAL = 0
      RIGHTVAL = 0
      GOTO GetData
    



    ... and That's The Way It Is.



    Post Edited (PJ Allen) : 1/10/2006 11:12:05 PM GMT
  • John AstralidisJohn Astralidis Posts: 28
    edited 2006-01-10 23:19
    Allen Thank I 'll try .

    Could you please remind me what the proper number for 4800 8n1 connection to write in my code? I mean like 16468 is for 9600 8n1. What s for 4800 8n1?

    John.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-01-10 23:20
    It is 16572 -- it's right there in the program, John.· C'mon.
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-01-10 23:32
    On a side note,

    PJ, I have had SERINs not work when I looked for an early termination char (the \L {\E} )- but *did* work when I omitted the specified end character. (At certain speeds, namely 9600.) Just confirming your statements.

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • John AstralidisJohn Astralidis Posts: 28
    edited 2006-01-10 23:32
    Ok, sorry.

    I have only 1 serial port in my PC sharing both modem Internet Connection and Communication with BoeBot. So, each time I want to test a program I have to disconnect.
    It's really irritating! If I use a usb-to-serial adapter do U think I will solve this problem? I mean, the Basic Stamp will be successfully recognised by the program editor?

    John.

    [noparse][[/noparse]I'll try your code now...]
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-01-10 23:36
    It would not hurt to try, John.· Make sure that they are on different COM #.· We're all waiting, buddy.

    Post Edited (PJ Allen) : 1/10/2006 11:40:25 PM GMT
Sign In or Register to comment.