Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

connect Multiple VIs with one Simulink model

Forgive me if it sounds silly. But I need some help on how to connect multiple VIs to the same Simulink model. We are developing a complex simulation model in MATLAB/Simulink with hundreds of model parameters that should be displayed to and manipulated by the users. We decided early on to use LabVIEW to develop the User Interfaces utilizing SIT Simulation interface toolkit to connect to the Simulink models. The reasons were that we used LabVIEW in previous project and were happy with it, it is easy to use to our clients, the LabVIEW User Interfaces mimics the real consoles very well and last but not least the Simulation Interface Toolkit documentation affirms that it is possible to connect multiple VIs with one model. I spent quite some time searching this site for some clue about this last fact without any success. Using global or shared Variables doesn’t help us a lot, because we have hundreds of model parameters to map to. It will make our already complex design even more complex. I suspect that the SIT Connection Manager as it is now cannot do it. I may need to make some modification to the template “sit Client VI Template.vi” or one of the SubVIs used in that template or even do all TCP connection, model initialization and parameter mapping myself from scratch using the VIs shipped with the Simulation Toolkit. Can anybody tall me where to start, before I may scrap the whole approach to realize this project using LabVIEW? I cannot afford to spend more time on this than I already did.

While reading the Simulation toolkit help document, I come across very enlightening examples on how to create a custom I/O Driver and custom FPGA VI with Simulation Interface Toolkit. Is there something like that on how to create custom Host VIs? The only thing I always come cross here is the following paragraph:

“.Using the Simulation Interface Toolkit, you can connect multiple VIs created on the host computer to the same Simulink® model. You also can connect multiple Simulink® models on the same computer to a single VI created on the host computer. “

It doesn’t say how. I do not know why NI did not come up with a similar example to demonstrate this fact. May be it is not as complicated as I think for the other LabVIEW users.

0 Kudos
Message 1 of 13
(4,929 Views)

Good morning!

 

To clarify, do you want to have multiple VIs connect to a single model because you want to organize the parameters? If so it may be easier to use a Tab Control to organize your data (Controls palette»Containers»Tab Control).

 

Otherwise are you trying to have multiple VIs access the same models as it is running or do you want to have them access the model at different times? If it is at different times, you would simply set up the VIs the same way as if you were using a single VI.

 

Regards,

Tanya Visser
National Instruments
LabVIEW Group Manager
0 Kudos
Message 2 of 13
(4,911 Views)

Thanks Tanya for the prompt response.

 We are developing a simulation model with multiple consoles for a central control room mainly for a training purpose. The type and number of consoles are selected by our client and are to be designed as a separate VI. There is no room for a design change here. There is one main User Interface VI, which is responsible to start and initialize the model. The other VIs can be lunched from this Main VI. It is possible that user may lunch as many VIs as possible at same time. When the Main VI is lunched, it will create the TCP connection and loads the model, if it is not yet loaded. User can specify the model default parameters by selecting a file and then starts the model. From this point on, the model is initialized and running with the default parameter values. Now they can lunch one or more console VIs. When lunched a VI should connect to the already running model through the already opened connection and consume data. When it is closed, it should die gracefully without taking the rest with it or closing the connection.

Is it possible to do the following?Check, if there is an already established connection. If there is not, so it is a new lunch and we know that this scenario works fine. If there is a connection, there is another VI already running. So it checks, if the running model is the same as the one specified in its sit Meta Info. If the model is the same, it just subscribes the data it wants without disturbing the existing traffic.

Best Regards.

 

Getachew

0 Kudos
Message 3 of 13
(4,899 Views)

Hi Getachew,

 

The easiest way to do what you want to do would be to use shared variables. You could use the main VI to collect all the data, and write it to shared variables. If network-published shared variables are used, any computer on the network could potentially access the data. There are more complicated ways of doing this but using shared variables is by far the most straight forward.

 

Here's a tutorial that describes the different types of shared variables and how to use them.

 

