LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variable and nested loops

Solved!
Go to solution

I would not consider 14 functions a lot.

 

Anything you can do with text-based code probably takes more lines of code then it does in LabVIEW.  If your text-based version of the code is as simple as you say, then the LabVIEW code should not be as complicated as you say.

 

Everything you are looking to do in LabVIEW can be done.  I have a lot of text programming experience, and I would prefer to do just about any of it LabVIEW.

 

If you haven't taken any courses and tutorials, then do it.

If you have any questions about how to do stuff in LabVIEW, show what you've done and people on the forums will try to help.

0 Kudos
Message 11 of 15
(724 Views)

I attached my VI. Please be gentle as it was a learning experience where I started simple and kept adding functionality. I would probably do a few things different...

 

The code I'm refering to isn't writing from 100% scratch. It was specifically written for a small ATE that besides it's own functionality allows use of other instruments through a GPIB.  Like LV, there's a lot of background functionality built into it. However, this looks simpler to me than my 14 functions and easier to follow (granted I'm used to it). While I'm new to LV, I do feel a simple built in scripting language like this would be awesome.  

 

SprdSht.OpenNewSpreadSheet MainWindow, False
'create header
  SprdSht.SetTextRC 1, 1, "Test Program Name: " + prog_name
  SprdSht.SetTextRC 2, 1, Tester
  SprdSht.SetTextRC 3, 2, "Voltage"
  SprdSht.SetTextRC 3, 3, "Current"
  SprdSht.SetTextRC 3, 4, "Ohms"
  SprdSht.SetTextRC 3, 1, "Date"
  
 SprdSht.SaveSpreadSheet  'brings up windows save dialog for user to save file
.
for x = 1 to Z

.

wait T

.

NI_GPIB.ibwrt Dev1%,"READ?"

Data = NI_GPIB.ibrd(Dev1%)
.
OutputData ("RESULT", Vout, Iout, Ohm, irow, icol)
next x

Function OutputData (sname As String, Vout, Iout, Ohm, irow, icol)
 
 If sname = "RESULT" Then
  SprdSht.SetNumberRC irow, icol+1, Vout
  SprdSht.SetNumberRC irow, icol+2, Iout
  SprdSht.SetNumberRC irow, icol+3, Ohm
  End If

 SprdSht.SetTextRC irow, icol+4, Now 'current date and time to spreadsheet


 SprdSht.SaveSpreadSheet 'saves under saved name
 irow = irow + 1
 End Function

0 Kudos
Message 12 of 15
(707 Views)

I'm going to take on the challenge of cleaning up this VI.

 

There are several Rube Goldbergs in it.  And other odd things

 

For instance, there is no need for a while loop where there is terminal + 1 (note there is an increment function that adds 1 to a number without needing to ADD a 1 constant) then stops the loop when 1 is <= that value.  i starts as 0, add 1, you now have 1.  Guess what 1 equals 1 so it stops after 1 iteration.  Always, without fail.

 

Note that instead of comparing to greater than a zero constant, you can use the >0 function in the boolean pallete.  Still one function, but you've eliminated the constant.

 

It is generally a bad idea to use the Stop sign function.  It is the same as just hitting the Abort function.  Any shutdown code such as closing a port will never get to run.  With a proper architecture, you shouldn't need it.

 

Sequence structures usually aren't needed (especially ones that have frames where just wires run through it.  I think yours can be eliminated entirely.

 

Arrange your VI so that wires don't need to run backwards.  It makes it harder to visualize the order of execution.  The Clean Up Diagram button is a good start.

 

I''m trying to be gentle.  Just pointing out some facts.  I'll post a cleaned up version after I work on it a bit.

 

Also, I agree that your VI is a lot more complicated than the text code you posted, but I also think you are doing a lot more actions in the VI.  I don't see anywhere nearly as much GPIB writing and text string structuring for those writes in the text code that you are doing in the LabVIEW code, so you really can't compare the two programs.

0 Kudos
Message 13 of 15
(683 Views)

The simpler task as a comparison is to code your text code into LabVIEW.  This took me about 10 minutes.

 

It creates a tab delimited text file that can be opened in Excel.

0 Kudos
Message 14 of 15
(672 Views)

Hi  RavensFan,

 

Thanks a lot!!!

 

I really didn't want to use the Stops. Those are kind of a test engineering-ism where you want to immediately stop on a failure to prevent (further) damage. I was very careful in when and how they operate such that everything is in a safe state. One of the Stops stops the program before it even really starts. It's basically checking to see if the user input makes sense and therefore allows the programming timing to work properly. I'm sure there's a better way to get to this in this case. I just haven't found it yet. The other case I do want the power supply to shut down immediately to prevent damage to my device, which it does.

 

I do realize I overengineered it. As I mentioned, I started out just trying to make the supply wiggle and went from there. The add 1 etc was a cut and paste and never changed. I'm sure there's few other functions besides the <0 that will help me simplify that I haven't found yet.

 

In regards to the sequence structure with the error lines running to them (I may have overcomplicated it!), I could not get the functionality in them to work as I intended otherwise. Those also bothered me. But it worked.

 

I appreciate the file you uploaded. I will study it well.

 

Thanks.

0 Kudos
Message 15 of 15
(651 Views)