LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop + shift register + multiply instances

Solved!
Go to solution
Hello fellow labVIEW users,
 
I'vea small issue which bothers me. I've created a VI's to open/read/close anencoder from a DAQ card. The question is related to the read VI.
 
I've 2 read VI's.
1.Where the input is a location.
 
2.png 
 
2.Where the input is a ARRAY of locations, this VI uses the first VI.
1.png
 
 
Thefirst VI for reading one location has a while loop, which runs 1 time, with ashiftregister. It does some calculations and then passes a value to theshiftregister, these values are important for the given location.
 
If Iwould like to have multiply instances of that read VI I would just put themparallel on my diagram. But what if I had a infinity number locations? For thatreason I created the second VI which can read a ARRAY of locations. This VIcalls the first VI in a for loop, for each location in the array of locations.
 
Nowyou maybe can already guess what is happening. The first VI which stands in thefor loop doesn't get called with multiply instances for each iteration(location) of the loop. So what happens is that the data of theshiftregister in the VI that takes care for reading 1 location getoverwritten each time.
 
The solution where I call the VI parallel from each other doesn't have this problem.
 
3.png  
Here the VI the 3 VI's are all being created in the memory. In the for loop this does not happen...
 
 
Sooo my question is how can I define that the VI (in the for loop) must create an instance for each iteration.
Message Edited by WouterG on 03-29-2010 12:40 PM
0 Kudos
Message 1 of 29
(5,720 Views)
Change the property on the VI to be reentrant. This is under the execution properities of the VI.


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
0 Kudos
Message 2 of 29
(5,706 Views)

@Mark I did and it also works fine when you place your VI's parallel to each other, see the last image from my openings post,... this however limits your array.... try keeping code up to date where you have 99 VI's parallel to each other.

 

Thats why I created the for-loop in which the VI stands. For each element and thus iretation the VI must be newly created in the memory. This however doesn't happen, even when you set the reentrent.

Message Edited by WouterG on 03-29-2010 01:00 PM
0 Kudos
Message 3 of 29
(5,700 Views)
Solution
Accepted by topic author WG-

Save the sub-VI as a template.

 

Open it using the reentrant switch (hex 😎 so it opens a new instance each time opened. Pass those refs to your For loop and use "VI Server call by reference" to call the right instance for each iteration.

 

But beeter would be to keep the array of cluster in a SR in the For loop rather than teh sub-VI and just pass in the state from the last time the sub-VI was called.

 

Or another approach...

 

Do all of teh reading and sub-VI stuff in an instance of a template, one for each counter. They can push their updates to queues so others can see what they have found.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 29
(5,675 Views)

Ben wrote:

Save the sub-VI as a template.

 

Open it using the reentrant switch (hex 😎 so it opens a new instance each time opened. Pass those refs to your For loop and use "VI Server call by reference" to call the right instance for each iteration.

 

But beeter would be to keep the array of cluster in a SR in the For loop rather than teh sub-VI and just pass in the state from the last time the sub-VI was called.

 

Or another approach...

 

Do all of teh reading and sub-VI stuff in an instance of a template, one for each counter. They can push their updates to queues so others can see what they have found.

 

Ben


 

I was also thinking of your second solution but I rather not do that because I need to edit my VI then for reading a single location, remove the while loop + shift register, and then I can't use that VI anymore for reading a single location. I must always use the array VI then, with 1 element.
 
Also I don't really understand your last solution, but I queues is a no-go I think because it is a real-time application. 
 
Can you maybe clarify your first solution a bit more?
 
0 Kudos
Message 5 of 29
(5,665 Views)

I've now the following...

test.JPG

 

This however returns a error after opening the reference, a error 7 warning...

 

Error 7 occurred at Open VI Reference in NBG - Encoder read array test.vi->Untitled 1.vi


Possible reason(s):


LabVIEW:  File not found. The file might have been moved or deleted, or the file path might be incorrectly formatted for the operating system. For example, use \ as path separators on Windows, : on Mac OS, and / on Linux. Verify that the path is correct using the command prompt or file explorer.


VI Path: C:\ni-rt\startup\Encoder read.vi


LabVIEW Real-Time: VIs built into executables cannot be accessed through VI Server calls. Use Source Distributions to dynamically call VIs on Real-Time targets. 

 

Now I searched for this and came here, http://forums.ni.com/ni/board/message?board.id=170&thread.id=449810&view=by_date_ascending&page=1, but the path files is not related to my problem since I don't have an executable just a VI. 

 

I tried, http://digital.ni.com/public.nsf/allkb/A7DBA869C000B5AE862570B2007C4170?OpenDocument, where the input was the IP of the server but this doesn't work either it returns error 26

 

Error 63 occurred at Open Application Reference in NBG - Encoder read array test.vi->Untitled 1.vi


Possible reason(s):


LabVIEW:  Serial port receive buffer overflow.

=========================

LabVIEW:  The network connection was refused by the server. For TCP/IP, make sure the server is running and listening on the port you are trying to use. Firewalls can also cause a server to refuse a connection. For VI Server, make sure you have enabled VI Server from Tools>>Options>>VI Server. 

 

I also enabled the VI server in tools options as described in the error, but that didn't worked either.

 

Any other idea's? 

0 Kudos
Message 6 of 29
(5,618 Views)

I did something very similar and opening the references worked without problems. Are you sure the VI is at the specified path on the RT system?

 

And something else, now you're opening new instances of the "Encoder read.vi" every time the VI is called, so you won't be able to use the shift register in the "Encoder read.vi". Open as many instances of "Encoder read" as you have tasks, then wire the array of references to the for loop along with the task array.

See image for a rough draft.

 

Reentrant-RT-Caller_BD.png

Message 7 of 29
(5,609 Views)

@dan_u thanks for your reply and noticing me to the SR. I know created a case which only gets executed at the first iteration, it does create then the necessary references

 

 sad.JPG

 

I don't get any errors now, but I don't get any data either. The blue line from array2 doesn't retrieve any values from the for-loop. What makes things more complicate is that I can't debug in the for-loop either because of the use of reentrent...

 

😞 pffffffffff  

0 Kudos
Message 8 of 29
(5,588 Views)

You can use the FP.open method after opening the VI reference to open the front panel of the VI that has just been created. Then you should be able to look into it and debug it.

 

0 Kudos
Message 9 of 29
(5,581 Views)

Your For loop is being fed a non-initiialised shift register.  If this array is empty, the contents of the loop will execute ZERO times (Code will not be run).

 

You need to initialise the shift register outside the loop.

 

Regards

 

Shane

Message 10 of 29
(5,557 Views)