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 //// Create TCP socket //// diSocket:RTS_IEC_HANDLE; diAddressFamily:INT:=SOCKET_AF_INET; diType:DINT:=SOCKET_STREAM; diProtocol:DINT:=SOCKET_IPPROTO_TCP; pResult:RTS_IEC_RESULT;  //// Non-Blocking mode //// pResult6:RTS_IEC_RESULT; diCommand:DINT; pdiParameter:POINTERTODINT;  //// Connect to server //// 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;  //Create TCP socketdiSocket:=SysSockCreate(diAddressFamily,diType,diProtocol,ADR(pResult));//Non-Blocking modepResult5:=SysSockIoctl(hSocket:=diSocket,diCommand:=SOCKET_FIONBIO,ADR(pdiParameter));//Connect to serversockAddr.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//Ping server pResult2:=SysSockPing(szIPAddress:='192.168.3.78',ulTimeout:=500, ADR(PingTime));// Send Byte send:=SysSockSend(hSocket:=diSocket,pbyBuffer:=ADR(Str),diBufferSize:=1,diFlags:=0,ADR(pResult4));// Rec Byte 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 //Close connection  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)