LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ communication between Labview and one application

Good afternoon everybody,

I have a data communication issue. I have an application that reads dll. These dlls must be wrapped : it means that they are themselves built in C++ with the dll from labview. The problem is that Labview, in its structure has a while and nothing goes out until the VI ends up. But, I want access to the value before the VI ends.

So, I was advised to use a TCP a protocol. But, I do not know anything to this subject. I do not know if my application can establish a TCP communication (has it a sense to say that ?). So, I think otherwise to do the communication between VS 2003 that calls the dll of Labview and that builds the second of my application. Do you have a link or a paper to explain me ?

Best regards

0 Kudos
Message 1 of 32
(5,514 Views)

Yes, but the question is different. The topic is linked but not the question. On the other post, the question is how to keep the front panel with a dll.

Here, the question is to establish a data communication (in TCP) between applications in particular way. Should I delete one post or the other ? How to do ?

0 Kudos
Message 3 of 32
(5,496 Views)
It seems like the same question you keep asking about over and over again.

You still have not provided any code to look at. You would obviously need to modify the VI to add tcp/ip communication but without the code, it's impossible to provide any details. If you want to modify the VI and don't know how, start by looking at the examples.
0 Kudos
Message 4 of 32
(5,483 Views)

I would like to provide the code but it is a commercial code and I cannot give it. I want to add the code for tcp. But is there a good tutorial to make a communication between C++ and Labview ? The only thing I would like to do would be to receive the data on C++ so C++ is the client ?

0 Kudos
Message 5 of 32
(5,473 Views)
There are examples for creating a tcp/ip server - Help> Find Examples. The c++ client would be your responsibility.
0 Kudos
Message 6 of 32
(5,461 Views)

@gautierdufourcq wrote:

I would like to provide the code but it is a commercial code and I cannot give it. I want to add the code for tcp. But is there a good tutorial to make a communication between C++ and Labview ? The only thing I would like to do would be to receive the data on C++ so C++ is the client ?


If I recall from the last thread, I would have guessed you want C++ to be the client and LabVIEW to be the server  (Didn't you want to send "stop" to LabVIEW?)  Redefine your end goal in clear wording and I can recommend the most appropriate response.

 

Either way, the code examples for LabVIEW are already mentioned above.  For C++, you can base it off of the Winsock examples from MSDN.  I have personally used these before and they may take a little tweaking but are pretty simple if you are familiar with the language of C++:

 

Client - http://msdn.microsoft.com/en-us/library/windows/desktop/ms737591%28v=vs.85%29.aspx

Sever - http://msdn.microsoft.com/en-us/library/windows/desktop/ms737593%28v=vs.85%29.aspx

 

I usually do something like this (for sending commands TO LabVIEW):

 

  1. C++ code is running all fine and dandy and calls LabVIEW DLL to initalize it.  (Doesn't even have to be a DLL.  You could just have a LabVIEW VI or exe running.   But also am pretty sure I recall you requiring a DLL).

  2. LabVIEW listens on a port to accept connections via client(s) that send command(s).  If you need more than one command, put a loop of some sort or jump back to a "listen" state in your state machine whenever idle.  Here is some sample code of TCP that shows a "server" from here: https://www.ni.com/en/support/documentation/supplemental/06/basic-tcp-ip-communication-in-labview.ht...



  3. C++ code then connects as a client to the same port (5020 in this example) with the IP of the machine running the LabVIEW code.

  4. C++ sends commands on that port as a string.  (The "request" indicator in that LabVIEW code sample would be parsed to figure out what case to execute.  I.E. "data acquisiton" or "stop" or whatever.)  Note:  You can specify on TCP Read VI a mode.  I recommend setting mode to "2" which is "CRLF".  This will read a string until a "/r/n" character escape sequence.  You can read more about the modes in the TCP Read documentation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 7 of 32
(5,455 Views)
And I'm not sure how you are defining 'commercial code'. A commercial program is usually an exe and you would not be able to modify it. If your company commissioned the program and received the source code, the source code is typically yours to modify or disclose as you see fit.

Modifying the source code to get rid of the loop seems just as viable as adding the tcp/ip communication. Writing the acquisition code in c++ to begin with seems just as viable.
0 Kudos
Message 8 of 32
(5,448 Views)

Thank you very much. It is a good starting point for me. I understand that I need to implement something in C++ and in Labview.

In fact, I am going to be precise. I call a dll in a software. Thanks to the previous posts, I can call the dll and managing the VI in this software because I have the frontpanel.

But I need the measures, so I want Labview gives me a scalar.

Is it true that Labview is my server ? And that C++ is the client ?

0 Kudos
Message 9 of 32
(5,441 Views)

I have absolutely no knowledges about property right. I do not how it works. I can indeed modify the code but I had to ask the VI to see the code. Thus, I think I cannot give the VI. Anyway, I am going to implement the codes in Labview and in the C++ code.

0 Kudos
Message 10 of 32
(5,437 Views)