LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Interfacing LabView with mbed via TCP/IP

Hello,

 

I am currently trying to send bytes of information to and from my mbed via ethernet TCP. I have used the "Simple TCP" VI's available on LabView, and have successfully integrated my mbed and LabView. However, the result is just the client (mbed) receiving data from the server in the form of a waveform.

 

The code I'm running on my mbed currently is as follows: 

 

 

#include "mbed.h"
#include "EthernetInterface.h"

EthernetInterface eth;
TCPSocketConnection socket;
Serial pc(USBTX,USBRX);
AnalogOut annyout(p18);
 
typedef struct packetToSent_s {
uint16_t data[160];      //[80] sends 15 bytes of data, [160] sends 30 bytes of data to Hercules.. this is what needs changing for data type
} packetToSend_t;

packetToSend_t dataOut;

int main()
{
    eth.init();  // dynamically allocate the mbed address, OK aslong as the Host IP is specified
    pc.puts("Initialized!!\n\n");
    eth.connect(); 
    pc.puts(eth.getIPAddress());
    socket.connect("10.58.74.19",23);//connect to the PC at the given IP address and socket, specify in Tera Term and Hercules also
    
    socket.send_all((char*)&dataOut,sizeof(packetToSend_t));  // send the data
    
}


Which simply sends an array of data to the TCP server. I am using Tera Term and Hercules for verification purposes, and the TCP server on Hercules indicates it has indeed received the array of hexadecimal digits. 

 

 

So, I am asking (I am new to LabView) how to modify this VI to:

 

1) Allow the client to both transmit AND receive binary data, instead of a random waveform.

2) Display the received and transmitted data, in binary or hex form. 

 

The data I wish transfer is output from the mbed, such as from a temperature sensor, or the likes. I've attached the VI for reference.

 

Thanks in advance.

J

0 Kudos
Message 1 of 9
(3,970 Views)

Hi,

There's a couple of good resources for developing TCP within LabVIEW. A good start is this one (goes a lot through what TCP is, but it discusses the functionality in LabVIEW):

 

http://culverson.com/beginners-guide-to-tcpip/

 

You can Write and Read to the same TCP connection, created using the Listener function. In order to write binary data, you need to change the data type in to a string, which is what is happening with the waveform in the example project.

 

When you read from the TCP and receive the string data, you will then need to change it back to the data type you expect it to be.

 

Does this help?

Nico

--------
Nico
Systems Engineer

Certified TestStand Architect Certified LabVIEW Architect

0 Kudos
Message 2 of 9
(3,907 Views)

Hi Nico, thanks for the reply.

 

That does help. I understand the conversion aspect. The issue is that I don't need to see the waveform. What I desire is to see some kind of matrix showing the received binary/ hexadecimal data. I am currently using Hercules as a TCP server, which shows the data I am writing to it from the mbed. I want something similar, but in LabView, where I can see the data being sent. As it stands, to my understanding, the simple TCP server/client VI is simply creating a client in LabView, and communicating with it via the server, also in LabView.

 

I have my mbed as the client and want to interface with the LabView client. As is, I am attaching my mbed to the same socket that the server is listening to, and when I compile my program and run this alongside the LabView server alone, the graph can be seen to be writing data to the mbed. However, I have no way of seeing the data I am writing TO the server, and no way of specifying what I wish to write to my client (mbed). So as I see it, I don't actually need the client VI... maybe.

 

Any more information on the above points, please communicate them to me. Thanks again Nico!

 

J

0 Kudos
Message 3 of 9
(3,895 Views)

A TCP/IP connection is always between a client and a server. Since your mbed application is the client, you need to run the server VI in LabVIEW. This server must be running and listening at the moment your client tries to connect. And of course you must use the IP address of the computer your LabVIEW VI is running on in the connect() call in your mbed and the port number in the mbed application and your LabVIEW VI must match.

 

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 9
(3,891 Views)
Hello, thanks for your reply. Unsure if my message got across from above. I have got to a point where my mbed is indeed communicating with labview server VI. The issue is this vi only writes to the mbed, and it writes some kind of "random" value and displays it on a graph or something? I need help amending this so that I can write to the server. As well as read from it, bytes of data. One of my mbed inputs is from a temperature sensor, it would be useful to be able to read the status of the analog pin and write it to the server, displayed as a range of sampled voltages or something. Or write to the server and have the graph display the written values as an amplitude. So the issue is essentially that this server VI is writing to the mbed... How exactly can I get the process reversed so it can read also? Thanks for your time. J
0 Kudos
Message 5 of 9
(3,885 Views)

Well the solution is mostly as simple as replacing the TCP Write function in your example VI with a TCP Read function with the right amount of bytes wired to the count input. Then you need to convert the byte stream data (which in LabVIEW for the TCP nodes is treated as string). For that you can use the Unflatten from String node with the right datatype as input (from your example code probably an array of unsigned 16bit integers) and you may have to select either Big Endian (network) or Little Endian byte order. I'm not quite sure which endianes the mbed uses. 

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 9
(3,879 Views)

There are two TCP write functions in my example. I have tried to use the unflatten from string function, but I am having great difficulty since I've not used LabView before. I made a new VI which was just reading, but am still struggling on how to DISPLAY the read values, even before I even manage to get the server to read from the mbed. Very confused.

0 Kudos
Message 7 of 9
(3,855 Views)

j

0 Kudos
Message 8 of 9
(3,855 Views)

I don't need the client VI, as I see it, since my mbed is the client. Am I wrong? I should just be able to change the server VI so that the server can write (as it is currently) and also read, then display the read values unflattened from a string to the unsigned 16 bit integers. Does the string not need to be flattened after it is output from the mbed, or is that automatically done by the TCP write and read functions? 

 

 

0 Kudos
Message 9 of 9
(3,850 Views)