Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Read byte from a file starting from a certain position

2018-06-14
2018-06-14
  • varrialeciro - 2018-06-14

    Hi all,
    I'm early approaching to PLC programming, and I'm trying to do a simple task like to read a file.

    I used the classic example with SysFile library and the program work correctly, so I can read all bytes of the file, convert them to string and parse all the stuff. Ok.

    This work only if the file's size is lower then 1000 bytes, because the maximum size of the array used to contain the bytes of the file can be 1000, in particular I have an ARRAY[0..MAX_BUFFER] OF BYTE, where MAX_BUFFER is 999.

    Obviously, I tried to increase the value of MAX_BUFFER but the array's size keep to be 1000. This means that the array can have maximum size 1000.

    So I thought to read, every PLC scan, chunk of the file and not the whole file. But the SysFileRead don't give me the possibility to start to read from a different byte. Seems that the function starts always from the first byte. So I have not the possibility to scroll the file.

    BytesRead := SysFileRead(hFile:=FileHandle, pbyBuffer:=pFileData, ulSize:=MAX_BUFFER, pResult:=pResult);

    The two parameters controllable are pbyBuffer (where I put the data readed) and ulSize (how many data I want to read). There is no an index or something like that.

    Someone can help me?

    Thanks a lot!

     
  • varrialeciro - 2018-06-14

    Solved, using this: SysFile.SysFileSetPos

    Thanks

     

Log in to post a comment.