PINK, BS2 and not declaring an array.
adamblake
Posts: 3
The
I ran into an interesting situation with the PINK board and the BS2.
I was trying to find a workaround for capturing a string from a webpage
using my BS2.
If I declare an array of the proper size, I run out of variable RAM to do much else
very quickly.
On a whim, I tried the following bit of code where I simply declare a variable of size byte
instead of making an array.
To my surprise, the following code worked in allowing my to read a string from a webpage and
then immediately store it in DATA in the EEPROM.
The problem is, I don't understand why this works and I've also run into some strange anomalies.
I'm pretty sure it's due to the fact that I'm overwriting other variables in RAM.
I think my solution will be to upgrade to a BS2p and use SPSTR with SERIN to store
the incoming string from the wepbage directly to Scratch PAD RAM and bypass this array/non-array
issue.
nbvar VAR BYTE ' PINK Data Variable Array
GetString:
DEBUG "Reading new message from webpage", CR
index = 0
SEROUT TX, Baud, [noparse][[/noparse]"!NB0R10"] ' Command To Read Variable 10
SERIN RX, Baud, 100, Timeout, [noparse][[/noparse]STR nbvar\20\CLS] ' Get Data With Timeout
DO UNTIL nbvar(index) = 0
WRITE WebData + index, nbvar(index)
index = index + 1
LOOP
MessageAddress = WebData
MemLocBit = 1
GOSUB NewWord
RETURN
Does anybody have any thoughts or comments on this issue?
regards,
-Adam
I ran into an interesting situation with the PINK board and the BS2.
I was trying to find a workaround for capturing a string from a webpage
using my BS2.
If I declare an array of the proper size, I run out of variable RAM to do much else
very quickly.
On a whim, I tried the following bit of code where I simply declare a variable of size byte
instead of making an array.
To my surprise, the following code worked in allowing my to read a string from a webpage and
then immediately store it in DATA in the EEPROM.
The problem is, I don't understand why this works and I've also run into some strange anomalies.
I'm pretty sure it's due to the fact that I'm overwriting other variables in RAM.
I think my solution will be to upgrade to a BS2p and use SPSTR with SERIN to store
the incoming string from the wepbage directly to Scratch PAD RAM and bypass this array/non-array
issue.
nbvar VAR BYTE ' PINK Data Variable Array
GetString:
DEBUG "Reading new message from webpage", CR
index = 0
SEROUT TX, Baud, [noparse][[/noparse]"!NB0R10"] ' Command To Read Variable 10
SERIN RX, Baud, 100, Timeout, [noparse][[/noparse]STR nbvar\20\CLS] ' Get Data With Timeout
DO UNTIL nbvar(index) = 0
WRITE WebData + index, nbvar(index)
index = index + 1
LOOP
MessageAddress = WebData
MemLocBit = 1
GOSUB NewWord
RETURN
Does anybody have any thoughts or comments on this issue?
regards,
-Adam
Comments
You can write values to a variable past what you have declared and will run; however there is only 26 variables allowed total when using the BASIC Stamp 2 modules and by declaring them, allows a user to reference them easily.·Depending on how many other variables you are using, they could be overwritten from the 20 byte string; causing the strange anomalies that you spoke of. The BS2e to BS2px allows the SPRAM to be used in a number of ways and as long as there is no power fluctuation or possible resetting of the controller, then the data should be safe.
I hope this helps,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com
Post Edited (Joshua Donelson (Parallax)) : 2/6/2010 12:06:14 AM GMT
I just ordered the BS2e.
I'm thinkin' that should do the trick.