2021年5月2日星期日

TwinCAT3: Data written into .txt file has gibberish together with actual values. How do I prevent this from happening?

I am currently running a file writer function block to save data being generated from my system. The data is put into an array of strings and then using File_Write is written into a text file. However, the end result shows gibberish together with the data I want.

Image of data captured: Data in text file(Numbers are the date I want)

File writing code I use:

    fbRisingEdge(CLK := bExecute);  CASE Step OF      0 :          IF fbRisingEdge.Q THEN              nFileHandle := 0;              bBusy := TRUE;              Step := 1;          END_IF                1 :          fbFileOpen(sPathName := sPathName, bExecute := FALSE);          fbFileOpen(sPathName := sPathName, nMode := nMode, bExecute := TRUE);          Step := 2;      2 :          fbFileOpen(bExecute := FALSE);          IF NOT fbFileOpen.bBusy THEN              IF fbFileOpen.bError THEN                  bError := TRUE;                  Step := 10;              ELSE                  nFileHandle := fbFileOpen.hFile;                  Step := 3;              END_IF          END_IF                3 :          fbFileWrite(bExecute := FALSE);          fbFileWrite(hFile := nFileHandle, pWriteBuff := ADR(GVL.sData), cbWriteLen := SIZEOF(GVL.sData), bExecute := TRUE);          Step := 4;      4 :          fbFileWrite(bExecute := FALSE);          IF NOT fbFileWrite.bBusy THEN              IF fbFileWrite.bError THEN                  bError := TRUE;                  Step := 10;              ELSE                  Step := 5;                  nBytesWritten := fbFileWrite.cbWrite;              END_IF          END_IF        5 :          fbFileClose(bExecute := FALSE);          fbFileClose(hFile := nFileHandle, bExecute := TRUE);          Step := 6;      6 :          fbFileClose(bExecute := FALSE);          IF NOT fbFileClose.bBusy THEN              IF fbFileClose.bError THEN                  bError := TRUE;              END_IF              Step := 10;              nFileHandle := 0;          END_IF        10 :          IF nFileHandle <> 0 THEN              Step := 6;          ELSE              Step := 0;              bBusy := FALSE;          END_IF  END_CASE  
https://stackoverflow.com/questions/67362737/twincat3-data-written-into-txt-file-has-gibberish-together-with-actual-values May 03, 2021 at 10:07AM

没有评论:

发表评论