Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Getting IP address from system
PostPosted: Mon May 19, 2014 4:03 am 

Joined: Tue May 06, 2014 7:11 pm
Posts: 1

Offline
Hi,

I'm currently developing an HMI application under iX Developer 2.10 which will be deployed to two T15B touch panels. The HMI application will generally be identical except for some unique functionalities that will be assigned to one touch panel only and for this purpose, I'm thinking of using the IP addresses from the T15B's as the bases for identification which might then be used to enable the unique functionalities and going away from having to develop two HMI applications. Is there a way of obtaining the system IP address via scripting or from another method which is still readily available for scripting? I've only done generic scripting in iX Developer from previous work and would really appreciate much if anyone can shed some light on this one. Thanks very much in advance.

All the best,

TuneMan


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Fri Oct 17, 2014 4:33 am 

Joined: Fri Oct 17, 2014 4:23 am
Posts: 1

Offline
Hi
I have made a script for getting a IP address.

Just use google "Get local ip address c#"

Code:
//added
using System.Net;
using System.Net.Sockets;

      public static string GetLocalIPAddress()
      {
         IPHostEntry host;
         string localIP = "No 192.*.*.* IP";
         host = Dns.GetHostEntry(Dns.GetHostName());
         foreach (IPAddress ip in host.AddressList)
         {
            localIP = ip.ToString();

            String[] temp = localIP.Split('.');
            if (ip.AddressFamily == AddressFamily.InterNetwork && temp[0] == "192")
            {
               break;
            }
                else localIP = "No 192.*.*.* IP";
         }
         return localIP;
      }


Br.
/Michael


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Thu Sep 21, 2017 1:37 am 

Joined: Fri Jan 27, 2012 4:20 am
Posts: 166

Offline
Works fine. The only thing I had to change, is removing word "static". Not sure what difference does it make?


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Mon Sep 25, 2017 9:56 am 

Joined: Mon Jun 11, 2012 2:10 pm
Posts: 98

Offline
static makes the function usable without instantiating a class instance. For example, say we had the following class

Code:
public class Foo
{
    public int Loc()
    {
        ...
    }
    public static int Stat()
    {
        ...
    }
}

to call Stat(), all you need is Foo.Stat(); while to call Foo() you need (new Foo()).Loc(); as Loc()is an instance function while Stat() is a static function. Note static functions cannot use class instance variables while instance functions can use both class instance and static variables.

_________________
Adam M.
Controls Engineer
FlexEnergy


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Wed Sep 27, 2017 8:02 am 

Joined: Fri Jan 27, 2012 4:20 am
Posts: 166

Offline
Thank You Adam.


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Tue Oct 31, 2017 7:56 am 

Joined: Fri Jan 27, 2012 4:20 am
Posts: 166

Offline
Just noticed, It works, if HMI connected to a network hub or device. How to check the IP address if it's not the case?


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Wed Nov 01, 2017 6:52 am 

Joined: Mon Jun 11, 2012 2:10 pm
Posts: 98

Offline
Under the Sample Programs > Panel/Hardware Management board there is a topic "Display All IP Addresses" to get the panel IP addresses. Maybe this would help.

_________________
Adam M.
Controls Engineer
FlexEnergy


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Wed Nov 01, 2017 8:06 am 

Joined: Fri Jan 27, 2012 4:20 am
Posts: 166

Offline
Hi Adam, thank You for reply.
I tried the sample. It behaves similar. When connected to a hub, the IP address shown is correct. When disconnected, shows 127.0.0.1.


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Thu Nov 02, 2017 7:37 am 

Joined: Mon Jun 11, 2012 2:10 pm
Posts: 98

Offline
Is the IP set static or dynamic?
127.0.0.1 is a loop back IP address. My guess is this is the IP you get when no IP address is assigned because the port is set to dynamic and no DHCP server is connected.

_________________
Adam M.
Controls Engineer
FlexEnergy


 Profile  
 
 Post subject: Re: Getting IP address from system
PostPosted: Thu Nov 09, 2017 10:51 am 

Joined: Fri Jan 27, 2012 4:20 am
Posts: 166

Offline
It is default setting. Is default dynamic?


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron