06-22-2021 07:05 PM
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!
Solved! Go to Solution.
06-22-2021 07:25 PM - edited 06-22-2021 07:33 PM
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:
06-22-2021 10:14 PM
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!
06-23-2021 01:05 AM - edited 06-23-2021 01:07 AM
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)!
06-23-2021 10:57 AM
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!
06-23-2021 11:07 AM - edited 06-23-2021 11:53 AM
@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.
06-23-2021 11:56 AM - edited 06-23-2021 11:56 AM
@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
06-23-2021 12:47 PM
It works perfectly now. Thanks a ton!