LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

passing a 2d array from LabVIEW into C++

Hi All;

I have a LabVIEW application that runs a simulation in real-time in my real -time machine(I am using PXI1031 as a real-time machine). Then I am observing the outputs of my program in my host machine. (I am using  shared variables to pass the data from my realtime machine to the host machine).  The output of my simulation program is a numeric 2D array that  contains the position values of each node in my CAD drawing.   Now I would like to continually  import this 2D array into my  VS C++ application, which is a visualization program based on Irrlicht. This visualization program allows real-time rendering. The VI that allows me to see the output of my real-time application and my C++ visualization application run on the same machine.  I was wondering if you could possibly show me a simple example of how to do this.  I am considering using TCP/IP to transfer the 2d array into my C++ application. Would using TCP/IP be the easiest way for this purpose? A simple example,  say a knob generating numeric values, and little C++ program reading the values and printing them on the screen, would help me a great deal. How can I know which IP adress that Labview sends info to so that I can read the values on this particular port using c++?

Thank you so much! 

 

 

0 Kudos
Message 1 of 9
(4,199 Views)

Hi;

I found a C++ library called boost that contains tools to read serial ports. Say I am using  Data Server.VI from examples. How can I access to its outputs? My c++ code has a constructor that accepts two parameters: a string to identify the device name of the serial port, which on Linux is /dev/ttyS0, /dev/ttyS1,... for real serial ports, and /dev/ttyUSB0, /dev/ttyUSB1,... for USB to serial converters. On Windows it is either COM1, COM2, for real serial ports, while it usually starts from COM4 for USB to serial converters. What is the device name that I should use in my c++ code so that I can read the outputs of the Data Server example? For example, the C++ function that I need to use for establishing a communication is this: SimpleSerial serial("/dev/ttyUSB0",115200). I would like to know what I should enter in this code particularly in place of "/dev/ttyUSB0" so that I can communicate with the Data Server. VI.

Thank you. 


 

0 Kudos
Message 2 of 9
(4,179 Views)
Data Server is a TCP/IP example. You won't be able to communicate with a serial communication library to a TCP/IP server. Instead you use the (typically) Berkely socket API (socket(), bind(), connect(), read(), write(), close()) to communicate with a TCP/IP server.
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 9
(4,170 Views)

Hi Thank you for your answer. I was wondering whether I could communicate with the C++ through Data server example  if I define a virtual serial port. Is  there any application example of Berkely socket API that you can refer to?

Thank you. 

0 Kudos
Message 4 of 9
(4,160 Views)

If you google for that you will certainly find more open source code that shows you the use of that API than you can ever possibly digest in your life ;-).

 

Possible starting points:

 

http://cplusplusworld.com/sockets.html

http://en.wikipedia.org/wiki/Berkeley_sockets

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

Hi;

Thank you so much for your response. I was wondering if you could possibly send me a code that reads the outpus of the Data server example. My C++ knowledge is rather shallow so I am feeling quite lost and frustrated:(( I found this example below from  http://cplusplusworld.com/sockets.html and I think I can work off of it. Could you please tell me what I should this code so that I can continuously read the output of the DATA Server example and say print them on the screen.

I would really really appreciate any help.

Thank you so much. 

 

#include <iostream>#include <cstdlib>#include "ComPlusPlus/ComPlusPlus" int main (int argc, char *argv [] ) {if ( argc != 3 ) {  std::cout << "Usage " << argv[0] << " [port] [host]\n";  return 1;} int port = atoi(argv [1]);std::string host = argv[2];	try {	 // -> Comment 1 compp::SocketTcp Client;	 // -> Comment 2 Client.Connect(host, port) ;  // -> Comment 3 Client.Shutdown(); } catch ( syspp::ComException e ) {	std::cout <<  "Exception " << e.what() << "\n" ;	} return 0;	}
0 Kudos
Message 6 of 9
(4,121 Views)
Also when I compile my program with VC++, my compiler can not find some of the header files such as #include <netinet/in.h>
#include <netinet/tcp.h>, #include <arpa/inet.h>. I was wondering if you could tell me where I can find these files. Sounds like all these files are for Linux and I was wondering where I could find windows compatible version of these files. 
Thank you! 
0 Kudos
Message 7 of 9
(4,088 Views)

You should look specifically for Winsock examples. Winsock is mostly Berkeley compliant, but it's headers are built entirely different. While it is possible to write C code that can compile both for Winsock and Unix Berkeley sockets library at the same time, that is the higher arts of multiplattform programming and not possible without at least some involved preprocessor magic in the include section of your C source code.

 

I have no example of communicating from C with the Data Server example. It's definitely not as trivial as doing it in LabVIEW, since you will not only have to deal with the socket library calls itself but also about error handling, byte swapping the data in the stream as LabVIEW uses Big Endian format on all platforms, and many more things.

 

If this is for your education go ahead and work yourself into this. But if it is for a production system you need to deliver with a deadline, I would certainly look for other solutions or hire someone knowledgeable to do this for you.  From the knowledgelevel you seem to have so far you might be looking at a many week long development path before you have anything workable and even longer before its working reliably.

Message Edited by rolfk on 05-19-2010 08:22 AM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 9
(4,075 Views)

And another point. You should maybe not look at using Winsock directly. You seem to be familiar with C++ and I'm sure there are either ready made C++ libraries that wrap the Winsock API or ActiveX components that you could call from your C++ program.

 

I can't help you with this at all, as I have never properly learned C++ and don't use it at all for myself. I prefer the lower level overview standard C gives me to the C++ way of doing things.

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