CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Thu Aug 16, 2018 7:31 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Sep 25, 2017 8:58 am 
Offline

Joined: Wed Jun 08, 2016 12:03 pm
Posts: 52
Hi!

I am trying to write "a;" to a csv file, but the results is the picture below.

I think this is a bug. I have posted my code here. If you want to try this code. You can replace this code line

Code:
sFileName := Standard.CONCAT(sFileName, '.csv'); // <-- Change fileName here if you want to try


Whith your file location.

If I use this code
Code:
[code]sendText := STANDARD.CONCAT('a', ';'); // <-- Why does this not working?[/code]


it will not working for me. But if I use
Code:
sendText :='a;'.


It works perfect. Why? It is the same if I set the code as

Code:
sendText := SQL_Array_Text[i];


I get garbarge values too. Why?

Code:
PROGRAM SparaDataTillSQL
VAR
        xFileStdInit:       BOOL:=FALSE;
        uiFileStdState:     UINT:=0;
        sFileName:          CAA.FILENAME;
        hFile:              CAA.HANDLE;
        szFileSize1:        CAA.SIZE := 0;
        szFileSize2:        CAA.SIZE := 0;
        filop:              FILE.Open;
        filwr:              FILE.Write;
        filrd:              FILE.Read;
        filcl:              FILE.Close;
        filsp:              FILE.SetPos;
      Date_and_time_format: DATE_AND_TIME;
      datumNamn: STRING;
      SQL_Array_Text: ARRAY[0..1024] OF STRING;
      // Räknare
      i: INT;
   // Texten som skall skickas
   sendText: STRING;
END_VAR


