Announcement

Collapse
No announcement yet.

File_Open, File_Read and file name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • John Kevin
    commented on 's reply
    As far as I know, there should be no distinct difference with regards to speed. However, you can create a timer between the function and check for the results.

  • Vincent44
    replied
    Originally posted by John Kevin View Post
    Hello,


    Yeah, that method is more efficient. If you can modify your text file again you can set your pointer directly using the command


    ​​​​​​​
    Code:
    file_Seek(handle,HiWord,LoWord);
    Code:
    file_Index(handle,HiSize, LoSize , recordnum );
    Best Regards,
    Kevin

    Yes, that's what I did.
    I don't really understand the difference between the two commands though.

    Is one of them fastest than the other ?

    Leave a comment:


  • John Kevin
    replied
    Hello,
    In the end, I modified my text file, to store some indexes at the begining. Bascially, the first data in the file is the location of the line 250, 500, 1000. I can read those information, and directly set my file pointer to the closest location. Then, from there, I read each line until I reach the one I need.
    Yeah, that method is more efficient. If you can modify your text file again you can set your pointer directly using the command


    ​​​​​​​
    Code:
    file_Seek(handle,HiWord,LoWord);
    Code:
    file_Index(handle,HiSize, LoSize , recordnum );
    Best Regards,
    Kevin


    Leave a comment:


  • Vincent44
    replied
    Hi,

    I started to read the file, line by line, until reaching the line I need. This works, but is not really efficient.

    Basically, I need to read some text from the file, to update the caption above a SmartSlider, according to the value of this slider. Since my file contains ~1500 I get a bit too much latency, which is not good for user exeperience.

    In the end, I modified my text file, to store some indexes at the begining. Bascially, the first data in the file is the location of the line 250, 500, 1000. I can read those information, and directly set my file pointer to the closest location. Then, from there, I read each line until I reach the one I need.

    Leave a comment:


  • John Kevin
    replied
    Hello,

    If I understood correctly, what you want to achieve is read a specific line on the file.

    As you have said,

    However, my lines do not all have the same number of char, which makes it hard to manage the file pointer directly.
    without knowing the address/uniform byte count on each line, it will be difficult to point it directly as you need to read it from top to bottom.

    What about reading only until the specified line was achieved? This is how I would implement it just in case you need it.

    Code:
    func ReadLine(var LineNumber)
        var filehndl;
        var lineNumber:=1;
        var readchar;
    
    
        filehndl:=file_Open("CAPTIO~1.txt",'r');
            repeat
                readchar:=file_GetC(filehndl);
    
                if(readchar == 0x0A) lineNumber++;
    
                if(lineNumber == LineNumber)
                    strLength := file_GetS(buff, 100, filehndl) ;
                    if(lineNumber == 1) print([CHR]readchar); //Offset for the first character
                    print([STR]buff);
                    readchar:=0x00;
                endif
    
            until (readchar == 0x00);
    
        file_Close(filehndl);
    endfunc

    Best Regards,
    Kevin
    Last edited by John Kevin; 23rd March 2019, 05:48 PM.

    Leave a comment:


  • Vincent44
    replied
    Hi Kevin,

    Thanks for the reply. I will manage my project according to these limitations.

    Another quick question concerning reading in file.
    I have formated some look-up tables in text files. These are rather large (~1600 lines), and therefore long to go through.
    My format is all based on lines : 1600 lines, corresponding to 1600 inputs. However, my lines do not all have the same number of char, which makes it hard to manage the file pointer directly.
    Is there any function to help me reaching a given line, whithout reading each line ?

    (hope that make sense)

    Leave a comment:


  • John Kevin
    replied
    Hello Vincent,

    To read the file which contains more than 8 characters, go to Command Prompt, change your directory (uSD Card), and type 'dir /x'.
    You can see there the filename which you can use in the Workshop4 to read the file.

    You can now use the file which should be something like this:

    Code:
    handle:=file_Open("CAPTIO~1.txt",'r');
    strLength := file_GetS(buff, 50, handle) ;
    print([STR]buff);
    file_Close(handle);
    Also, is it possible to open txt files, stored in subfolder ?
    Unforunately, you can only have access to the root folder of the uSD Card.


    I hope this helps.
    Best Regards,
    Kevin

    Leave a comment:


  • Vincent44
    started a topic File_Open, File_Read and file name

    File_Open, File_Read and file name

    Hello,

    I am facing a problme with opening/reading some text files stored on the SD card of the Gen4 Diablo.

    Using a simple code as below work fine
    Code:
    handle := file_Open("Mode1.txt", 'r');
    strLength := file_GetS(buff, 50, handle) ;
    print([STR]buff);
    file_Close(handle);
    However, as soon as my file name gets longer, it won't work.
    Code:
    handle := file_Open("Caption_Mode1.txt", 'r');
    strLength := file_GetS(buff, 50, handle) ;
    print([STR]buff);
    file_Close(handle);
    The limit seem to be about : 8 char, excluding the extension .txt

    Is there any workaround ?
    I am planning to store a ~150 reference files on my SD card, so being able to name them with a longer name could be nice.

    Also, is it possible to open txt files, stored in subfolder ?
    I tried something like above, but did not get any result. Might be the same file name length issue.
    Code:
    handle := file_Open(".\MySubFolder\Mode1.txt", 'r');
    Thanks.
Working...
X