Hello. I'm using , and would like to use 'localhost' as the "" input. https://help.codesys.com/webapp/RL4Lo8oYYkL-EiF1HG7hca7bLAI%2FTCP_Server;product=CAA_NetBaseServices;version=3.5.14.0 How can this be done? What is the best way to read this operating-system's variable? Should I use a different library? Thank you.
P.S. Would it be easier if I wrote the specific IP address in an *.XML file and read it from there? If so, do codesys has an XML library? Thanks
Could you just use the loopback address 127.0.0.1?
Best is to use loopback, but if you need to know your device IP, you could either use this :
// Gets specific interface IP address FUNCTION GetOwnIp : STRING(15) // Returns IP address from selected adapter. Need SysSocket library VAR_INPUT IndexOfAdapter : INT := 0; // Index of the ethernet adapter to get IP from (base 0) END_VAR VAR sHostName : STRING; // Own hostname Host : SysSocket.SOCK_HOSTENT; // Own host description pIPAddress : POINTER TO DWORD; // Pointer to INADDR containing IP address in_addr : INADDR; // Strong typed INADDR containing IP address sIPAddress : STRING; // IP address in string format END_VAR (* Get own hostname. *) SysSockGetHostName(szHostName:=sHostName, diNameLen:=SIZEOF(sHostName)); (* Get own IP address by its name. *) SysSockGetHostByName(szHostName:=sHostName,pHost:= ADR(Host)); (* Get adress of first adapter *) pIPAddress := Host.pAddrList[IndexOfAdapter]; (* Cast pointer data to INADDR type *) in_addr.ulAddr := pIPAddress^; (* Get string format *) SysSockInetNtoa(pInAddr := ADR(in_addr),szIPADDR := sIPAddress, diIPAddrSize:=SIZEOF(sIPAddress)); (* Function return *) GetOwnIp:=sIPAddress;
Log in to post a comment.
Hello.
I'm using , and would like to use 'localhost' as the "" input.
https://help.codesys.com/webapp/RL4Lo8oYYkL-EiF1HG7hca7bLAI%2FTCP_Server;product=CAA_NetBaseServices;version=3.5.14.0
How can this be done? What is the best way to read this operating-system's variable?
Should I use a different library?
Thank you.
more posts ...
P.S.
Would it be easier if I wrote the specific IP address in an *.XML file and read it from there?
If so, do codesys has an XML library?
Thanks
Could you just use the loopback address 127.0.0.1?
Best is to use loopback, but if you need to know your device IP, you could either use this :