CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Thu Jul 18, 2019 6:09 pm

All times are UTC+01:00

Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Nov 20, 2018 2:23 pm 

Joined: Wed Mar 01, 2017 3:07 pm
Posts: 8

I want to write a string to a file from a specific position. I use SysFileSetPos() from SysFile library to set the position. The thing is it works only when you open the file with write mode, and with write mode, It meanwhile overwrites the original content. I tried to use Append mode, but it always write to the end of the file.

So Is there any better solution for this. :D

   sTitleVersion := CONCAT(sTitle,'');
   sTitleVersion := CONCAT(sTitleVersion,'"');
   hFile := SysFile.SysFileOpen('/app/service/codesys/info.json', SysFile.ACCESS_MODE.AM_APPEND, pResult:= ADR(udiPosError));
   udiPosError := SysFile.SysFileSetPos(hFile,23);
   SysFile.SysFileWrite(hFile, ADR(sTitleVersion), INT_TO_UINT(STANDARD.LEN(sTitleVersion)), pResult:= ADR(udiPosError));

PostPosted: Tue Nov 20, 2018 4:39 pm 
Frequent User
Frequent User

Joined: Fri Feb 23, 2018 3:41 pm
Posts: 142
If you need to modify your file data, access_mode should always be write.

Then, your problem is about inserting some bytes in your filestream at specified position.
You may then create a new file, write the part of your file before the position where you will insert. Then write your new data, then write the lasting data from previous file.
Delete old file and rename new.

That's no point elegant but may solve it.

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00

Who is online

Users browsing this forum: Andreas Kehrer and 6 guests

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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited