Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Statement: SEEK #bFileNumber, NewPos

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS
View previous topic :: View next topic  
Author Message
hzz

Bascom Member



Joined: 20 Feb 2007
Posts: 314

spain.gif
PostPosted: Tue Nov 24, 2020 12:46 am    Post subject: Statement: SEEK #bFileNumber, NewPos Reply with quote

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 = 1 Then
'     Open File
      P_file_handle = Freefile()
      File_name1 = "Test11.bin"                             '********************************************************************** PUT HERE THE DESIRED FILE NAME
      Open File_name1 For Binary As #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
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Nov 24, 2020 9:58 am    Post subject: Reply with quote

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
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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