Storing String from Serial to EEPROM
Steel
Posts: 313
I am having some trouble converting types and storing them for later use.·
I used the Data command to write information to the EEPROM:
DATA %01111111, %11000001, %00100000,··%10111111, %11000011, %11100000
Instead of having that in the code, I decided that I wanted to send the data through serial.
I created a VB.Net application to send this to the Stamp through COM1:
"!%01111111, %11000001, %00100000,··%10111111, %11000011, %11100000"· (Same as above)
I set up this code on the Stamp:
IncomingData1······· VAR···· Byte
T9600············· CON···· 84
Inverted······· CON···· $4000
SERIN 16, T9600 + Inverted, [noparse][[/noparse]WAIT("!"),IncomingData1]
-How can I format the 'IncomingData1' Variable to take a String from the ComPort instead of a Byte or word?
-How can I take the variable "IncomingData1" and store all of that information the same way I would with the "DATA" command?
-If I performed a Read, would I pull the data out of the EEPROM in the same fashion?
Any help would be appreciated.
Shaun
I used the Data command to write information to the EEPROM:
DATA %01111111, %11000001, %00100000,··%10111111, %11000011, %11100000
Instead of having that in the code, I decided that I wanted to send the data through serial.
I created a VB.Net application to send this to the Stamp through COM1:
"!%01111111, %11000001, %00100000,··%10111111, %11000011, %11100000"· (Same as above)
I set up this code on the Stamp:
IncomingData1······· VAR···· Byte
T9600············· CON···· 84
Inverted······· CON···· $4000
SERIN 16, T9600 + Inverted, [noparse][[/noparse]WAIT("!"),IncomingData1]
-How can I format the 'IncomingData1' Variable to take a String from the ComPort instead of a Byte or word?
-How can I take the variable "IncomingData1" and store all of that information the same way I would with the "DATA" command?
-If I performed a Read, would I pull the data out of the EEPROM in the same fashion?
Any help would be appreciated.
Shaun
Comments
·· You can not input a string from the COM Port.· You can input bytes one at a time, and deal with them on the fly.· You can try getting a byte from the serial port in a loop and writing to EEPROM, but speed may be a factor.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
If it is one that supports SERIN directly to the ScratchPad ram (BS2P and up I think) you can input a string directly from SERIN in one call.
The only 'gotcha' is the call doesn't return how much data is received. I don't have the editor in front of me but basically all you need to do is:
First fill scratchpad with x00.
The do the SERIN read of however many bytes the ScratchPad can hold with a timeout too. Have it go to the same place in code either way.
Then you woud want to do something like...
Set a byte to 0 to denote the position you are in the scratch pad.
Then read a word from scatchpad at the position byte. If the word is 0000 loop back to the read or move on in your code as you hit the end of the received data. (Or the call timed out with no data)
Else read a byte at position byte and write it to EEPROM. Increment the position byte by one.
Then loop back to reaching/checking the Word from scratchpad.
If there is the possibility of a long string being received you should also check that position byte is equal to or less then the max number of bytes the scratchpad can hold.
Once you have the data, you can use WRITE to store it (you'll have to keep track of where WRITE is writing to).
And yes, READ pulls a value from the EEPROM (again, you supply the address for READ).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 9/2/2005 2:01:39 PM GMT
·· I see I missed something in your original post.· I thought you were sending the data exactly as it was to be stored in the DATA statements, because of the line (Same as above).· I now·see you are actually trying to send each byte/value as 9 bytes of ASCII data representing each binary value.
·· I couldn't see doing that (Or a reason) so in my mind I was looking at the RAW Values of the binary bumbers and thinking, "You can only get these one byte at a time", which is true.· But the Stamp BIN modifier is converting that sequence into a single byte, which is then put into an array element.· Just out of curiosity, why send the bits as ASCII values?· Why not send the actual binary value?· You would be sending a lot less data.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
· SERIN Sio, Baud, [noparse][[/noparse]NUM myValue]
... will accept "32" or "$20" or "%100000" and put the 32 into myValue.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax