08-22-2017 12:36 PM
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?
08-22-2017 12:58 PM - edited 08-22-2017 01:01 PM
@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.
08-22-2017 12:59 PM
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
08-22-2017 05:06 PM
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.
08-23-2017 12:10 AM
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
03-30-2020 01:37 PM
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.
03-30-2020 03:15 PM
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
03-31-2020 01:29 AM - edited 03-31-2020 01:46 AM
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, …)!
03-31-2020 01:46 AM
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
03-31-2020 01:14 PM
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.