LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to take step measurements with standard state machine

Solved!
Go to solution

Hi,

 

I am fairly new to labVIEW so please bear with me. I am using LabVIEW 2011 SP1 and I am working with the standard state machine design pattern so that I can take step measurements (vi is attached). The way I have it set up is as follows:

 

Start
Process 1: Set the monochromator to a wavelength with the command “!GW xxx” where xxx is the wavelength. Action (query) is “write”.
Process 2: Read the voltage measurement and save it in a csv file.
Stop

 

So this process works fine if I just need to take a measurement at a single wavelength. However, I want to upload a csv file with a bunch of wavelengths in one column, and I want the LabVIEW program to step through each of the wavelengths and record the voltage in the second column of the csv file (or even a separate csv file if that's simpler).

 

My attempt:
I was able to append the voltage values to a separate csv in Process 2 but I still have a few problems. The first is how will that wavelength value be converted to a command (!GW xxx) in Process 1. My attempt was to make a column in the csv of all the commands (instead of just a wavelength value). However I can’t connect the Read from spreadsheet file.vi to the command in the block diagram. The second problem is where would I incorporate the for loop such that each wavelength value goes through Process 1 and 2 but back to process 1 for the next wavelength, and repeat. The Scan.csv is all the wavelength commands I want to go through to obtain voltage measurements. 

 

Thank you!

Download All
0 Kudos
Message 1 of 8
(1,342 Views)

I assume reading the file once is sufficient, so that does not belong inside a FOR loop. (and a state enum is not a logical choice to wire to N anyway, right?). Read the file as array of strings. get the first column, and process the values in a FOR loop. 

 

It also seems redundant to have that !GW on every line. Why not save as numeric datatype and form the full command before writing to the instrument?

 

Can you explain the states? Do you want to do the following:

 

  1. start (init instrument, etc.)
  2. read file of wavelengths and store in shift register
  3. Set first wavelength
  4. read measurement & append to file. If there are more wavelengths, pick the next and go to #3. else go to idle.
  5. etc.

 

 

0 Kudos
Message 2 of 8
(1,324 Views)

Yes that is what I want to do. However I made some changes such that I don't need to read the csv of commands. Instead I made an array of the wavelengths using the Ramp Pattern vi. In this case I need to do 2 things:

 

1. Use a FOR loop to set the wavelength (from the array)

2. Convert the value from the array into the command format !GW xxx 

 

I am not sure how exactly to implement this. Do I convert each value in the array to a string and somehow modify the string such that it has the !GW ? I attached my updated vi. 

 

Thanks!

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

Hi dave,

 


@davenalaa wrote:

 In this case I need to do 2 things:

1. Use a FOR loop to set the wavelength (from the array)

2. Convert the value from the array into the command format !GW xxx 

I am not sure how exactly to implement this.


You need to implement those 2 steps exactly like you wrote them:

Btw. the enum for the statemachine should also be typedefined (and that typedefinition has to be used for all instances of that enum)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 8
(1,258 Views)

Hi, thanks for the help. I have one last problem, this allows me to set the monochromator to a bunch of wavelengths but doesn't allow me to take voltage measurements at each wavelength, i.e:
 
Start: Open instrument
Process 1: Set monochromator to wavelength 1
Process 2: Measure voltage and record it in csv file
AND then back to process 1 for the next wavelength, measure voltage and append to csv file, etc. Repeat until all wavelengths are stepped through. 
Stop
 
I assume Process 2 needs to be removed and just incorporated in the FOR loop in Process 1. I attached my solution. Is this correct? 
 
Thanks!

0 Kudos
Message 5 of 8
(1,233 Views)

@davenalaa wrote:

 Is this correct? 


NO. LabVIEW is a parallel language and you have no data dependency between writing the wavelength and reading the measurement. This means both occur in random order or even at the same time.

 

You don't need any inner loops. The outer while loop is sufficient for all looping operations.

 

You did not include your enum and most of your state constants are not the enum. This can cause problems.

 

Shouldn't the wavelengths and step be integers? It helps if you would save the VI with typical default values in all controls.

0 Kudos
Message 6 of 8
(1,228 Views)
Solution
Accepted by topic author davenalaa

@altenbach wrote:
You don't need any inner loops. The outer while loop is sufficient for all looping operations.

 


I don't have your enum or hardware, so here's a quick draft that hopefully can give you some ideas. Change the timing and states according to your needs. There are several places where you can save your data using simple low-level functions

0 Kudos
Message 7 of 8
(1,210 Views)

It works perfectly now. Thanks a ton! 

0 Kudos
Message 8 of 8
(1,197 Views)