From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Waiting for existance of file to proceed

So I am trying to work on some optimization things for our experiment that is controlled through LABVIEW.  

 

The idea is that we have a few variables we can adjust through LabView, which programs devices and does its thing, and then we use MatLab to process the images.  My idea is to use some preexisting open source code that I found in nature (M-LOOP) to optimize our parameters.

 

The idea is that once the experiment runs, I have a variable that I want to optimize.  Once I read that, the M-LOOP will guess new params (saved in a txt file).  So what I want to do is have labview wait for this file to be created, then read the new variables and then start the procedure again.

 

I think I have the variable part down, but the difficult part for me is getting the procedure to run.  The way he experiment works is it in in an event structure that waits for the value of a button to change.  So is it possible to programmatically do this?

0 Kudos
Message 1 of 17
(3,363 Views)

@jmaslek wrote:

 

I think I have the variable part down, but the difficult part for me is getting the procedure to run.  The way he experiment works is it in in an event structure that waits for the value of a button to change.  So is it possible to programmatically do this?


Attaching a simplified version of your VI would be much more efficient than vague descriptions, so please do so.

 

To see if the file status has changes, you could poll it at regular intervals (e.g. using this function). If the writer keeps the file open, you also need to ensure to allow read access, etc.). even if the file exists, I would image that new values are occasionally written to it, so you probably need to compare the contents with previous reads.

0 Kudos
Message 2 of 17
(3,348 Views)

It would be so much easier to answer this, and to have the answer actually apply to your code, if you attach your VI (no pictures, please, unless you know how to make a Snippet).

 

If you do have an Event loop in your program, you could give it a 1000-msec (1 sec) TimeOut case where it checks for the existence of your file.  If your file is present, the "Is Present" case could involve raising a Value Changed (signalling) Property on some variable (but not a Latching Boolean Control).  Depending on how your Event Loop communicates with the rest of the VI (I'm sure clearly evident in the VI's Block Diagram), there may be other, more direct, ways of signalling this Event.

 

Bob Schor

0 Kudos
Message 3 of 17
(3,347 Views)

Yes, as altenbach said, check not only existence, but read the file once in a while. I would even make Matlab to write the time (iteration number, etc) to indicate it has been updated.

Communicating through file is simple, but has some limitations. You can look into local tcp or udp communication to send params and commands between different applications, make either labview or matlab part a dll to be called when needed. 

0 Kudos
Message 4 of 17
(3,310 Views)

See https://forums.ni.com/t5/Example-Programs/Event-based-File-and-Folder-Watcher/ta-p/3502878

 

for a .net event based solution, if you are using Windows.

 

mcduff

Message 5 of 17
(3,289 Views)

I use the attached VI to check to see if a file exists and if it is free to access. I've been using this under for Windows 10 and LabVIEW 2018 and haven't encountered any problems with it. I know it's not written in the conventional manner.

0 Kudos
Message 6 of 17
(2,568 Views)

Hello,

 

In general the answer is YES, it is possible. And it should not be hard.

 

But you really need to upload some material in order to get specific instructions.

 

BR,

Jakob

0 Kudos
Message 7 of 17
(2,552 Views)

Hi Jim,

 


@Jim12345678 wrote:

I know it's not written in the conventional manner.


Yes, it's written in a very non-LabVIEW like way!

Your VI after converting the stacked sequence into a flat one:

 

The same VI after cleanup:

No locals, no free-floating terminals, no sequence frames, no coercion dot at the wait function, no default constant of wrong datatype at FileOpen function, terminals connected to connector pane outside of structures, you even used an inappropriate connector pane pattern.

Still room for improvements (more comments, error handling, …)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Download All
Message 8 of 17
(2,536 Views)

Ah, a C programmer that has declared 'variables' and done a 'main' frame. It's been a pretty long time since we saw Localitis and Sequentitis. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 9 of 17
(2,528 Views)

Aha! You noticed!

 

I've been programming in LabVIEW for 22 years and I get no end of grief for my approach, but it lets me do things that would simply be impossible if I followed convention.

0 Kudos
Message 10 of 17
(2,490 Views)