http://zone.ni.com/devzone/cda/tut/p/id/4679

 

Let me know if this will work for your application.

 

Take care!

Tanya Visser
National Instruments
LabVIEW Group Manager
0 Kudos
Message 4 of 13
(4,881 Views)
Hi Tanya, Thanks for your help. I really appreciate it. Before I posted my question, I already tried many work around. I have developed two test cases using Global Variables and Shared Variables respectively. Both approach works fine for project with limited number of controls/indicators. But, as I mentioned above I have a more complex project with hundreds of parameters to map.The thing is a shared variable can not directly participate in the parameter mapping. Therefore, you end-up having duplicate controls/indicators, one set of controls/indicators on the Main VI for parameter mapping and other exact same controls/indicators on the VI which implements the actual functionality of the console interface. On top of that, you cannot even transfer data directly from indicators on the Main VI to the Shared Variables. You need to use a local variable to do that. This is additional layer of data transfer which may have a big hit on the application performance.The best solution is, if I can find a way to connect every VI directly to the model. It may be difficult to do it for the first time. Still it is a time well spent. If I succeed, it may not be the last time, when I consider using LabVIEW for my project. I really need to know where I should start to do some modifications to the sit Client VI template or to build my own connection using the SubVIs distributed with the Simulation Toolkit.
0 Kudos
Message 5 of 13
(4,869 Views)

Hi Getachew,

 

I'm still working on a solution to connect multiple VIs to one running model at the same time.

 

As a side note, front panel controls and indicators can be directly bound to network-published shared variables by right-clicking them on the front panel and selecting Properties from the right-click menu. In the Data Binding tab you can choose a variable to which you want to bind. That would clean up the block diagram because you wouldn't have to drop down variable nodes.

Tanya Visser
National Instruments
LabVIEW Group Manager
0 Kudos
Message 6 of 13
(4,846 Views)

Hi Tanya, 

 

Thanks, this is a good advice. You know, I come from a text based programming background recently. So, there are many things I do not know yet. Thank you also for working hard on a solution to directly connect multiple VIs to same model.

 

Best Regards.

 

Getachew

0 Kudos
Message 7 of 13
(4,832 Views)

Hi Getachew,

 

I am still looking into this issue for you. I've escalated this question to R&D and am still waiting for a response. Once I get an answer I will make sure the Developer Zone article is clearer.

 

Take care!

Tanya Visser
National Instruments
LabVIEW Group Manager
0 Kudos
Message 8 of 13
(4,782 Views)
Hi Tanya,  Thank you so much. I really appreciate your help. I will eagerly wait for any possible solution. In the meantime, I am following your advice and I am connecting the less complex VIs to the model using the Shared Variables approach. I do not know how long it might take to solve this problem or if there is a solution at all. Connecting this VIs directly to the model later does not take long anyways. So far, I have succeeded to do so for variables with a simple data types. But I have a problem while using Shard Variables for waveform data (Array of Double Waveform, Array of Int16 Waveform). For example, a harmonic wave coming from the model is coerced beyond recognition when it reaches the final VI. We have many wave chart indicators that should receive data from a Simulink model. How should I go about it when it comes to this kind of data types?  Best Regards,  Getachew
0 Kudos
Message 9 of 13
(4,767 Views)

Hi Getachew,

 

I heard back from R&D and there cannot be more than one TCP connection to a model at a time. There can be one central VI communicating with the model and all other VIs would need to communicate to that central VI (not the model). This can be done using shared variables as we discussed.

 

The DevZone article was a little misleading, in that it meant that multiple VIs can connect to a model but not simultaneously.

 

As for using shared variables, to use an array type or waveform type you would want to use Single process shared variables or Network-Published shared variables. These can be accessed from a project in LabVIEW. Is your VI in a project? If it is not I would recomment including it in a project and using the above mentioned variable types to transfer data between your VIs.

 

Take care!

Tanya Visser
National Instruments
LabVIEW Group Manager
0 Kudos
Message 10 of 13
(4,757 Views)