1º - I'm trying to test the Internet conection in my device. I got the idea of "doing a ping" to google, for example.
Apparently I can't do it directly, so i tried to open a socket in my application and use the function "SysSockPing" from SysSocket.lib. But always than a tried run it returns "1", in the CmpErrors it means "ERROR FAILED". For my surprise if i connect then send a mensage and then receive it actually works. What I'm doing wrong ?
2º- The time out of SysSockConnect is too long (1 minute approximately). Can i change it ?
 PROGRAMPingTestVAR
 ////CreateTCPsocket////
 diSocket : RTS_IEC_HANDLE;
 diAddressFamily : INT :=SOCKET_AF_INET;
 diType : DINT :=SOCKET_STREAM;
 diProtocol : DINT :=SOCKET_IPPROTO_TCP;
 pResult: RTS_IEC_RESULT;
Â
 ////Non-Blockingmode////
 pResult6 : RTS_IEC_RESULT;
 diCommand : DINT;
 pdiParameter : POINTERTODINT;
Â
 ////Connecttoserver////
 sockAddr : SOCKADDRESS;
 result: RTS_IEC_RESULT;
 pResult3: SYSSOCKET.RTS_IEC_RESULT;
 //pInAddr: INT;
Â
 Â
 //sockAddr.sin_family :=SOCKET_AF_INET;//sockAddr.sin_addr :=SysSockInetAddr('192.168.4.102');
 //sockAddr.sin_port :=SysSockHtons(19998);
Â
 ////PING/////
  PingTime: UDINT;
  pResult2: RTS_IEC_RESULT;
 Â
 ////SEND /////
  send: DINT;
  hSocket : RTS_IEC_HANDLE;
  pResult4: RTS_IEC_RESULT;
  pbyBuffer: POINTERTOBYTE;
  diBufferSize: INT;
  diFlags: INT;
  Str : BYTE :=66; //caractere ASCII em DEC/////REC///// Â
  rec : DINT;
  Str2 : BYTE;
  pResult5 : RTS_IEC_RESULT;////TESTE////
  state : BOOL :=FALSE; Â
  state2 : BOOL :=FALSE;
  checkfail : INT;
  cont: INT; END_VAR
 cont :=0;
 checkfail :=0;
 GVL.ResetCode :=1;
Â
 //CreateTCPsocketdiSocket :=SysSockCreate(diAddressFamily, diType, diProtocol, ADR(pResult));//Non-BlockingmodepResult5 :=SysSockIoctl(hSocket :=diSocket, diCommand :=SOCKET_FIONBIO, ADR(pdiParameter));//ConnecttoserversockAddr.sin_family :=SOCKET_AF_INET;pResult3 :=SysSockInetAddr('192.168.3.73', ADR(sockAddr.sin_addr));sockAddr.sin_port :=SysSockHtons(1234);result :=SysSockConnect(diSocket, ADR(sockAddr), SIZEOF(sockAddr));WHILE(cont<10)DO
 Â
IF(result=0)THEN//Pingserver
 pResult2 :=SysSockPing(szIPAddress:='192.168.3.78', ulTimeout:=500, ADR(PingTime));//SendByte
 send :=SysSockSend(hSocket :=diSocket , pbyBuffer :=ADR(Str), diBufferSize :=1, diFlags:=0 , ADR(pResult4)); //RecByte
 rec :=SysSockRecv(hSocket :=diSocket, pbyBuffer:=ADR(Str2), diBufferSize :=1, diFlags :=0, ADR(pResult5)); END_IF//TesteSend=RecIF(Str2=Str)THEN
  Str2 :=0;
  state :=TRUE;
  checkfail :=0;ELSE
  state :=FALSE;
  checkfail :=(checkfail+1); END_IFcont :=(cont+1);END_WHILE
 //Closeconnection
  SysSockClose(diSocket);IF(checkfail>=5)THEN
  state2 :=TRUE; //teste conexão após os 10 ciclos, sendo true = conexão fail
  GVL.ResetCode :=0;
  ELSE
  GVL.ResetCode :=1;
  state2 :=FALSE;
  END_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
{attribute'qualified_only'}VAR_GLOBALCONSTANTÂ Â _IPSTRING:STRING:='192.168.1.1';//IPtopingEND_VAR
Program
VARÂ Â PingTime:UDINT;END_VAR
//PingcommandIFCmpErrors.Errors.ERR_OK=SysSockPing(szIPAddress:=Const._IPSTRING, ulTimeout:=500, pulReplyTime:=ADR(PingTime))THEN
  PingOk :=TRUE;  ELSE
  PingOk :=FALSE;  END_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2019-01-25
Originally created by: LeonardoP-
dFx hat geschrieben:
Had to issue a ping for an app, using festo hardware running codesys v3.5 SP10
This is my working code :
Global Vars
{attribute'qualified_only'}VAR_GLOBALCONSTANTÂ Â _IPSTRING:STRING:='192.168.1.1';//IPtopingEND_VAR
Program
VARÂ Â PingTime:UDINT;END_VAR
//PingcommandIFCmpErrors.Errors.ERR_OK=SysSockPing(szIPAddress:=Const._IPSTRING, ulTimeout:=500, pulReplyTime:=ADR(PingTime))THEN
  PingOk :=TRUE;  ELSE
  PingOk :=FALSE;  END_IF
I tried the same code and it continues returning cmperror =1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Originally created by: LeonardoP-
Hello community
1º - I'm trying to test the Internet conection in my device. I got the idea of "doing a ping" to google, for example.
Apparently I can't do it directly, so i tried to open a socket in my application and use the function "SysSockPing" from SysSocket.lib. But always than a tried run it returns "1", in the CmpErrors it means "ERROR FAILED". For my surprise if i connect then send a mensage and then receive it actually works. What I'm doing wrong ?
2º- The time out of SysSockConnect is too long (1 minute approximately). Can i change it ?
Had to issue a ping for an app, using festo hardware running codesys v3.5 SP10
This is my working code :
Global Vars
Global constants
Program
Originally created by: LeonardoP-
Global constants
Program
I tried the same code and it continues returning cmperror =1
Did you tryied pinging a local IP address (on the same subnet) ?
Please check your gateway settings. If it is ok, and your Gateway can reach internet, you should be able to ping 8.8.8.8 (google dns server)