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

CSV - Line writing trigger; FB_FilePuts Error 1795; SFC/ST

2019-01-09
2019-01-14
  • Vijolica555 - 2019-01-09

    Hello guys,

    I opened a topic "SFC jumping steps - TwinCAT" yesterday but did not get any answer - also i think it is not possible to jump steps in SFC as i hoped so i need to find a different solution. First what my problem is:
    I generate .csv File where lines look like:
    "RunningNo";"UTCTimeStamp";"StingInput1";"StringInput2";"StringInput3";"Measuredvalue1";"MeasuredValue2";"MeasuredValue3"

    RunningNo is with every line +1;
    UTC TimeStamp is time when we measured our Value or when we save a line;
    StringInput1 is place of machine or smt where measurement is made;
    StringInput2 is name of measurement that is made;
    StringInput3 is group of measurement that is made;
    Measuredvalue1 is value that we measure.

    For this file i measure Errors. I get 1 when error happend and 0 when it is not. Till now i cyclicly measured values - every minute.
    Now would i like to save a line ONLY WHEN ERROR HAPPENS - SO WHEN OUR VALUE IS 1 (TRUE).
    Ex:
    "560";"1542027630";"StingInput5";"Error5";"Stingkey";"1";"";""
    "561";"1542027631";"StingInput8";"Error8";"StingKey";"1";"";""
    "562";"1542027690";"StingInput9";"Error9";"StingKey";"1";"";""
    "563";"1542027750";"StingInput5";"Error5";"StingKey";"1";"";""
    "564";"1542027810";"StingInput1";"Error1";"StingKey";"1";"";""

    I have 43 different errors that can happen: That is from Error 1 to Error 43.

    I generaded .csv til now like SFC - example on picture. LineToWrite is string which i want to write in every line.

    So.. Do you have any ide how to save a line only when Error happens?
    Since in SFC I can not jump a step i tried to write ST, but i get an Error at FB_FilePuts: ErrorID 1795: invalid index offset.

    So does anymody have any idea how to change SFC or what can cause an error at ST at FB_FilePuts? Thank you

    Here is example of new code wehre i get an error at FB_FilePuts:

    CASE nStep OF
       0: 
          IF rtStart.Q THEN
             bStart := FALSE;
             q_bFinished := FALSE;
             nStep := 1;
          END_IF
          
       1: 
          fbFileOpen(
             sNetId      := '', 
             sPathName   := sPathName, 
             nMode      := (FOPEN_MODEAPPEND OR FOPEN_MODETEXT), 
             ePath      := PATH_GENERIC,  
             tTimeout   := DEFAULT_ADS_TIMEOUT,
             bExecute := TRUE);
          IF NOT fbFileOpen.bBusy THEN 
          fbFileOpen.bExecute := FALSE;
          nStep := 2; 
          END_IF
          
       2:
          IF Error1 THEN
             LineToWrite1_active();
             fbFilePuts(
                sNetId   := '', 
                hFile   := fbFileOpen.hFile, 
                sLine   := CONCAT(sLineToWrite,'$N'),
                bExecute := TRUE);
             IF NOT fbFilePuts.bBusy THEN 
                fbFilePuts.bExecute := FALSE;
                nLineIdex := nLineIdex +1;         
                nStep := 3; 
             END_IF 
          ELSIF NOT Fehler_ST_0010 THEN 
             nStep := 3;
          END_IF
       3:
          IF Error2 THEN
             LineToWrite2_active();
             fbFilePuts(
                sNetId   := '', 
                hFile   := fbFileOpen.hFile, 
                sLine   := CONCAT(sLineToWrite,'$N'),
                bExecute := TRUE);
             IF NOT fbFilePuts.bBusy THEN
                fbFilePuts.bExecute := FALSE;
                nLineIdex := nLineIdex +1;            
                 nStep := 4; 
             END_IF 
          ELSIF NOT Fehler_ST_0015_00 THEN 
             nStep := 4;
          END_IF
       4:
          IF Error3 THEN
             LineToWrite2_active();
             fbFilePuts(
                sNetId   := '', 
                hFile   := fbFileOpen.hFile, 
                sLine   := CONCAT(sLineToWrite,'$N'),
                bExecute := TRUE);
             IF NOT fbFilePuts.bBusy THEN
                fbFilePuts.bExecute := FALSE;
                nLineIdex := nLineIdex +1;            
                 nStep := 5; 
             END_IF 
          ELSIF NOT Fehler_ST_0020 THEN 
             nStep := 5;
          END_IF
          
       5:
          nStep := 50;
       50: 
          fbFileClose(
             sNetId   := '', 
             hFile   := fbFileOpen.hFile,
             bExecute := TRUE);
          IF NOT fbFilePuts.bBusy THEN 
             fbFileClose.bExecute := FALSE;
             nStep := 60; 
          END_IF 
          
       60:
          q_bFinished := TRUE;
          bStart := FALSE;
          nStep := 0;
          
    END_CASE
    

    IMG: 1.png

     
  • Vijolica555 - 2019-01-09

    Hello,

    So my solution was parallel bench for every line where transition is RT_TRIG Error1,... I have 43 parallel steps so i took time to do ti but is working. If anyone have quicker solution i would still like to hear it eventhough this is working fine.
    Why i had problem a long time is that i did not know what is the difference between alternative and parallel bench. This doc. helped me: https://assets.omron.eu/downloads/manua ... ide_en.pdf m

    IMG: 1.png

     
  • dFx

    dFx - 2019-01-14

    In general, coders tends to be lazy. If you may reuse some code, then do it. (copy paste edit fails are frequent)
    For this code, if "Fehler_ST_0020" is a fault bit, do some code or place it directly in a boolean array.
    Then just code your error logging block for each array item in a loop. This will reduce 43 steps in 1 slightly bigger.

    That said, you should know that working with files is slow, so opening and closing cyclicaly a file is something I dont recommend.
    Maybe you could just open it once, then close it to copy it over some media.

    Your ST code error may be dues to severall simultaneous write at a time in your file.

     

Log in to post a comment.