Data Output with Memory Stick Datalogger
Hi,
I want to write some data in a file. The datafile.txt is opened in front of this programm.
===========================================================
EEPROM DATA
Name0·········· DATA··· "BOLTS M1", CR, 0
Name1·········· DATA··· "NUTS", CR, 0
===========================================================
===========================================================
' Write tagid value to file.txt
· DEBUG "Writing start", CR
· PAUSE 250
· LOOKUP tagNum,
········ [noparse][[/noparse]Name0, Name1], idx··················· ' point to first character
· DO
··· READ idx, char································ ·' read character from name
··· IF (char = 0) THEN EXIT···················· ' if 0, we're done
··· DEBUG char, CR························· ····· ' otherwise print it
··· SEROUT TX\CTS, Baud2, [noparse][[/noparse]"WRF ", $00, $00, $00, $05, CR, DEC5 char, CR]
········· ·············································· ' more text on line 2.
··· idx = idx + 1······················· ············ ' point to next character
· LOOP
· DEBUG "Storing finished", CR
· GOSUB Get_Serial_Bytes
=================================================================
My problem is, that I do not understand the commands with a "$". Has anybody a hint for me for understanding this?
Or is there a better possibility to write·Name0 or Name1 in a File with the Memory Stick Datalogger?
·
I want to write some data in a file. The datafile.txt is opened in front of this programm.
===========================================================
EEPROM DATA
Name0·········· DATA··· "BOLTS M1", CR, 0
Name1·········· DATA··· "NUTS", CR, 0
===========================================================
===========================================================
' Write tagid value to file.txt
· DEBUG "Writing start", CR
· PAUSE 250
· LOOKUP tagNum,
········ [noparse][[/noparse]Name0, Name1], idx··················· ' point to first character
· DO
··· READ idx, char································ ·' read character from name
··· IF (char = 0) THEN EXIT···················· ' if 0, we're done
··· DEBUG char, CR························· ····· ' otherwise print it
··· SEROUT TX\CTS, Baud2, [noparse][[/noparse]"WRF ", $00, $00, $00, $05, CR, DEC5 char, CR]
········· ·············································· ' more text on line 2.
··· idx = idx + 1······················· ············ ' point to next character
· LOOP
· DEBUG "Storing finished", CR
· GOSUB Get_Serial_Bytes
=================================================================
My problem is, that I do not understand the commands with a "$". Has anybody a hint for me for understanding this?
Or is there a better possibility to write·Name0 or Name1 in a File with the Memory Stick Datalogger?
·
Comments
The four hex values prior to the CR is the Hex size of the data in bytes you are writing to the file.
To get your code to work, remove the DEC callout from char - you want the ascii code, not the equivalent binary. (if Name0 is text)
The following code will write one byte with the ascii code of char to the file:
SEROUT TX\CTS, Baud2, [noparse][[/noparse]"WRF ", $00, $00, $00, $01, CR, char, CR]
See http://www.parallax.com/dl/docs/prod/comm/VDAPFirmwareSpec.pdf·for the list of cammands and their syntax.
thanks for your answer. But what is the size of the data in bytes I am writing to the file? How can I calculate the size (Name0 is text with numbers and letters)?
What is the easiest way to write a word with 6-8 letters or numbers in a file?
Another question: I have some data in the EEPROM (example: TEST DATA "392DS2"), and know I want to read out the second character. Is there a possibility in PBASIC to access a certain place of the stored data TEST? Something like TEST=9....
You can loop through the write statement as you have done until you get to the end character (0, as you have here). That way it does not matter how long the string is.
Use lookup as you have done, then add to it the position in the string you want to read. READ (idx+location),Char
address VAR Byte
string VAR Byte(15)·· 'array for data =13 bytes + length + terminating 0
idx VAR Byte
len VAR Nib
x VAR Nib·· 'this variable is to test with and·expects the item number 0 or 1
DEBUGIN DEC x
Name0 DATA "BOLTS M1",8,0·· 'including the space bytes to write=8
Name1 DATA "NUTS",4,0········ 'bytes to write=4
LOOKUP x,[noparse][[/noparse]Name0,Name1],address
DO
READ address,string(idx)
len=string(idx-1)
IF string(idx)=0 THEN EXIT
idx =idx+1
address=address+1
LOOP
DEBUG STR string \len ,CR,"LENGTH IN BYTES=",DEC len
To write to the logger you would use the len variable to control the number of bytes you want to write
SEROUT TX\CTS, Baud2, [noparse][[/noparse]"WRF ", $00, $00, $00, DEC len, CR, STR string\len, CR]
Jeff T.
okay. I did it in the same way like you. The rfid.txt is created. But the file is empty, Notepad shows me nothing. If you say, your program should run, then the mistake have to be in another part of the saving procedure. I copied the hole procedure:
====================================================
'Variables:
buf·········· VAR···· Byte(10)··············· ' RFID bytes buffer····
address·····VAR···· Byte
idx2········· VAR···· Byte
len·········· VAR····· Nib
====================================================
Store:
' Delete rfid.txt if one exists, ignore error if no file exists
DEBUG "Delete rfid.txt start", CR
PAUSE 500
SEROUT TX\CTS, Baud, [noparse][[/noparse]"DLF rfid.txt", CR]
GOSUB Get_Serial_Bytes
GOSUB Purge ' Purge Buffer
DEBUG "Delete rfid.txt done", CR
' Open rfid.txt for output (write)
DEBUG "Open File for Output start", CR
PAUSE 250
SEROUT TX\CTS, Baud, [noparse][[/noparse]"OPW rfid.txt", CR]
GOSUB Get_Serial_Bytes
DEBUG "Open file for Output Done", CR
'Write tagid value to rfid.exe
DEBUG "Writing starts", CR
PAUSE 250
LOOKUP tagnum,[noparse][[/noparse]Name0,Name1],address
DO
READ address,buf(idx2)
len = buf(idx2 - 1)
IF buf(idx2) = 0 THEN EXIT
idx2 = idx2 + 1
address = address + 1
LOOP
DEBUG STR buf \len ,CR,"LENGTH IN BYTES=",DEC len, CR
SEROUT TX\CTS, Baud, [noparse][[/noparse]"WRF ", $00, $00, $00, DEC len, CR, STR buf\len, CR]
DEBUG "Storing finished, RFID Reader ready", CR
GOSUB Get_Serial_Bytes
' Close rfid.txt
DEBUG "Closing start", CR
PAUSE 250
SEROUT TX\CTS, Baud, [noparse][[/noparse]"CLF rfid.txt", CR]
GOSUB Get_Serial_Bytes
GOSUB Purge ' Purge Buffer
DEBUG "Closing Finished", CR
===============================================
The program runs until the end. And the line "DEBUG STR buf \len ,CR,"LENGTH IN BYTES=",DEC len, CR" works perfect. Only the created file rfid.txt is empty.
Has anybody a suggestion?
Post Edited (tobimersi) : 10/31/2007 5:25:22 PM GMT
One·difference is that I am using the shortened command set ("SCS"). This makes dealing with some of the logger commands easier to handle but a little less intuitive. I countered that by making the commands I used constants
Also there is no CTS/RTS flow control, the pin assignments are RX=pin0 and Tx=pin1, CTS is connected to VSS , RTS is not connected. Flow control is achieved by waiting for the return of the command prompt (">")
The program was tested on a BS2px ,so the baud constant will need altering to suit the Stamp you are using.
When you download the program and get the "Ready for input" insert the flash memory and wait for the memory activity light to stop blinking, then input a value between 0 and 2. There is no delete routine so each time you write you will need to delete the file before trying again.
You may not wish to use this method and if you don't then I hope you read it and possibly get something out of it. Read the FTDI docs regarding the short command set.
Jeff T.
Is there everywhere a explanation of the "serout"-function?
SEROUT, along with all the other PBASIC commands, is described both in the PBASIC Reference Manual and in the PBASIC Help File. The former can be downloaded from the documentation section of the Parallax web site. The latter is a part of the PBASIC IDE.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