LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CSV File - Server and Labview

Solved!
Go to solution

Hello,

 

I save my results data from a Vision picture analysis to a CSV File. Works great! Now I want to read the CSV automatically by a server application. I need some hints or tricks to avoid access violations by the server or labview if both programs want to read / write to the file simultaneously.

What I want to do:

 

The server application read the output file every 30 seconds:

Read the data and delete it afterwards - so no data duplicates should accrue. 

 

Labview writes the data to the file: 

If the file does not exists: (deleted) create a new one

If the file is in use: try it next time again (to lose one or two datasets is not important) 

 

I want to use the "write to spreadsheet" function but maybe someone can give me a tip to use this or that to do a better job! Smiley Wink

 

Best regards,

 

Paul

0 Kudos
Message 1 of 6
(2,989 Views)

In the File->Advanced palette, there is a nice gem called Check If File Or Folder Exists.vi.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 6
(2,962 Views)

I am not sure you want to use Write To Spreadsheet. The functionality is probably too rigid for your application. Use the Open/Write/Close VIs and format using the Array to Spreadsheet String node.

 

You may want to try a minor variant to your procedure.

 

  1. Write the CSV file using a timestamped name. This allows multiple, simultaneous files to be on your disk.
  2. The server reads and deletes the oldest file every thirty seconds.
  3. LabVIEW creates a new file with a new timestamp as often as needed (how often is this? Don't want to write faster than you read.)

A simple <name>_YY-MM-DD-<time>.csv file name format should work for you. You can generate the timestamp string easily enough.

 

Let us know if you need further help.

0 Kudos
Message 3 of 6
(2,953 Views)

Hello Crossrulz,

Thank you for your help! I overlooked that VI,  works good for initialization and recreation of the file but I am still looking for a method to check if the file is occupied by another program. I found some topics about that stuff using the error code .... let’s see. An alternative could be the tool "Handle v3.51" from Microsoft but you have to use a lot of “string gymnastic”. Not my favorite topic! 😉   

Best regards,

Paul

 

 

 

0 Kudos
Message 4 of 6
(2,951 Views)
Solution
Accepted by topic author Meisspa

Hi Paul,

 

couldn't you just try it like that (see attachment):

 

If error 5 occurs the file is already open.

 

Is that OK for you?

 

Best regards

Christoph

Staff Applications Engineer
National Instruments
Certified LabVIEW Developer (CLD), Certified LabVIEW Embedded Systems Developer (CLED)


Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved
0 Kudos
Message 5 of 6
(2,920 Views)

Hi Cristoph,

 

thank you for your code sample. Using a case structures for checking if the file is occupied by "code 5" works greate! Thank you!  

0 Kudos
Message 6 of 6
(2,862 Views)