Beckhoff twincat. Remove string from the file

anykey

Member
Join Date
Dec 2014
Location
Sibir
Posts
3
Hello! Sorry, my english is poor:rolleyes:

Please tell me how to remove the line from the file. The library TsSistem no suitable function.
Can be used spool file, but this variant not pleasant to me.

Thanks in advance!
 
I guess the question is this: there is a text file. The topicstarter would like to open it, find and remove a certain text string from it, and then save the file back.
 
OK. What you have to do is use the use the functions SysFileOpen, SysFileRead (to read the file), SysFileWrite (to write the file back to disk), and SysFileClose. These are all parts of the basic CoDeSys installation.

Aside from that, before we go any further it would be helpful if you could post the contents of a file. There are several variables that will effect how we treat it and seeing the file will really help.

Good Luck,

Yosi
 
LadderLogic
Thanks! Nearly so. The principle of the queue. When filling the log files of a certain number of entries, the first is removed - FIFO

OK. What you have to do is use the use the functions SysFileOpen, SysFileRead (to read the file), SysFileWrite (to write the file back to disk), and SysFileClose. These are all parts of the basic CoDeSys installation.
I know that:book:

Test program (while bRun =true, the recording process in the image lines)



Code:
PROGRAM recs
VAR
   file: INT;
   bRun: BOOL;
   fbFileOpen: FB_FileOpen;
   fbFileWrite: FB_FilePuts;
   fbFileClose: FB_FileClose;
  str: STRING;
  ii:BYTE;
END_VAR

CASE file OF
   0:
      IF bRun THEN
         file :=1;
      END_IF;

   1:
      fbFileOpen(
         sNetId := ,
         sPathName := 'hard disk\file11.txt',
         nMode := FOPEN_MODEWRITE OR FOPEN_MODETEXT,
         ePath := PATH_GENERIC,
         bExecute := TRUE,
         tTimeout := t#1s);

      IF NOT(fbFileOpen.bError) THEN
         IF fbFileOpen.hFile <> 0 AND NOT(fbFileOpen.bBusy) THEN
            fbFileOpen(bExecute := FALSE);
            file :=2;
         END_IF;
      END_IF;

   2:
         str := CONCAT(BYTE_TO_STRING(ii),'; blah-blah-blah;$L');
    ii:=ii+1;
      fbFileWrite(
         sNetId := '',
         hFile := fbFileOpen.hFile,
         sLine := str,
         bExecute := TRUE,
         tTimeout := t#5s);
      file := 3;

   3:
      IF NOT(fbFileWrite.bError) THEN
         IF NOT(fbFileWrite.bBusy) THEN
            fbFileWrite(bExecute := FALSE);
            file := 4;
         ELSE
            fbFileWrite(bExecute := TRUE);
         END_IF;
      END_IF;

   4:
      IF bRun THEN
         file := 2;
      ELSE
         file := 5;
      END_IF;

   5:
       fbFileClose(
         sNetId := '',
         hFile := fbFileOpen.hFile,
         bExecute := TRUE,
         tTimeout := t#1s);

      IF NOT(fbFileClose.bError) THEN
         IF NOT(fbFileClose.bBusy) THEN
            fbFileClose(bExecute := FALSE);
            file := 0;
         END_IF;
      END_IF;

END_CASE;
Uff. I hope understandable:D
 

Similar Topics

Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
1,032
Hello, I was wondering if anyone know how to upload a PLC program to the Beckhoff TwinCAT 3 from a file? i.e. without having the development pc...
Replies
0
Views
760
Hi anyone got any tips and tricks?? I'm at a stage wherei need to tidy up my hmi project and give all objects sensible names, I did start this...
Replies
0
Views
964
Hello, I have a System running a beckhoff IPC with twincat 2 software on it, Also i have no original source code. Is it possible with the...
Replies
1
Views
1,269
Hi all, I've inherited someone else's program and can't for the life of me figure out his use of the # symbol in one of his structured text...
Replies
5
Views
1,924
Back
Top Bottom