LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing a .csv file in vi while the data is written by 3rd party java applicaiton

Hi

 

I have a requirement like below explained.

 

A java applicaiton reads data from hardware and writes in a .csv file. This java applicaiton is triggered by a button click in Labview VI.

 

    --> cmd window   -- cmd /C java Client n

 

the data will be read from hardware and written to the file per every second.

 

In the labview vi, we are reading the .csv file simultaneously and plotting the graph. 

 

The above operations need to happen simultaneously. 

 

When we tried this, we are geeting the "File Not Found Excpetion(the file is used by other process) in java application.

 

Can anyone help me why this might be happening in Labview. I tried this with a "c" applicaiton instead of Labview and it is working fine.

 

Problem observed only with labivew.

 

Regards

 

Kris

0 Kudos
Message 1 of 8
(3,907 Views)

How are you opening the file within LabVIEW?  Perhaps if you open for Read access (as opposed to read/write) it won't put a lock on the file that keeps Java from accessing it.

0 Kudos
Message 2 of 8
(3,900 Views)

Naah, I said, that will never work.  But to my shock and (pleasant) surprise, it does!  Here is a snippet of a little routine I cobbled together using LabVIEW for both the Writer and the Reader.

Simultaneous Write and Read.png

The Writer is on top.  It creates a Temp.txt file on my Temp directory, deletes it if it is already there, then opens it for writing.  There's a boolean "Done" flag that tells me when the Writer finishes, so I clear it before entering the Writing Loop.  Here, every half-second, I write the sequential numbers 0 .. 9, with a New Line to create a Text File of Lines.  When I'm finished, I close the file.

Below this is the Reader Loop, designed to start after the Writer Loop has opened (and created) the file.  Here we open the same file in Read-Only mode.  The Reader Loop also goes 10 times (I could have built in a Stop condition, but this is only a Proof-of-Concept).  The loop is initialized with the current File Position (0) in a Shift Register.  The inner While Loop is a "Wait for Data to Appear", a loop which checks 10 times a second to see if the File Position has changed, exiting when it does (meaning the Writer has Written Something).  It then reads a line from the File (the Read Text function has its "Read Lines" property set) and displays it.

 

When you run this, you will see the Reader's output, Line, count up, 0 .. 9, and then the program stops with no errors.  What fun!

 

Bob Schor

0 Kudos
Message 3 of 8
(3,861 Views)

I'm glad you tried it out.  I didn't have the time to experiment.  I just figured that the OS has some mechanism for locking and not locking files.  And that the File Open had the Read-only,  Read/Write, and Write-only  (why would someone need write-only?) access modes, there must be a reason to have the different modes, and I figured it must be related to file-locking.

0 Kudos
Message 4 of 8
(3,855 Views)

I'm not going to experiment this time, but I wonder if Write-Only implies you can't do File Position commands, i.e. it forces you to "write at the end-of-file"?


BS

0 Kudos
Message 5 of 8
(3,845 Views)

Guessing also. I would interpret write-only to mean that one else can read or write to the file while the write-only user has it open. This could be used to prevent a parallel reader from getting partial information.

 

Lynn

 

 

0 Kudos
Message 6 of 8
(3,833 Views)

I presume you meant ... noone else can read or write ...

 

BS

0 Kudos
Message 7 of 8
(3,812 Views)

Right.  Someday maybe I will learn to tipe tape typ type.

 

Lynn

0 Kudos
Message 8 of 8
(3,806 Views)