LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

start stop event structure queue

Solved!
Go to solution

Hello,

I would like for the attached vi to start logging/displaying data when the Start button is pushed, not when the VI starts. So I did some research and was led to the Event Structure (this is my 1st time using an event structure). I have been trying all sorts of things over the last few hours so what I have now is probably somewhat convoluted, however, my latest error is that my dequeue is receiving an "invalid refnum".

 

Could someone guide me on what I am doing wrong?

 

Thanks.

 

Download All
0 Kudos
Message 1 of 16
(5,289 Views)

Easiest way would be to write the code in flat sequence. Add while loop in the first frame, connect start button with conditional terminal. Subsequent frame would execute when you hit the start button. The technique is one of the common ways to write code.

My experience is that its easier to learn labview quickly by following traditional architectures for writing codes.

 

0 Kudos
Message 2 of 16
(5,284 Views)
Your consumer loop won't run until your producer loop stops.  Why?  Because the consumer loop is dependent on a wire that is coming out of your Init File subVI.
0 Kudos
Message 3 of 16
(5,268 Views)

highlight execution [click the light bulb] and watch the VI run and you'll see what's happening.

The consumer loop runs to de-queue information, but your file refnum has not arrived yet, and it won't arrive until the stop event executes.

 

I suggest you make an "init" case and load the file refnum into the queue as well as the intial array.

Then the consumer can read the refnum and the array data out of the queue.

 

You also must realize that the way you've got it setup right now, when you click the stop button, the producer loop will stop, and your acquisition will stop.

Kudos for trying the queued event structure  - once you get the hang of it, you'll see it's worth the struggle to learn.

 

 

0 Kudos
Message 4 of 16
(5,265 Views)

kwaris wrote:

Easiest way would be to write the code in flat sequence. Add while loop in the first frame, connect start button with conditional terminal. Subsequent frame would execute when you hit the start button. The technique is one of the common ways to write code.

My experience is that its easier to learn labview quickly by following traditional architectures for writing codes.

 


No offense to the Kwaris but please do not follow this advice. LabVIEW is a dataflow language, not a traditional sequencial language. If you follow this advice you will not be able to harness the full power of dataflow programming. Please take some time to learn the basic concepts of dataflow programming. Also follow the advice given regarding the producer/consumer architecture.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 16
(5,227 Views)

I concur with Mark. Using sequence structures in order to control a VIs order of execution is a sign of bad/missing architecture (with the exception of FPGA of course)......

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 16
(5,208 Views)

Thanks for the advice. I am trying to figure out how I can still accomplish what I need. It should be quite simple but seems to me to be much more complex than it needs to be in LabVIEW.

 

Would it make sense to only use the event structure to handle the start/stop button. When the start button is pressed, the INIT vi would be run and the refnum and initial start times passed to the producer/consumer loops which were OUTSIDE the event structure. When the stop button is pressed the event structure would simply pass the signal thru to the producer loop condition terminal?

 

Sorry, for the basic questions - I am new to both producer/consumer loops and event structures.

0 Kudos
Message 7 of 16
(5,189 Views)

Hi Nouse,

 

I had some free time and was bored so took a look at your vi for you. You was on the right track, had started with a good architecture which is half the battle, just needed some fine tuning:

 

Data logger image.JPG

 

I took your code and added it to this. All that i have taken out is the Sub vi's that get your data, i replaced this with a random number just to see some data on the wavechart and also being logged in your file. A point to notice is that your 'CNAP INIT FILE' vi has no error cluster propogation. If you run this subvi and there isnt the 'C:CNAP\' Directory (As there wasnt on my computer at first) the 'OPEN File' vi errors and halts the program, as you have no error propogation or handling in this vi you cannot handle this error.

 

I changed the vi slightly and added a 'Start' 'Stop' and 'Exit'. This allows you to start acquiring/logging data, stop (without exiting the program), restart acquiring/logging or exiting the program. A point to note is that if you do 'Stop' and then 'Start' again, relatively quickly your 'CNAP INIT FILE' Vi will append a previously written file, which is fine, but it will also send out a new start time. So your readings in the same file will start from 0 time. You may want to catch this and not update the new start time if appending an old file.

 

I have attached the VI in both LV2009 and LV8.6 as you never stated your version.

 

Hope this helps,

 

Rgs,

 

Lucither

Message Edited by Lucither on 03-27-2010 03:32 AM
------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
Message 8 of 16
(5,163 Views)

Hey Lucither,

That is great and much appreciated! I am working with LabVIEW 8.5.1 however, so could not open any of the files. If it is at all possible to convert your stuff to 8.5.1, that would be great. For now, I will just try to use the jpeg as a starting point and fill in the missing frames. Thanks again!

0 Kudos
Message 9 of 16
(5,133 Views)

HI Nouse,

 

No worries, have attached the correct version for you. Dont forget to mention what LV version you are using when asking for help, that way the guys can send you any code for the correct version. I beleive you can also save it in your settings so that it appears in your information (i actually need to do that myself).

 

Let me know if it works ok. Dont forget to Kudos me or select 'problem solved' if this helps. Gives me a warm feeling inside Smiley Happy

 

Hope the rest of the project goes well. If you encounter any probs dont hesitate to ask. There are plenty of guys on here more then willing to help as long as you explain well and provide some sort of code example of what you have done so far. Carry on learning about the producer/consumer architecture, you stated earlier that it appears more difficult then it should be in Labview. Once you get used to the dataflow of Labview and start to feel more comfortable with the architectures you will start to really appreciate how powerful and intuative Labview can be. Anything is hard at first unless you dedicate time to learn it. I was the same as you at first but now i shudder at the thought when i have to write 'C' or 'C++' code as i just want to use Labview all the time. Not only that the NI forum is by far the best software forum i have ever used. There seems to be a legion of helpful people on here willing to help with any problem.

 

Regards,

 

Lucither

Message Edited by Lucither on 03-28-2010 03:54 AM
------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
Message 10 of 16
(5,121 Views)