SD card question
g3cwi
Posts: 262
Hi there
I need to read records from a card, manipulate and select a few and write them to a new file. Mike Green suggested that I need to have two copies of fsrw running to do this efficiently (at least I understood it that way). Do I therefore declare two objects i.e.
SDR: "fsrw"
SDW: "fsrw"
Do I need to mount the card etc for each? Can a card be opened for reading and writing by two instances of fsrw at the same time? If not, why do I need two running?
No doubt this is obvious to someone - but not to me!
Regards
Richard
I need to read records from a card, manipulate and select a few and write them to a new file. Mike Green suggested that I need to have two copies of fsrw running to do this efficiently (at least I understood it that way). Do I therefore declare two objects i.e.
SDR: "fsrw"
SDW: "fsrw"
Do I need to mount the card etc for each? Can a card be opened for reading and writing by two instances of fsrw at the same time? If not, why do I need two running?
No doubt this is obvious to someone - but not to me!
Regards
Richard
Comments
I am now trying to use the GPS_IO_Mini technique to read in the records for processing. The first thing I spotted was an error in GPS_IO_Mini whereby the array gps_buff is declared as a byte but cleared using longfill - in fact longfill seems to have the incorrect syntax anyway as using the correct syntax crashes the program. This has all sorts of potentially unwanted consequences. My code is:
I was sort of hoping this would (as a test) read the dats from the CSV file:
G/SP-004,559,1779895,1432603
G/SP-013,385,1779537,1431506
G/SP-015,343,1778549,1431703
G/SP-001,636,1781278,1433843
G/SP-002,582,1781162,1435389
and print G/SP-004 to the TV. It does not work though, it just prints "G" lots of times.
Any ideas?
Cheers
Richard
How you save records is also how you read records. Did you save the data as a longs or as ASCII bytes? Post your database file.
Some good clues.
Processing the first record:
Recorda[0] = 559 and Recorda[1] = 1779895
I expected that Recorda[0] would be "G/SP-004" but for some reason it is not - but I feel close now!
Regards
Richard
Regards
Richard
Now the next challenge. My code processes 50,000 records (each with four fields). For each record it does a calculation (three calculations actually). Depending on the result of the calculation the record is either disguarded or needs to be kept in a new file on the SD card. The code that identifies the records is working fine.
There could be up to about 100 records that I need to keep. The SD card is read by fsrw and I cant see a pointer involved so I am guessing it is being read by clocking each byte out? If I detect a record that I want to save and try to save it, I am guessing that I will loose my place in the read file? So I need a method of saving records with one file open for reading and another open for writing.
Is this where I need two instances of fsrw or cant I have two files open on an SD card?
Expert advice welcome.
Thanks
Richard
PS my code takes 6 minutes to test all the records - seems mighty slow!
bytemove(sel_buff[selcnt],@r_buff,cptr)
...causes the program to crash
As does the end of file detection (EOF). Any thoughts on how best to do these?
Regards
Richard
Regards
Richard
I agree with Dave. You should take a closer look at your code.
sel_buff is a long array. This loop is zeroing out 100 bytes in sel_buff each loop, but your startng address increments by 4 bytes each loop. Also, your last loop will zero out the 96 bytes after the sel_buff array.
It appears that you're treating sel_buff as if it were a 2 dimensional array of 100 elements with 100 bytes each. That would make it 10,000 bytes in size. Spin doesn't support 2 dimensional arrays, so you would need to do the 2D indexing yourself. You could declare sel_buff as "long sel_buff[2500]", and address each 100-byte chunk as @sel_buff[index*25], where index would have the range of 0 to 99. Is that what you intended?