LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reference passing and Queue questions.

Hi,

I've been posting in the Counter/Timer forum but was told this would be a better place for these two questions.

1) Reference passing. I have a subVI that uses a counter to timestamp and input signal. I want to create 8 of these subVIs to have 8 timestamping channels. Inside the subVI there's a while loop that reads that data and an event structure. So I want to have a stop button on my main VI that gets passed to the subVIs to stop the read while loops and everything else. I was told to create a reference to my stop button and pass it to the subVI. So first I figured out how to create a boolean reference in my subVI. I did that, put it inside the event structure and registered an event change on that reference. Firstly, will this event pick up on the stop button I reference being changed? Or do I have to program it another way? So then I use a property node to grab the value and stop the while loop. That's all fine and dandy. But back on my main VI when I try to hook up my reference to the subVI it complains about wire types. I've looked at 4 other reference passing examples now and as far as I can tell, I'm doing exactly the same thing as all the others. Any ideas anyone? (you can look at my code that I've included)

2) Queues. I'm not sure whether I'm having problems with my queues. To avoid write slow downs (I want to take my timestampings I'm generating and write them to a txt file) I want to stick the timestamps on a queue. I got this all working in a VI, but I'm not sure whether it's working now that I've turned it into a subVI. I only want 1 queue that gets accessed by the 8 timestamping subVIs. I pass the queue into each of the subVIs (there's only 2 right now), but I'm not sure whether I've set it up correctly (I can't test it too much yet, because the references from problem 1 aren't working yet). Any suggestions would be helpful.

3) With passing along error in and error out I'm not too sure how careful I have to be with this. You can look at the SingleTimeStamping_v2 to see that the errors go from my start task to my queue then back to the tasks (someone else gave me that code). But when I changed this into a subVI, I didn't want a bunch of error in and out nodes. But I'm not sure whether I have to be careful with this. Sorry this isn't a well formed question, but I don't have a well formed idea yet of what to do.

Thanks to anyone who helps,
Chris
0 Kudos
Message 1 of 5
(3,323 Views)
Passing references is a little different sometimes. Here is your VI modified to elimiate the "reference problems". I changed your subVIs to not use a strictly typed reference and then had to change the data to the appropriate type (non-typed references produce variant data).

It works, but it's a little more complex. Only a little.

I traced through your program and found another problem... You create the queue and then pass it to the subVIs and immediately close the queue with "force destroy" turned on. This could destroy the queue BEFORE the subVIs get to use it. This could cause a few errors. I hope that this is just an example that you posted for us to look at the reference problem.

Anyway, have fun.

Rob
Message 2 of 5
(3,307 Views)
Hi Robert,

Thanks for helping me solve the reference problem. I also actually had another problem in there that I solved by finding some example code. When I had the event structure set up to recognize when the Bool Ref changed, it never fired this event and consequently never stopped the loop. I guess the reference to the boolean never does change (it always points to the same boolean), but the boolean variable referenced does. 😛 Anyways, so in order to set up an event, I'm assuming that you have to decode the value of the reference as you've done, then pass it to a stop control and then do the event on this control? Sounds like a lot of work, so I did it like the example that I found where the reference is outside the while loop, the processing to get the boolean value is in the loop, and the value is passed right to the stop condition without ever defining a stop event. Works pretty much the same. The other problem was that for whatever reason, the source that I started this code with had the button action as latched, which caused problems, LabView complained, only one of the loops stopped, etc, don't know why, so I changed it back to switched mode. Here's my working code if anyone is interested.

Thanks again Robert,
Chris
0 Kudos
Message 3 of 5
(3,278 Views)
Hi there, some further questions on queues,

I've included some example code of what I want to do. Basically I have a counter/timer card that I'm using to timestamp TTL signals that are coming into my system. Next what I want to do is push these timestamps onto a queue so that they can be read by a separate loop so that the reads don't slow things down. Someone gave me some example code with the queue idea in it, you can see it in the SimpleTimeStamping_v2.vi. So the queue code works fine and dandy when everything is set up in one file. What I wanted to do was compartmentalize things into subVI's to make things simpler in the program. So I made a timestamping subVI, each subVI handles one counter channel (there's 8 in total, so there's 8 subVI's), I want to also pass into this timestamping subVI a queue to put the timestamps on. I just want 1 queue, not 8. So I put that in (just like in SimpleTimeStamping_v2, but now that it's a subVI it complains about needing a GPIB controller to be in charge to work). I also want to make a subVI that handles the file writing for the elements in the queue. I put together just a basic queue example of how I want things to work (without the timestamping stuff cluttering things up). The Enqueue subVi would be where the timestamper pushes things to the queue, the Dequeue subVI would be where the timestamps are written to a file. This example gives me the same errors. I know I've probably botched up how I should set this up, but I was working off example code that worked. Can someone tell me where I've gone wrong and how to fix it?

Thanks,
Chris
0 Kudos
Message 4 of 5
(3,261 Views)
Hi Chris,

I took some time cleaning your code and making the queue work without any errors. Make sure to control the flow of your main VI. In your example you are releasing the queue while it's still being used by the SubVIs. I changed the dataflow to not release the queue until the SubVIs are finished executing by inserting a Sequence frame around the calls to the SubVIs.

Also, in case you want to call multiple instances of the same SubVI, and you want these multiple instances to execute in parallel, you will have to set the SubVI to execute in reentrant mode. Do this by opening the SubVI and going to "Edit >> VI Properties >> Execution" and enable "Reentrant execution".

NB! When your SubVI is running in reentrant mode you can't rely on the front panel shown of the SubVI. This is because you can't have multiple of the same front panels opened at the same time (a LabVIEW limitation). Therefore LabVIEW chooses not to update the front panel when the VI is executing in reentrant mode.

Have fun!
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 5 of 5
(3,251 Views)