RobotStudio event

How to create a .csv file

Hello to all of you,
I'm new to ABB RAPID programming and this is my first post on this forum.

I am working on a program that should write a report file in .csv format, my question is: how is possible to change line between one "write" instruction and the next?
The following is the code I wrote:

VAR string ORA;
VAR string DATA;
VAR iodev MY_FILE;
VAR num zero:=1000;
VAR num K:=289;
VAR num app_calc:=0;
VAR num app_ch_mm:=0;
VAR num app_mm_abs:=0;
DATA:=CDate();
ORA:=CTime();
app_calc:=ANALOGIC_1-zero;
app_ch_mm:=app_calc/K;
app_ch_mm:= Round(app_ch_mm\Dec:=0);
TEST N_Point
    CASE 01:
        TPErase;
        Open "HOME:", \File:="Measure.csv", MY_FILE;
        Write MY_FILE, "CONTRÔLE BROCHES: RAPPORT DES VALEURS MESURÉ";
        Write MY_FILE, "Date: "+DATA+",,Heure: "+ORA;
        Write MY_FILE, "Trou N.,Nom de la variable,Valeur mesurée";
        Close MY_FILE;
        Ctrl_Pin_KO:=FALSE;
        setgo REG_01, app_ch_mm;
        IF app_ch_mm<Min OR app_ch_mm>Max THEN
            Ctrl_Pin_KO:=TRUE;
            SetDO REJECT_PIN_CTRL, 1;
        ENDIF
        Open "HOME:", \File:="Measure.csv", MY_FILE\Append;
        Write MY_FILE, "01,REG_01," \Num:=app_ch_mm;
        Close MY_FILE;
        TPWrite "REG_01="\Num:=app_ch_mm;
 
 CASE 02: 
        setgo REG_02, app_ch_mm;  
        IF app_ch_mm<Min OR app_ch_mm>Max THEN
            Ctrl_Pin_KO:=TRUE;
            SetDO REJECT_PIN_CTRL, 1;
        ENDIF
        Open "HOME:", \File:="Measure.csv", MY_FILE\Append;
        Write MY_FILE, "02,REG_02," \Num:=app_ch_mm;
        Close MY_FILE;
        TPWrite "REG_02="\Num:=app_ch_mm;
...
...
...
ENDTEST


Thanks for any tips you will give to me

Comments

  • Micky
    Micky ✭✭✭

    Hi,

    I am not sure if I understand your problem, but if you want to write several data into the same line, you can use the optional parameter "\NoNewLine" of the instruction "Write".

    In this case the line feed character that normally indicates the end of the text is omitted. 

    You have to reuse this argument NoNewLine as long as you will add no line break .

     

    Example:

    Write myFile,"Value1 ;"\num:=nValue1\NoNewLine;

    Write myFile,"Value2 ;"\num:=nValue2\NoNewLine;

    Write myFile,"Value3 ;"\num:=nValue3;

    The three values will be written into the same line of your text file.

    Best regards

    Micky

     

     

  • Hi Micky,
    thanks for your reply.
    My problem is exactly the opposite: what should I do to write a new line every time I put new data into my file?

    With the option "\NoNewLine" I write all the data on a single line.
    Without this option I was thinking that there is some difference but... when I open the file using the Notepad in Windows7 I can't see any kind of change :-(

  • Klaus
    Klaus ✭✭
    Hi.

    Use wordpad insteed.

    BR Klaus
    Best Regards

    Klaus Soenderhegn
    www.cadalysator.dk
  • Neily03
    Neily03 ✭✭✭
    Like Klaus said use Wordpad or even Word, Notepad will display everything one line, we had the same problem here, thought we were going mad!
  •    
          
    \Append;  will start a new line

    Here in an example.....




    PROC   RECORD_THINGS()

        VAR string stDirNetwork_Parts:="pc:/asdf/Parts/";
        VAR  string stDirNetwork_Logs:="pc:/asdf/Logs/";
        VAR iodev ioCVB_LOG;
        VAR iodev ioCVB_READ;
        VAR num A_number;   
        VAR num This_Cycle;   
        VAR num lineCounter := 0;   
        VAR string FILE_WORDS;    
        VAR string LOG_RECORD;    
        VAR string This_Average;
        VAR string  whichLOG := "123456.csv";


    !!!    RECORD ALL OF THE THINGS    !!!!
         
            Open    stDirNetwork_Logs\File:= WhichLog, ioPPFP_LOG\Append;

            Write ioPPFP_LOG, What_Part + "," + CDATE()+"," + CTime() +"," +   This_Average +","\NoNewLine;
            Write ioPPFP_LOG,  "," + "Machine Total  =  "  \num:=Machine_Count;
            
            Close ioPPFP_LOG;
     
    !!!!    DONE RECORDING ALL OF THE THINGS    !!!!     
       
    ENDPROC
  • DenisFR
    DenisFR ✭✭✭
    Hello,
    RAPID use Unix End Of Line ASCII 10 (LF) while Windows use 13 + 10 (CR LF) and MAC 13 (CR).
    You can install Noteped++ to edit your files. It's free and open source.
    If you really want to have Windows EOL, you can do it like this:
    <div>VAR num eol{2}:=[13,10];</div><div>...<br></div><div>  Write ioPPFP_LOG, "Your text here"\NoNewLine;</div><div>  WriteBin ioPPFP_LOG, eol, 2;<br></div>...<br>
    Or
    ...
    <div>VAR string sEOL;<br></div><div>...</div><div>&nbsp; sEOL:=ByteToStr(13\Char)+ByteToStr(10\Char);;<br></div><code><div>&nbsp; Write ioPPFP_LOG, "Your text here" + sEOL\NoNewLine;</div>