LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use resource or release resource based on boolean?

I have a case where I need to turn a AO on and off and when turned off I need it set back to zero offset. I need to do this with four different AO channels each with their own boolean switch. I have it setup but what I am having trouble is releasing the resource after the first switch is turned on then off.

The logic seems to escape me.

0 Kudos
Message 1 of 10
(3,816 Views)
Can you post a screenshot of the particular code or even better a code sample?
Regards,
André (CLA, CLED)
0 Kudos
Message 2 of 10
(3,811 Views)
Here is an example I have been trying to get to work.
0 Kudos
Message 3 of 10
(3,793 Views)

There are a couple key problems.

1.  Your top loop has a run condition with nothing wired to it. 

2.  All your loops create a DAQ task continually in side the loops.

You will want to set up a state machine architecture perhaps with several parallel loops.  Each DAQ loop should have 4 states.  1.  Create task  2.  Run Task,  3.  End task  4.  Idle.  Then the boolean when true can run the state 1 immediately followed by state 2.  It continues to run state 2 while the boolean is true.  When it goes false, it runs 3 then 4.  It will continue to run 4 until the boolean goes true again.  State 4 should also have a condition to end the loop whenever your master program stop button (One you create, NOT the abort button at the top of Labview.))

0 Kudos
Message 4 of 10
(3,788 Views)
Ok I sort of understand what you are stating and I see the examples but for the life of me cannot figure it out.

I understand the while loop is controlled by boolean. The case structure should have 4 cases.
1. create task
2. Run Task
3. End Task
4. Idle

What causes case 1 & 2 to run and not cases 3 & 4 using just a boolean control? Does the boolean control need to be wired to case 1 & 2 when true and use the "not true" wired to cases 3 & 4? Did that make sense?

I am sure my confusion is something to do with the shift register which is a feature I do not fully understand or even how to add to a structure. I right click on the case and see no option to add shift register.



0 Kudos
Message 5 of 10
(3,780 Views)


THurst wrote:
Ok I sort of understand what you are stating and I see the examples but for the life of me cannot figure it out.

What causes case 1 & 2 to run and not cases 3 & 4 using just a boolean control? Does the boolean control need to be wired to case 1 & 2 when true and use the "not true" wired to cases 3 & 4? Did that make sense?

I am sure my confusion is something to do with the shift register which is a feature I do not fully understand or even how to add to a structure. I right click on the case and see no option to add shift register.



Pretty much, but I'm not sure we're exactly on the same wavelength so I'm attaching a simple example in LV 8.2.1.  You add a shift register to the while loop, not the case structure.
 
The boolean is switch action.  I only modeled 1 DAQ loop, you can create others in parallel.  There needs to be a wait function inside the loop so that the loop doesn't spin endlessly when nothing is happening in the idle case.  It is a good idea to make a type definition of the enum that decides the cases.  That way if more states need to be added, they are added to the typedef and all the constants and indicators get updated automatically.
 
A better architecture would be a producer/consumer with events, where there is one loop that handles the mouse clicks and distributes commands to each of the specific DAQ loops, but I don't think we need to go into those complications yet.
0 Kudos
Message 6 of 10
(3,768 Views)
Ok now I understand how the boolean is used for the cases. Now how would I wired the task items. I took your example and added the task but am having trouble with the wires between cases.
0 Kudos
Message 7 of 10
(3,764 Views)
You will need to wire your task channels to the right hand edge and into a shift register.  That way the reference to the tasks will be available in all other cases.  See attached.  I also wired up the error wires to an indicator.
0 Kudos
Message 8 of 10
(3,757 Views)

Hi THurst,

I will like to step into the forum and suggest a more simple approach, if you can run this shipped example: “Cont Gen Voltage Wfm-Int Clk-Non Regeneration.vi”, and simply write a waveform with amplitude zero, before ending the task.  This might be a good resource to look at: What is the Difference Between the DAQmx Stop Task.vi and DAQmx Clear Task.vi? , The screenshot might give you an idea, but basically you press the Boolean to change the amplitude of the sine wave to zero and then you stop the task.

I hope it helps



Message Edited by Jaime F on 12-12-2007 02:48 PM
Jaime Hoffiz
National Instruments
Product Expert
0 Kudos
Message 9 of 10
(3,742 Views)

Thank you everyone for all your help. I was able to get what I needed from the earlier suggestions with state machine using enum and shift registers. The idea is to have three outputs

- one is just on with AO of 0.1 VDC

- Two others control seperate function generators.

When the respective boolean control is set to on the output is generated and when set to off it resets the AO to zero output. I was having trouble getting the resource released as it is the same resource.

I have attached the example.

Thank you again everyone.

 

0 Kudos
Message 10 of 10
(3,734 Views)