LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visual c++ and Labview variables crossover

Hi. I've searched and found some possible solutions, but I'm still a little confused and wonder if you could help?

 

I've got a game developed in VC++ using the SDL graphics libraries. I want send the coordinates of a character and targets into a VI which will do some calculations for the target and read in a joystick position. The new character position from the joystick, and the new position of the target are then sent back to the c++ program and the graphics are updated.

 

Is this at all possible? What is the best approach? I've looked into activex and dlls but haven't really found an addequate solution as yet.

 

Thanks so much in anticipation...

 

Ted.

0 Kudos
Message 1 of 8
(4,489 Views)

Just my hints: 

 

If you only passing simple datatypes like strings or integers I would prefer a DLL. If they might be a bit complex, like arrays I would use ActiveX.

 

 

0 Kudos
Message 2 of 8
(4,467 Views)
Thanks so much! Do you know any good links or tutorials to achieve this? I'm having trouble finding something comprehensive... Many thanks.
0 Kudos
Message 3 of 8
(4,446 Views)

I'm sorry that I cannot point you to some examples creating DLLs in C++, but google should know it.

And just do a search at ni.com in how to call this dll in LV then via the Call Library Function Node.

 

Christian

0 Kudos
Message 4 of 8
(4,420 Views)

tedthemouse wrote:
Is this at all possible? What is the best approach? I've looked into activex and dlls but haven't really found an addequate solution as yet.

There is no "best" approach. It all depends on the circumstances and requirements. What are your specific requirements that lead you to conclude these are not adequate? Is it speed? Complexity? Unfamiliarity with how to use it? Platform independence?

0 Kudos
Message 5 of 8
(4,409 Views)

Hi,

 

These are the options I've come up with so far:

 

* DLL - I can't compile the c++ as a DLL as I run this as an executable game. I thought I could use a DLL to pass data between the two, but it seems that they create their own instance in Labview and c++ and the variables are not shared.

 

* Activex - I was put off by this as other forums seemed to suggest it was quite complicated...

 

* Command prompt - I was thinking I could trigger the game exe from labview using the system exec function, and then write and read data between the two programs from the command prompt. This seems very inefficient.

 

* Shared/Network variable - This is the way I wanted to go, especially if we have a cRIO in the loop.  I've managed to create a shared variable between Labview and visual studio through measurement studio, but this works on a MFC library and my game runs as a WIN32 console application. I can't seem to access the shared variable from c++.

 

I've looked all over the internet and haven't found many examples of how to do this. I know I'm missing something and any help you have would be fantastic!

 

Thanks so much,

 

Ted.

0 Kudos
Message 6 of 8
(4,364 Views)

You missed quite a few options:

 

- file storage: write information into a file and read it from the other side. Advantage: easy; Disadvantages: slow

 

- pipe communication: using Windows API functions to communicate through named pipes between the application.  Advantage: nice and clean; Disadvantage: complicated Windows API calls

 

- shared memory: using Windows API functions to communicate through shared memory between the application.  Advantage: nice and clean; Disadvantage: complicated Windows API calls

 

- TCP/IP: creating either in your C++ or LabVIEW app a TCP/IP server and communicate through that.  Advantage: nice and clean; Disadvantage: complicated Windows API calls on C++ side.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 7 of 8
(4,342 Views)

Thanks very much for all your help and advice.

 

I've made a Labview TCP server that sends and recieves data from a client written in c++. I've now integrated this into the game and Labview is picking up the player positions to perform calculations and adjust feedback to the joystick.

 

Thanks again,

 

Ted.

0 Kudos
Message 8 of 8
(4,144 Views)