How to: get the state of a network adapter

How to: get the state of a network adapter

hi,
as this question appears from time to time, I created a small sample how to get the network information from the available network interfaces into zenon.
I used the NetworkChange class from the .NET Framework (in namespace System.Net.NetworkInformation) and took the NetworkAddressChanged event to get notified about changes in the IP address. Alternativly, the NetworkAvailabilityChanged event could also be used - but there, I get no events if the IP changed (as the name already suggests ;) )
The sample does the following:
Everytime the IP address of an adapter changes (can be because of a different allocation of an IP address or because we lost the connection or because the adapter was disabled), we get the information from all interfaces in the network. In this demo, I then write this information onto a zenon variable of type string and display that string in the runtime. In reality, you could e.g. execute a zenon function (by calling this.RtFunctions().Item("myFunction").Start()) or writing some values onto a zenon variable on which you can react with a limit violation or a reaction matrix.
Note that I tried my best to eliminate any possible errors, but: I cannot guarantee that the source code is without any mistakes.
It is a zenon 7.0 project optimized for 1280x1024. Feel free to try it out, improve it, add a comment or something else ;)
best regards,
Martin

This is a migrated post! Originally posted on 04.04.2013 by user martins. Please be aware that information can be outdated.

    Disclaimer

    This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.

    The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.

    Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.

    Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.

    COPA-DATA reserves the right to change this document from time to time at own discretion.


    Ing. Punzenberger COPA-DATA GmbH
    Karolingerstraße 7b · 5020 Salzburg · Austria
    www.copadata.com