From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

running instruments in parallel with a slight twist

Solved!
Go to solution

Hello, first post here. I am very new to labview (less than 2 weeks) and I am currently learning C++, so I don't have a ton of experience programming. I am working with a research group in a summer internship and currently I am working on writing some code for a ferromagnetic ressonance experiment. Right now my code is at a point where everything works very well except for my power supply. I am using official drivers, the problem is that these drivers run great as a standalone since they can run continuously. When I use the driver in my code it starts running and, since it never technically ends until I power it down, it keeps the rest of my code from executing, which means I don't get any data collection. 
How can I run the power supply live while executing the rest of my code for measurements? I need the events to be synchronized in this order:
set frequency

     set current(field strength)

          read voltage

          read x and y values

          read teslameter

     set new current

          read voltage

          read x and y values

          read teslameter

etc.

 

Thank you in advance.

-Kike (keekay)

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

Kike,

 

It sounds as though you will need to modify the code for the power supply to work well as a subVI. The power supply driver code apparently has a high level user interface, including a stop button.  Code like that is never intended to run as a subVI.

 

Open the block diagram of the power supply VI. It probably has a while loop which runs until the user presses Stop. You will need to change that so that it runs only once each time you call the the VI from your main program. It may be as simple as removing the while loop and fixing the few errors which that process creates. (Be sure you save a copy under a new name before you start modifying.)  

 

As for your main program, consider a state machine architecture. It is very good at that kind of sequencing and is easily modified when someone decides to change the order of events or add some requirement. There are examples, Design Patterns, and Templates which come with LabVIEW, especially the more recent versions.  These are great places to start and good things to learn.

 

Lynn

0 Kudos
Message 2 of 8
(2,322 Views)

It sounds like you are using an example as a driver.  Look at the example and see what it is doing.  You should make another VI that does similar or just call the lower level VIs directly in your main VI.

 

The State Machine is a good arhitecture to know.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 8
(2,311 Views)

Won't running the VI once as it is called simply start the current output and end it? I had a similar problem with the teslameter, however, since the teslameter is only writing a value to my spreadsheet I changed the while loop to a default false so that it would run once per iteration. That worked well. I need the power supply to continue the current output until all of the sensors have finished collecting data. If I misunderstood your suggestion please tell me.

 

Again, thank you for your help!

0 Kudos
Message 4 of 8
(2,296 Views)

I actually tried this; I gave up a ways into it because the driver they provided me with was so much better than the one I managed to come up with. I know it's a driver and not an example because it's the software that came with the power supply. There is another version that someone else had written several years ago; it's extremely buggy and doesn't have the security (protection for overvolting, overheating, etc.) that the one I am using has. 

0 Kudos
Message 5 of 8
(2,292 Views)
Solution
Accepted by topic author kikemart

If the existing VI has shutdown code (and it should), then that is one of the things you will need to modify.  Typically in cases like this you would break up that VI into three parts. The first handles initialization. It will be outside your loop or int an intialization state of a state machine and only runs once. the next part just sets the power supply output pararmeter(s). It can be called repeatedly inside your loop as you go through the current range. The last part is a shutdown VI. It sets the output to zero (or other safe value), disables the output, and ends communication with the power supply.  It will be after the loop or in a Shutdown state of the state machine.

 

Often it is rather easy to create these three VIs because you can just copy and paste the relevant parts of the original VI.

 

Lynn

0 Kudos
Message 6 of 8
(2,287 Views)

Just because the software came with the power supply does not make it a driver.  Many instrument makers provide example code or easy to use VIs in addition to the low level drivers.

 

Open the block diagram.  Inside you may find subVIs with names like Initialize, Set Current, and Shutdown.  Those would be parts of the driver.

 

Lynn

Message 7 of 8
(2,281 Views)

Lynn-

Thanks, I understand. I was just looking through the driver code and thinking about rewritting it, so I will definitely be doing this. I won't tag this as the solution (yet) just in case that I run into any problems, but everything should go well, this should be easy. Thank you everyone who helped.

0 Kudos
Message 8 of 8
(2,278 Views)