From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling DLL FMI Objects in Labview

Hello,

         I am working with Functional Mock Up Interface between Modelica and Labview.
         I have made an FMI Program and now comes the tricky part of Porting it to Labview(We use RT Target with a PCIe6343 Device).
         The easiest and simplest direction i took was to convert this FMI program(written in C) into a DLL.
          Now this FMI program uses FMI objects and FMI functions for data handling.
         My first out of many questions is.
         1.Can i Call a Function specified in The DLL to create an Object in Labview.?
          2.How to get to creating an Object via a C DLL.
         
             Regards

          Raghu

0 Kudos
Message 1 of 4
(3,380 Views)

Hello Raghu,

first of all - have you verified that your FMI dll can run in the LabVIEW Real-Time operating system? If it depends on a run-time environment of Modelica, I suspect your efforts to fail, as you cannot simply use the MS-Windows installers of Modelica to install a run-time environment onto the RT target.

The second issue will the object creation and handling in LabVIEW. There is no native "object data type" in LabVIEW that corrensponds to your FMI objects, so you must either find a way to represent this object in native LabVIEW data types (maybe a cluster will do, but it will cost you quite a bit of time to research and implement this), or you could try to write a so-called "Wrapper DLL", which will create and manage the instances the your FMI objects and pass only the necessary attribute values and method operation results to your LabVIEW application.

Please keep in mind that you will have to use something like C++ or C# for this "Wrapper DLL", as e.g. ANSI C does not natively feature object-orientated programming...

Best regards,
Sebastian

0 Kudos
Message 2 of 4
(3,355 Views)

Hello Sebastien,

                           For now i am not thinking about implementing this on the RT Target.
                           First i want to simulate this in the LV Run time environment.
                           Im having problems here.
                           Problems.
                           1.Since the Code is in C we use Structures and Functions .
                              a.Functions need to share some variables.
                              b. I need to make all these variables global therefore.
                              c.I have read and know this is not a wise practice.

                            2.Next idea is to Implement the FMI Interface as C++ program using Classes.
                               a.This is time consuming as the whole program was written in C.
                               

                          I have a feeling i am running around circles here.
                          WHich of these two would you suggest?.
                          Have you had any experience with Functional Mock Up Interface?

                           Regards

                          Raghu

0 Kudos
Message 3 of 4
(3,353 Views)

Hi Raghu,

 

you cannot directly access global variables that are declared in a DLL from LabVIEW or any other programming environment. The easiest solution for this is to add functions to your DLL which provide dedicated reading and writing access to those globals to external callers.

 

Using C++ instead of LabVIEW will therefore not resolve this issue, as you still need to define data i/o functions inside the DLL to access the global variables.

 

 

But before you start re-engineering your model DLL to include these functions, you might want to re-evaluate the concept of your mock-up interface. From my understanding, a FMU provides the simulation functionality only (give the model some inputs, wait for the calculation to finish, read back the outputs), which can be called through a standardized interface from a quite complex simulation framework. The framework provides data generation and storage, i/o with the simulation model, data visualization and logging. Although writing such a framework in LabVIEW is possible, I would not recommend doing so alone, as you will probably need several month just for concept design and programming.

 

So from my point of view, the only sensible way to go would be to see if your existing simulation framework has an interface (ActiveX, .NET, OPC, TCP/IP low level, ...) that allows you to share data other programming environments. This way, you could implement the user interface in LabVIEW and send the user-changed parameters to the simulation framework, which then forwards them to the model. The model's outputs are then read back from the framework and will be passed to your LabVIEW application, which visualizes them for read-out...

 

Best regards,

Sebastian

0 Kudos
Message 4 of 4
(3,335 Views)