IF NOT xFileStdInit THEN
   filop(xExecute:=FALSE);
    filcl(xExecute:=FALSE);
    filwr(xExecute:=FALSE);
    //filrd(xExecute:=FALSE);
   xFileStdInit:=TRUE;
    uiFileStdState:=0;
   
   //Skapa filnamn
   datumNamn := DT_TO_STRING(Date_and_time_format);
   datumNamn := STANDARD.REPLACE(datumNamn,'_', 1, 17); // Här tar vi bort :
   datumNamn := STANDARD.REPLACE(datumNamn,'CC', 1, 20); // Samma här också.
   sFileName := Standard.CONCAT('\FlashDrive\Project\Project Files\Reports\FTP_Get\',datumNamn);
   sFileName := Standard.CONCAT(sFileName, '.csv'); // <-- Change fileName here if you want to try
   
   // Skapa en lång array med värden som skall loggas
   SQL_Array_Text[0] := GVL.Ordernummer;
   SQL_Array_Text[1] := GVL.VentilNamn;
   SQL_Array_Text[2] := GVL.SerieNummer;
   SQL_Array_Text[3] := GVL.VentilPort;
   SQL_Array_Text[4] := INT_TO_STRING(GVL.TestNummer);
   SQL_Array_Text[5] := GVL.FlodesInstallning;
   SQL_Array_Text[6] := GVL.TryckInstallning;
   SQL_Array_Text[7] := GVL.LastInstallning;
   SQL_Array_Text[8] := GVL.Operator;
   SQL_Array_Text[9] := INT_TO_STRING(GVL.MaxFlode);
   SQL_Array_Text[10] := GVL.VentilTyp;
   SQL_Array_Text[11] := BOOL_TO_STRING(GVL.Externt_Lackage);
   SQL_Array_Text[12] := BOOL_TO_STRING(GVL.Hysterestest);
   SQL_Array_Text[13] := LREAL_TO_STRING(GVL.Hysteresvarde);
   SQL_Array_Text[14] := BOOL_TO_STRING(GVL.Shuntslidkarvning);
   SQL_Array_Text[15] := REAL_TO_STRING(GVL.Shuntslidkarvningvarde);
   SQL_Array_Text[16] := BOOL_TO_STRING(GVL.Backventillackage);
   SQL_Array_Text[17] := REAL_TO_STRING(GVL.Backventillackagevarde);
   SQL_Array_Text[18] := BOOL_TO_STRING(GVL.Slidlackage);
   SQL_Array_Text[19] := REAL_TO_STRING(GVL.Slidlackagevarde);
   SQL_Array_Text[20] := BOOL_TO_STRING(GVL.Shuntlackage);
   SQL_Array_Text[21] := REAL_TO_STRING(GVL.ShuntlackageVarde);
   
   //
   
   
   
ELSE
    CASE uiFileStdState OF
        0:(* create a new file *)
            filop.sFileName:=sFileName;
            filop.eFileMode:=FILE.MODE.MRDWR;
            filop.xExclusive:=TRUE;
            filop( xExecute:=TRUE);
            IF filop.xDone THEN
                hFile:=filop.hFile;
                uiFileStdState:=1;
            END_IF
            IF filop.xError THEN
                (* error handling*)
                ;
            END_IF

        1:(* write text in the file *)
            filwr.hFile:=hFile;
            filwr.pBuffer:=ADR('#,');
            szFileSize1:=SIZEOF('#,');
            filwr.szSize:=szFileSize1;
            filwr.udiTimeOut:=100000;    (* 100ms Timeout *)
            filwr( xExecute:=TRUE);
            IF filwr.xDone THEN
                uiFileStdState:=4;
            END_IF
            IF filwr.xError THEN
                (* error handling*)
                ;
            END_IF


        4:(* close file  - TestFile.txt *)
            filcl.hFile:=hFile;
            filcl( xExecute:=TRUE);
            IF filcl.xDone THEN
                uiFileStdState:=5;
            filop(xExecute:=FALSE);
            filcl(xExecute:=FALSE);
            filwr(xExecute:=FALSE);
            END_IF
            IF filcl.xError THEN
                (* error handling*)
                ;
            END_IF

        5: (* Open - Append mode *)
         filop.sFileName:=sFileName;
            filop.eFileMode:=FILE.MODE.MAPPD;
            filop.xExclusive:=TRUE;
            filop( xExecute:=TRUE);
            IF filop.xDone THEN
                hFile:=filop.hFile;
                uiFileStdState:=6;
            END_IF
            IF filop.xError THEN
                (* error handling*)
                ;
            END_IF
      6:(* write text in the file *)
            filwr.hFile:=hFile;
         sendText := STANDARD.CONCAT('a', ';'); // <-- Why does this not working?
            filwr.pBuffer:=ADR(sendText);
            szFileSize1:=SIZEOF(sendText);
            filwr.szSize:=szFileSize1;
            filwr.udiTimeOut:=100000;    (* 100ms Timeout *)
            filwr( xExecute:=TRUE);
            IF filwr.xDone THEN
                IF( i < 20) THEN
               i := i + 1;
            ELSE
               uiFileStdState:=8;
            END_IF
            filwr(xExecute:=FALSE);
            END_IF
            IF filwr.xError THEN
                (* error handling*)
                ;
            END_IF
         
      8:(* close file  - TestFile.txt *)
            filcl.hFile:=hFile;
            filcl( xExecute:=TRUE);
            IF filcl.xDone THEN
            filop(xExecute:=FALSE);
            filcl(xExecute:=FALSE);
            filwr(xExecute:=FALSE);
                uiFileStdState:=9;
            //i := 0;
            END_IF
            IF filcl.xError THEN
                (* error handling*)
                ;
            END_IF
      9: (* Nothing *)
         ;
         
    END_CASE
END_IF



You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Mon Sep 25, 2017 12:18 pm 
Offline

Joined: Wed Jun 08, 2016 12:03 pm
Posts: 52
Hello!

I found the solution to this problem!

Insted of

Code:
szFileSize1:= SIZEOF(sendText);


Use

Code:
szFileSize1:= INT_TO_UINT(STANDARD.LEN(sendText));


Moderator need to report this so the online help shows correct example.


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: No registered users and 1 guest


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