Jump to content

Creating multiple instances of the same VI


klove

Recommended Posts

Could someone kindly set a new user straight on this...

I need to create multiple instances of the same sub-VI to communicate with some number of identical devices on an RS485 bus. I have flailed about using a couple different methods that I have come across in my searches as follows:

1. Used a call by reference node. Result: could only create one instance of the VI. Pehaps I need to make the VI re-entrant, but what I really want is multiple independant instances of the VI...

2. Tried the OpenG "Open_VI_Clone_Reference" function but can't make anything open at all. Does anyone have some simple example code using this method?

3. As I understand it, I should be able to also do this with something known as a VI template, but as of yet have been unable to find any documentation on this.

I would really appreciate some guidance on what direction I should be heading with this, and perhaps a simple example of creating the multiple instances.

Thanks,

Kirk :headbang:

Link to comment
1.  Used a call by reference node.  Result: could only create one instance of the VI.  Pehaps I need to make the VI re-entrant, but what I really want is multiple independant instances of the VI...

3.  As I understand it, I should be able to also do this with something known as a VI template, but as of yet have been unable to find any documentation on this.

3670[/snapback]

Combine the two methods:

1. create a template (see picture) the same way you would do with a normal vi. Vi and templates are same, except of the tailing "t" in the file extension. In the explorer (for Windoze) one can convert from one type to the other by removing/adding the "t".

post-253-1106722444.png?width=400

2. Call this template with the "call by reference node". LV creates a vi-instance of this template, and you are not limited to one instance.

Didier

Link to comment
  • 2 weeks later...

In the OpenG toolkit there is a VI that you can point to any other VI and it will make a copy of your VI, as a template, then open a copy of the template, (get it into memory) then delete the physical copy it just made.

Palettes>>Application Control>>OpenG Application Control>>Open VI Clone Reference.

Not only is it a nifty VI, it is a good, compact example of templates, etc. (But you should still study the NI Week 2004 presentation referenced above).

Link to comment

Let me chime in here just to suggest that the application may neither require nor benefit from multiple instanciations of a VI. The only thing I know about the application so far is that you have multiple identical devices with which you need to communicate (and thus perhaps maintain state information on them). But you also said that they share a common RS-485 bus. So, is it correct to say that the system hardware constrains you to only communicate with one device at a time?

If this is the case, could you do all your operations in a for loop, indexing on some array of state clusters? Unless the devices may be in multiple states requiring more or less access to the shared resource (the RS-485 communications channel), it may be much simpler to design a system that just traverses from device 0 to device N-1, calling a common code block that takes state info as input and produces state info as output. The array can grow or shrink at runtime as needed to accommodate device additions or deletions if this is a requirement. Fundamentally all presentation to the user interface begins with arrays of controls/indicators, which may appear as tables or lists.

If you choose to go the dynamically instanciated VI route, you'll still need some mechanism (a semaphore, or a non-reentrant subVI) to marshal the access to the shared resource.

Your call - I've designed such things both ways in the past. Just figured it wouldn't hurt to ask about the particulars a little more.

Best regards,

Dave

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.