LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a text file for automation

I've created a text file to send a set of commands for mass flow controllers, solenoid valves, and LED. The numerical values indicate both numerical and Boolean outputs. How do I create a program using a read-text file so that it takes those commands and runs the vi automatically?
If there is any other method to give commands for automation, kindly address it.

0 Kudos
Message 1 of 4
(90 Views)

Good morning, @kishore 2, and welcome to the LabVIEW Forums.

 

As you are a new member, there are some points to suggest, to help us provide the most useful help to you:

  1. Posting LabVIEW code (which you did) is good.  However, almost all LabVIEW "experts" use (or have access to) older versions of LabVIEW (like LabVIEW 2019 or 2021), and are not able to open code saved using later versions (such as LabVIEW 2022 -- when I tried to open your code, my LabVIEW 2019 said "Can't, it's LabVIEW 2022 ...").
  2. It helps to know how familiar you are with LabVIEW, how much experience you have programming in LabVIEW.  Seeing your code would help, but absent that, saying something like "I've been programming in LabVIEW for 3 years ..." or "I'm familiar with the Queued Message Handler" would help us to know "where to begin".

Looking at your Text file (which seems to be in Comma-separated Variable format), several approaches come to mind, including Message Handlers, State Machines, etc.  But we don't know "what you know" (without seeing your code), so address Point #2 above, please (and don't forget Point #1)..

 

Bob Schor

0 Kudos
Message 2 of 4
(55 Views)

I' ve seen applications that does exactly that. 

You basically have to build a command interpreter inside labview. 

You read a file, most common format would be CSV file, then a case structure would detect and execute one command at a time. 

 

0 Kudos
Message 3 of 4
(45 Views)

I've built a similar system using a state machine, and your setup is on the right track. As others mentioned, you'll need a SubVI to read the CSV file, which you can load during the initialization step. Use the "Read Delimited Spreadsheet" function to convert the file into an array format. Pro tip: arrays of clusters work really well for managing these types of programs.

 

Here’s an outline of the state machine structure that’s worked for me:

  1. Initialize: Initialize UI and zero out the array pointer.

  2. Load Sequence: Convert CSV data to an array of clusters. Also, get the array size to set your stopping condition. You could add some error checks here, such as that the file exists or the size of the array is greater than zero.

  3. Load Step: Ensure the pointer is within the array bounds.

  4. Configure Valves: Adjust valve states based on the data in the current cluster/step.

  5. Execute Step: You could use a duration timer as a transition condition for each step.

  6. Increment Pointer: Move to the next step in the sequence.

Repeat steps 3–5 until the pointer exceeds the array size, at which point:

  1. Shut Down: Turn off all field devices.

  2. Quit.

This setup keeps things organized and modular. It's the same program, no matter how long the sequence is.

 

The paper here might also be helpful for additional insights.

 

I attached one of my CSV to array subvi converters and an example file.

There are state machine toolkits available to help with that part of the project. I personally use the Enhanced State Diagram.

-----------------------------------------------------------------

If you can not measure it, you can not improve it.
- Lord Kelvin
Download All
0 Kudos
Message 4 of 4
(24 Views)