LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I continuously read an update a .log File

Hi Everyone, 

 

I have external software which is continuously being logging data to Notepad(.log) text file.

 

The software buffers data 4 minutes. Therefore, I will need to wait 4 minutes before the first write operation and be able to see data on the text file.

 

I am trying to read that data from the same file in real time every 4 minutes. However, LabVIEW doesn't read the file unless I stop software from logging data, even though I can manually open the file and see the data logged for the past 4 minutes while the software is logging data for the next 4 minutes.

 

Here is the overall program code and offline .log file.

 

I would like to get some help please. Thank you.

 

  

 

o

Download All
0 Kudos
Message 1 of 10
(3,349 Views)

@LaAb wrote:

LabVIEW doesn't read the file unless I stop software from logging data, even though I can manually open the file and see the data logged for the past 4 minutes while the software is logging data for the next 4 minutes.


 

This is probably because if a program has a file open for writing (read/write) then a second program tries to open the file (read/write mode) it causes a file sharing violation. 

 

BTW: This has been true since DOS.

 

Two suggestions:

  1. Open the file as Read Only with the second program.
  2. Make temporary a copy of the file and open the temporary file in the second program.
========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 10
(3,331 Views)

@LaAb wrote:

...LabVIEW doesn't read the file unless I stop software from logging data, even though I can manually open the file and see the data logged for the past 4 minutes while the software is logging data for the next 4 minutes.


I don't have LabVIEW 2020 (only 2018 at the moment), so I cannot see your code. However, it sounds like a common file permissions error. Try to open the file as read-only access to avoid Windows thinking you want to modify the file. This may avoid the locking behavior.

 

open read-only.png

 

If editing the log program is possible, I would recommend opening and closing the file reference every 4 minutes as opposed to holding the reference open forever.

_______________________________________________________________
"Computers are useless. They can only give you answers." - Pablo Picasso
0 Kudos
Message 3 of 10
(3,329 Views)

Thank you for replying. 

I'm new to LabVIEW so  I hope you forgive me for asking silly questions and making stupid mistakes. 

 

I have used this code but still can't read the file.

 

I can edit the log programme on the software to log data on schedule, for instance log data for every minute continuously till I press stop logging on the software and it will be saved us time sequence.

 

 

 

LaAb_2-1643659230832.png

 

 

 

LaAb_1-1643658856918.png

 

0 Kudos
Message 4 of 10
(3,309 Views)

Any reason why you don't just use the Read from Text File primitive to do all that? If you are not reading a partial file, you don't need all that complexity.

 

Read from Text File.png

 

The Read from Text File function already opens a file as read-only.

 

_______________________________________________________________
"Computers are useless. They can only give you answers." - Pablo Picasso
0 Kudos
Message 5 of 10
(3,263 Views)

The file is ready to be read once the software buffer is full. 

 

I have solved it this why (see attached pic). However, can't get the graph working. The Y-axis appears fine but the X-axis 0. I want to the reflect the X-axis of the file. Is there a way you can help on that. 

 

Thank you

LaAb_0-1643977637815.png

 

0 Kudos
Message 6 of 10
(3,244 Views)

Hi Lab,

 


@LaAb wrote:

The file is ready to be read once the software buffer is full. 

 

I have solved it this why (see attached pic). However, can't get the graph working. The Y-axis appears fine but the X-axis 0. I want to the reflect the X-axis of the file. Is there a way you can help on that. 


So the graph is not working, but you "solved" the problem? 😄

 

  • Why do you need 3 ExpressVIs to create a plot in a XYGraph from 2 columns of your spreadsheet file? Why not use a simple BundleCluster node???
  • Why do you need 2 IndexArray nodes to index two columns from the same array?
  • Which file do you read using the ReadSpreadsheetFile function? There is no path wired!
  • Which "software buff is full" when the "file is ready"? Please explain this…
  • Did you debug your VI and checked the X and Y data using probes?
  • Why don't you attach code? We cannot debug/edit/run images with LabVIEW!
  • Why don't you use shift registers in favor of local variables???
  • Why do you multiply your time interval value by 1030? Are you moving faster in space than we do?
  • Why don't you use the ClearError function to handle error 4?
  • Why don't you cleanup your block diagram?

So many questions for such small code…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(3,236 Views)

 

Thank you for your feedback GerdW.

 

Before won't be able to read the file when the software buffer is full so I was referring to that when I say I solved the problem.

 

There might be a simpler way to do it but I'm new to LabVIEW. 

 

There is a path wired so I select a file(.log) while the software is logging data. Once the buffer of the software is full then the data appears on .log file.

 

The buffer takes 206 seconds to be full and time interval is 0.2s.

 

i will attach the code, If you can help me to make it more simpler and to get the graph represents .log file, that would be appreciated.

 

Thank you.

0 Kudos
Message 8 of 10
(3,227 Views)

Hi LaAb,

 


@LaAb wrote:

i will attach the code, If you can help me to make it more simpler and to get the graph represents .log file, that would be appreciated.


See this:



@LaAb wrote:

There is a path wired so I select a file(.log) while the software is logging data. Once the buffer of the software is full then the data appears on .log file.

 

The buffer takes 206 seconds to be full and time interval is 0.2s.


There is no "buffer" in your VI!? What exactly are you talking about?

 

Why do you check the filesize every 1s when your "other software" takes 206s to "make its buffer full"?

What is that "time interval is 0.2s" coming from?

Why do you try to read the file incrementally when that "other software" writes "once the buffer is full then the data appears on log file"?

 


@LaAb wrote:

Thank you for your feedback GerdW.


Nice to get a "thank you", but you didn't take any of my suggestions!?

 

What should be displayed in the graph?

Which spreadsheet file do you want to load - there still is no filepath wired!?

(Why do you use ReadSpreadsheetFile function when you already collect log file content in this "Data" wire/indicator!?

 

Please explain in simple words what you really want to achieve…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 10
(3,219 Views)

Hi GerdW,

 

I have used your code and it is much simpler but still XY Graph is not displaying anything.

 

The software is a third party and its hardware have a buffer. The software reads sensor data directly and the software allows me to log data of the sensor in real time.

 

However, The softeware is not compatible with Modbus/TCP connection as a result, to get a real time data from software I had to implement this code. 

 

I was checking it every seconds because when I press stop logging data on the software side, I want the LabView side to read the new file. However, with your code, still working fine except XY Graph.

 

It should display the log file

LaAb_0-1644242286706.png

You are right, there is no need for ReadSpreadsheetFile function. I was just experimenting. 

 

 

I want to display the data (.log) above as it is, in any form of graph as soon as the LabView reads it.

 

Thank you.

0 Kudos
Message 10 of 10
(3,195 Views)