Posted: Tue Nov 24, 2020 12:46 am Post subject: Statement: SEEK #bFileNumber, NewPos
Has anyone tested SEEK as a statement (To set the file pointer to a desired location)?
I can't make it work even in a simple example:
Code:
If Sd_card_ready =1Then ' Open File
P_file_handle =Freefile()
File_name1 ="Test11.bin"'********************************************************************** PUT HERE THE DESIRED FILE NAME Open File_name1 ForBinaryAs #p_file_handle
' Set starting at position =20
Ltemp =20 Seek #p_file_handle , Ltemp
Print #1 , "Gbdoserror="; Gbdoserror
' Write data at position 20
Btemp1 =33 Put #p_file_handle , Btemp1
Print #1 , "Data_byte pos=";Loc(#p_file_handle)' This must be 20 but it is 1 ¿? ' ----------------------------------------------------------------- ' Save data to SD Card and close file ' Flush #p_file_handle ' flush to disk (This is not needed. The data is already flushed when Closing the file) Close #p_file_handle
' ----------------------------------------------------------------- End If
What I expected this code to print is:
Quote:
Test SD Card
SD Card OK
Filesystem = 11
Gbdoserror=0
Data_byte pos=20
However it prints the following when the file is created (the first time I run the program)
Quote:
Test SD Card
SD Card OK
Filesystem = 11
Gbdoserror=0
Data_byte pos=1 This should be 20!
After this, everytime I run the program with the file is already created in the SD card, it prints the following:
Test SD Card
SD Card OK
Filesystem = 11
Gbdoserror=97 This error is cpFilePositionError
Data_byte pos=1 This should be 20!
Notes:
- I have tried to create files, subdirectories, write content to files, Dir the files and everything seems to work fine. It is just a problem with Seek as stratement.
- I'm using a XMEGA192A3U
- The complete code is posted at the end of https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=14714
- The SD card has been formatted with SD Card Formatter as suggested in BASCOM Help
- The card is a 4GB SDHC Card
- I have tried with a 16GB SDHC card and the result is the same, except that Filesystem = 12
The first step is always to read the help topic. In this case for SEEK.
It has an important note : In QB/VB you can use seek to make the file bigger. When a file is 100 bytes long, setting the file pointer to 200 will increase the file with 0 bytes. By design this is not the case in AVR-DOS.
So if you want to create files of certain size, you must do so explicit by writing to the file. _________________ Mark
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum