From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Automotive Ethernet

cancel
Showing results for 
Search instead for 
Did you mean: 

Raw Ethernet Frame Decode and Encode Example

This example contains the Raw Ethernet Frame Decode and Raw Ethernet Frame Encode VIs which demonstrate how to capture, log, transmit, and process raw Ethernet frames from the network in LabVIEW. There are two versions of the Ethernet Project contained in the attachment: one which runs the example on a Windows host PC and one which runs from an NI Linux Real-Time controller. Each project contains identical sets of VIs. The VIs are built from a library of VIs that work together to wrap various Ethernet packet sniffing functions available from WinPcap, a Windows packet capture program. For setup instructions, see the readme in the attachment.

 

The following image depicts how the Ethernet frames are interpreted in this example: the raw hexadecimal string is parsed into LabVIEW data types for the Destination MAC address, Source MAC address, optional VLAN Tag (also called 802.1Q header), and EtherType. The Payload is left as a hexadecimal string in LabVIEW. The CRC/FCS field of an Ethernet frame is not present at this level of decoding/encoding because it is already stripped away by the NIC; if a packet does not have a correct CRC/FCS, it would be discarded.

 

By Bill Stafford (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia CommonsBy Bill Stafford (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons

 

Note: if you are unable to see VLAN tags, you may need to configure your network adapter to display them. Follow these instructions from the Wireshark website to do this.

 

The attached zip folder contains the following files:

rawEnetZipContents.PNG

Message 1 of 12
(15,780 Views)

As a note for anyone using this example with LabVIEW 2017 on an RT target.  This installs new software onto the Linux OS.  In 2017 the opkg config file points to the wrong repository.  It will give errors when you run the install but these are easy to miss.  If you try to run the example you will get error 13. 

 

To repair you need to fix the opkg file.  Details are documented here:

https://forums.ni.com/t5/NI-Linux-Real-Time-Discussions/LabVIEW-2017-RIO-17-0-PSA-Feed-Adjustment-fo...

 

0 Kudos
Message 2 of 12
(15,132 Views)

Hi,

 

This example is really useful and I try to adapt it to my specific application. However I don't understand how the array of string is passed to the dll in Write N Packets.vi (how it is used in the library actually). Would it be possible to have the source code of the lvpcap64 library please?

 

Thank you in advance.

0 Kudos
Message 3 of 12
(14,536 Views)

 

The source code for the lvpcap library includes private NI code that can't be shared at this time. I will do my best to explain how it works without sharing the code directly.

 

The array of strings is passed into the Call Library Function Node as a void *. The lvpcap library will reinterpret this argument as LStrHandle * (an array of LStrHandle--see definition of LStrHandle below).
Each element of that LStrHandle array will be dereferenced to access the uChar array as defined in the LStr struct. This uChar * will be cast to u_char * and then passed into the pcap_sendqueue_queue function implemented in wpcap.dll (see this page for how that function works). After all the strings are queued up, the pcap_sendqueue_transmit function is called to transmit them. I hope this helps.

 

Definition of LStrHandle (from LabVIEW include file extcode.h):
typedef struct {
int32 cnt; /* number of bytes that follow */
uChar str[1]; /* cnt bytes */
} LStr, *LStrPtr, **LStrHandle;

Message 4 of 12
(14,523 Views)

That is perfect, thank you very much.

0 Kudos
Message 5 of 12
(14,519 Views)

Hi:

   It really works! Both on 32 and 64 bits windows。

   However,everytime Windows application switches,somepackets would be missed。

   Raising Vi priority,using inline,cannot solve the problem。  

0 Kudos
Message 6 of 12
(14,363 Views)

Hello, I've installed Winpcap, and followed the steps, but when run the vi (decode or endoce) the next error shows up:

Call Library Function Node in Ethernet Palette.lvlib:

Initialize.vi:5890001.

Can you help me?

0 Kudos
Message 7 of 12
(14,010 Views)

Hi,

Do you see an error code or any other information in the error dialog box?

To help rule out any issue with the WinPcap installation/setup, could you install and run Wireshark from https://www.wireshark.org/#download? Wireshark depends on WinPcap, so we can narrow down the issue this way.

0 Kudos
Message 8 of 12
(13,997 Views)

Hello, the error dialog box in the principal vi shows that:

Error 13 occurred at Call Library Function Node in Ethernet Palette.lvlib:Initialize.vi:5890002->Ethernet Palette.lvlib:Ethernet Initialize.vi:2010001->Raw Ethernet Frame Decode.vi

 

And if I run the Initialize.vi, the error occurs in the Call Library Function Node as you can see in the image.

I'm running LabVIEW 2015 on Windows 10 x64

Thanks.

0 Kudos
Message 9 of 12
(13,914 Views)

I have used this Labview project on Windows 7 and it works properly.

However, recently I upgraded my PC to Windows 10. Now there are no packets getting received in the Raw ethernet frame decode vi

I searched online and found that Win10pcap needs to be installed for Windows10. Still there is no packet being received. I am able to capture the raw ethernet packets on Wireshark indicating that Win10pcap is correctly installed.

 

Is there any updated version of this labview project for Windows10?

 

Also, on Windows 7 PC, I am not able to send Ethernet frames with size larger than 1518 Bytes (Jumbo frames). Is that a limitation of the Labview project?

0 Kudos
Message 10 of 12
(11,872 Views)