How to read a long string in SX/B
John Couture
Posts: 370
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
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
· 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 J. Couture
San Diego Miramar College
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax