From Thursday, May 23rd (05:00 PM CDT) through Friday, April 24th (1:30 AM 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.

Example Code

Network PING (.NET)

Code and Documents

Attachment

Overview

These examples utilize the built-in Windows OS Ping feature to perform a "Ping" using LabVIEW. Examples are included with and without .NET calls.

Description

In real world network-based applications it is important to know if a link is up and running, as well as cable and connector statuses (checking for damage, water intrusion and such...). To obtain such feedback, we can use the built-in Windows OS ping feature. After a successful ping session, users can execute more complicated network tests. The most important step in executing ping commands is to not generate too many requests and to not upset the Network Managing team, especially if the ping command would be part of automated routing inside a complex application.

Steps to Implement or Execute Code

  1. Open the attached VI (DOTNET - Network Ping.vi or Get Ping Timing.vi) best suited for your application. Note that Get Ping Timing.vi is the same task minus DOTNET
  2. Configure tha appropriate IP address, buffer size (SetSize), and timeout
  3. Run VI

Requirements to Run

Software

  1. LabVIEW 11.0 or later

Hardware

  1. N/A

Additional Images

Block Diagram

DOTNET - Network PING.png

2013/04/25 Update:

Memory leak detected!

Ping2.png

Ping timing information can be obtain from WMI query

PingOverWMI.png

Example attached.

-Artur

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
bevis99
Member
Member
on

The example is better than ping command. 

GriffinRU
Member
Member
on

System command was giving me some troubles with SoftMon.exe under LANDesk managment...

-Artur

tshelleyamrc
Member
Member
on

Is there a way to send ping command from cRIO platform, using .NET?

Thanks,

Tim

GriffinRU
Member
Member
on

Hi Tim,

Probably not, but if you can create proper environment to run .net on you target device... well just for ping command - sounds silly.

What you can do, is to create a workaround by opening a TCP port with timeout and data payload if you need one.

-Artur

tshelleyamrc
Member
Member
on

Thanks,

I have an application running on a crio which needs to connect to a database which does not have a static IP address. I just want to ping the Hostname to get the IP address, to open the DB connection. Any thoughts, on the best way to do it?

GriffinRU
Member
Member
on

Data Communications -> Protocols -> TCP -> "string to IP" and "IP to string"

-Artur

P.S. And by the way you should be able to open port with name not just IP, and later convert to IP...

tshelleyamrc
Member
Member
on

excellent i'll sorted.. an oversight on my part.

NickRH
Member
Member
on

Hi all,

Having a bit of a problem implementing this code, I seem to always get a `0` value (Sucess) from the Ping commmand even when I`m disconnected. ( Both LAN and WiFi) I`ve double checked in command line and ping fails. Any ideas where I`ve gone wrong ?

NetpingBlock.JPG

Thanks in advance,

GriffinRU
Member
Member
on

Works fine, try to increase payload -> pings timer resolution is 1ms at fast networks you might be below 1ms on round trips...

-Artur

NickRH
Member
Member
on

Thanks Artur,

I tried Ping from the CLI, it would appear my initial Ping speed is sub 1 ms and the following 3 are > 1 ms.

I have put in a check to look at the `Roundtrip speed` too, seems to work.  Not sure why but If I leave the IP address blank and disconnect the network I still get a valid connection. Any idea why ?

GriffinRU
Member
Member
on

blank ip = localhost -> make sense

NickRH
Member
Member
on

Ah ok, I see.

I`ll have to be careful that I don`t pass a blank string in then. (I`m using the Ping to check for network availability.)

Thanks for your help Artur.

EricHayoz
NI Employee (retired)
on

I have created a Community Example Program which may be a great extension to yours (it also uses Windows OS functionalities, namely netsh). It performs the scanning of WiFi hotspots nearby, lists them in a ring, shows available network profiles and connects to a chosen hotspot (kudos welcomeSmiley Wink) :

 

WiFi Network Scanning and Connecting with LabVIEW - Discussion Forums - National Instruments
https://forums.ni.com/t5/Example-Program-Drafts/WiFi-Network-Scanning-and-Connecting-with-LabVIEW/ta...

 

Screenshot_Front.PNG

Eric H.
Applications Engineering
National Instruments
alecjcook
Member
Member
on

snippet.pngLangham ping crash.PNG

Hi, I am having trouble running this code. Most of the time this runs fine, but occasionally I get this horrible invoke node error "Exception has been thrown by the targer of an invocation". Does anyone know what this means or how to avoid it? I have put a while looop around this code, but when this exception happens, it continues to happen. Any ideas?
Many thanks, Alec

Contributors