LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from Log files

Hi, I'm trying to read data from some log files line by line, but the Line buffer is never enough even if I put 1000000, who might know the solution fatal.PNG?

0 Kudos
Message 1 of 9
(4,304 Views)

Your first parameter of ReadLine seems to be wrong, it should be the file handle obtained by calling OpenFile, not a constant...

0 Kudos
Message 2 of 9
(4,283 Views)

Yes ! I rectified that!

if(GetFirstFile (PathBuffer, 1, 1, 0, 0, 0, 0, fileName) == 0);

if(GetNextFile (fileName) == 0)
{ n = GetFileInfo(fileName,&size);
if (n == 0)
FmtOut("File does not exist.");
else
FmtOut("File size = %i[b0]",size);

if (FileHandle = OpenFile (fileName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII))
{
SetCtrlVal (panelHandle3, PANEL3_FILESUCCESS, "fichier ouvert");
ReadFile (FileHandle, LineBuffer, 10000);
SetCtrlVal (panelHandle3, PANEL3_FILESUCCESS, LineBuffer);
}

CloseFile(FileHandle);
//InsertListItem (panelHandle3, PANEL3_LISTBOX, -1, fileName, 0);
}
else
MessagePopup("error","file not found !");

******************************************************************************

Now Size ==0 and LineBuffer is showing 5 random caracters !! 

0 Kudos
Message 3 of 9
(4,273 Views)

I do not know your file contents (e.g., the first two lines of your log file could be useful) nor your PathBuffer so I only can guess. For example, I do not understand the purpose of your first line

if(GetFirstFile (PathBuffer, 1, 1, 0, 0, 0, 0, fileName) == 0);

Shouldn't there be a '{' instead of your ';' ?

In any case, what you could/should do is set breakpoints to verify that your code is doing what you expect it to do; e.g., did you verify that fileName is what you expect it to be?

0 Kudos
Message 4 of 9
(4,252 Views)

you're right I didn't give you much informations. It doesn't matter, all the files have data in them, I can see the fileName I am already using breakpoints, but what I am doubting of is what if .log files have specific libraries like .ini files ?? 

0 Kudos
Message 5 of 9
(4,247 Views)

ReadLine doesn't care about file contents, it is just interested in a linefeed character Smiley Wink

However, if you are using ini files you might want to have a look at the toolslib library inifile.fp

0 Kudos
Message 6 of 9
(4,238 Views)

Yes I already worked with .ini files, so do you have an idea of the best way to read .log files ??

0 Kudos
Message 7 of 9
(4,233 Views)

If it is a simple structure I would assume that your approach is fine: read one line, e.g. using ReadLine, and then scan this line using scanning functions such as sscanf or Scan to extract its contents

0 Kudos
Message 8 of 9
(4,228 Views)

Ok thank you, I will try that 🙂

0 Kudos
Message 9 of 9
(4,224 Views)