Shop OBEX P1 Docs P2 Docs Learn Events
How to read a long string in SX/B — Parallax Forums

How to read a long string in SX/B

John CoutureJohn Couture Posts: 370
edited 2006-03-05 23:31 in General Discussion
1) SX/B allows the creation of arrays that are up to 16 characters long on the SX18/SX28.

2)·I'm trying to read in a long string from the serial pin and then, once the CR or LF is received, process the line.· Trying to access anything beyond the 16th byte causes it to hang.· Am I missing something obvious?· As I write this I can see a work around by putting in more IF statements or the __RAM statement, but I'm trying to minimize code.


' Declarations
Buffer· var byte(16)
Buffer2 var byte(16)


' Code
Main:·
·· BufIdx = 0

Main2:
···SERIN SIO,BAUD,TX_Char
·· if TX_Char = $0D then Main3
·· if TX_Char = $0A then Main3
·· buffer(bufidx) = TX_Char
·· inc BufIdx
·· if bufidx < 25 then Main2
Main3:
·· ' process line

·· x = Buffer(21)

·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture

San Diego Miramar College

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-05 22:09
    Look at the PUT_BUF and GET_BUF routines in this program:

    · http://forums.parallax.com/attachment.php?attachmentid=39038

    You'll see that this SX28 program creates a 64-byte circular buffer.· In the end there are restrictions with the SX28 memory that we just have to live with and code for.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • John CoutureJohn Couture Posts: 370
    edited 2006-03-05 22:58
    Pretty clever! Jon, I always like looking over your code because every time I learn something new. Now where did you say that all inclusive book of the SX/B language was ... other than in your head? (grin). Thank you Jon, Great Job.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-05 23:31
    Maybe I'm close to the language because my job in the project is to maintain the help file....

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