LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW-FPGA and TCP/IP Communication with Matlab/Simulink

Hi, quick question: I am wondering if TCP/IP communication is possible with LabVIEW-FPGA?

 

More backstory: I have some pre-existing code written in LabVIEW-FPGA 2016. I would like to send data from Labview to matlab and from matlab to labview in real time(I am performing processing in Matlab that cannot be done in Labview). Initially, I tried to use the MATLAB Script box, but it is not supported in LabVIEW-FPGA. 

 

Now, I am trying TCP communication, but I cannot get it to work. I am using the TCP labview-matlab code from the matlab site: https://www.mathworks.com/matlabcentral/fileexchange/42567-matlab-and-labview-data-exchange-over-tcp... It works with LabVIEW(in a different project that doesn't use Labview-FPGA), but it does not work with LabVIEW-FPGA. 

 

Any help would be appreciated

 

 

 

0 Kudos
Message 1 of 9
(1,411 Views)

Hi lara,

 


@Iara_S wrote:

Hi, quick question: I am wondering if TCP/IP communication is possible with LabVIEW-FPGA?


Based on assumptions on your LabVIEW skill level (made from your message text) the answer is "No!".

The FPGA has no access to any Ethernet port of your computer!

 

(Technically you may write a FPGA routine to mimic the Ethernet protocols to drive some DIOs with some additional amplifiers attached to drive the usual voltage levels used on LAN cables. But that would be beyond your skills - and mine…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(1,409 Views)

On which target do you want to run that code? What if you transfer the data from FPGA to the host and from there over the TCP to the MATLAB app?

Lucian
CLA
Message 3 of 9
(1,397 Views)

Thank you for your response. Your assumptions about my LabView skill level are correct. 

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

The LabVIEW-FPGA controls a NI myRIO DAQ. MATLAB does not support the myRIO otherwise I would do everything in MATLAB. 

 

Please excuse if what I am about to ask sounds stupid. However,  If I understand your suggestion correctly, you are saying:

LabVIEW FPGA sends data to LabView which sends data to MATLAB? I am not sure how I would send data from LabVIEW FPGA to LabView. 

0 Kudos
Message 5 of 9
(1,372 Views)

LabVIEW FPGA runs directly on the FPGA chip. It looks like LabVIEW but is under the hood simply a VHDL script that gets compiled into a bitfile to run directly on the bare metal. Theoretically one could implement Ethernet in the FPGA and add some external Phy to the digital IOs of the FPGA, but your myRIO FPGA hardware is likely not large enough to do that.

 

But that is only part of the application running on the myRIO. The myRIO also has a NI Linux Realtime OS executing on the embedded ARM CPU. And it needs a LabVIEW realtime (or alternatively a C programmed executable) which loads the FPGA bitfile into the FPGA chip and interacts with it somehow. While it is also possible to just run install the FPGA bitfile residently so it is always initialized on power up and just does its thing controlling the IOs, this is very seldom used in such a way. You do usually somehow want to control how the FPGA actually behaves, based on user input, or some other events that are not all just digital IO directly to the FPGA.

 

This LabVIEW realtime application can do TCP communication as it is for the most part similar to what you can do on your Windows computer. In addition it loads the FPGA bitfile and communicates with the FPGA program through FIFO's, or Registers.

 

In addition if you have a finished Matlab model you could also consider to create a shared library from that with the additional Matlab Coder App.

The resulting C code could be compiled into a shared library for the myRIO Linux OS using the standard gcc compiler and could then be called from your LabVIEW real-time application. As your myRIO uses an ARM CPU, you have to compile your shared library for that architecture. Your standard gcc installation on your PC does not compile to ARM but to Intel x86/x64 instead. You can however install gcc directly on your myRIO from the NI opk repository and then run the compile on there and then you do get the right shared library architecture.

 

If you want to get very fancy and complicated you could also develop your entire control app in C using the NI-RIO C API. You still need to develop the FPGA part in LabVIEW however, if you need any FPGA functionality.

Rolf Kalbermatter
My Blog
Message 6 of 9
(1,344 Views)

The nice thing about the myRIO, its FPGA, and LabVIEW Real-Time is that you have three processors running in parallel (the FPGA, the Atom processor inside the myRIO, and the Intel Chip inside the Host PC).  The myRIO is  truly parallel -- with proper coding, you can have part of the Chip acquiring data and another part of the chip, running at precisely the same time, involved in sending the data coming in up to the LabVIEW RT code.  In our case, as fast as the FPGA puts it in a FIFO, the myRIO LabVIEW code moves it out of the FIFO into a DVR, and another parallel loop on the Target sends the data via TCP/IP (using LabVIEW Network Streams) to the Host PC for saving to disk and doing any higher-level processing we need.

 

I've not tried linking LabVIEW and Matlab -- at what level can you make the TCP/IP link with the MatLab routine?  Does it come from a LabVIEW routine running on a PC to a MatLab routine also running on (the same, or a different) PC?  Once you are at the PC (Windows) level, you can (potentially) "farm out" MatLab processing to a second PC that doesn't even need to have LabVIEW installed ...

 

Bob Schor

0 Kudos
Message 7 of 9
(1,334 Views)

@Bob_Schor wrote:

The nice thing about the myRIO, its FPGA, and LabVIEW Real-Time is that you have three processors running in parallel (the FPGA, the Atom processor inside the myRIO, and the Intel Chip inside the Host PC).


Little correction here. Atom CPUs are also Intel x86/x64 architecture. Not sure how prevalent they still are but between 2008 and 2015 they were THE variant of Intel Core architecture CPUs meant for low power and low cost applications. They were very popular for embedded systems and small mini systems such as used for set top boxes and media servers because they could operate without active cooling and still perform pretty well. They also often included many peripherals on chip so that the manufacturers could pretty much slap some memory and connectors on the board and be done with it.

 

The myRIO (both versions 1900 and 1950 that I know of) contain a Zilinx Zync-7010 FPGA with integrated ARM Cortex A9 x2 cores CPU on it, running at .667 MHz. Binary code, including built executables and shared libraries that need to run on this, need to be compiled accordingly for the ARM Cortex A CPU architecture. And while it should support the NEON SIMD VFPv3 standard according to the datasheet, NI choose for some reason the softfp mode for the ABI, so the binary code needs to be compiled accordingly to use software floating point emulation.

 

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 9
(1,314 Views)

Thank you all for your replies, they have been so helpful. I have managed to solve my problem by following this tutorial: https://learn-cf.ni.com/teach/riodevguide/procedure/quickstart_rt.html. In this way, I can run the FPGA code while also sending data to and from Matlab using TCP in the main VI. 

For reference, I am using a myRIO 1900. 

0 Kudos
Message 9 of 9
(1,294 Views)