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 Sat Dec 15, 2018 2:54 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 
Offline

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

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


Code:
   sTitleVersion := CONCAT(sTitle,'0.0.0.0');
   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));
   SysFile.SysFileClose(hFile);


Top
   
PostPosted: Tue Nov 20, 2018 4:39 pm 
Offline

Joined: Fri Feb 23, 2018 3:41 pm
Posts: 67
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.


Top
   
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