TCP/IP Communication: Problem with response data

izzarshah
2011-10-21
2023-08-17
  • izzarshah - 2011-10-21

    Hi everyone,

    I've created a program to communicate with a Festo PLC using Hyper Terminal.

    When I send a command, it sometimes response with a correct response but with an addition of "previous" response.

    For example:

    Command1: Timeout=t#20s<cr><lf>
    Response1: Timeout=t#20s,DONE<cr><lf></lf></cr></lf></cr>

    Command2: Get<cr><lf>
    Response2: Get,DONE<cr><lf>20s,DONE<cr><lf></lf></cr></lf></cr></lf></cr>

    An extract of the program looks like this:

                IF gCmdExecDone THEN
                   strCmdDone:=DELETE(strRecv, 2, iPos);
                   strSendDone:=CONCAT(strCmdDone,',DONE');
                   strSendDone:=CONCAT(strSendDone,'$R$N');            (* $R$N = <CR><LF> *)
                   gStrSend:=strSendDone;
                   diSent:= TcpSendData(Client.diSocket, ADR(strSendDone), SIZEOF(strSendDone), 50);
                   IF diSent <= 0 THEN (*Problem occured*)
                      CloseSocket(ADR(Client.diSocket));
                      Client.stIPAddress:= '';
                      LifeSignTimeoutTimer(IN:= FALSE);
                   ELSE
                      bSent:= TRUE;
                      LifeSignTimer(IN:= FALSE);
                      strSendDone:='';
                      SysMemSet(dwDest:= ADR(diSent), bCharacter:= 0, dwCount:= SIZEOF(diSent));
                   END_IF
                          END_IF
    

    The response marked red above is what bothers me. Meaning that a trace of old response (Response 1) is still there and was send together with (Response 2).
    I've tried SysMemSet and SysMemFree but to no avail.

    Is the response saved into any of the PLCs memory?!? If yes, how can i access them and clear after every reponse being received?

    Thank you in advance

     
  • shooter - 2011-11-01

    If the string is not complete send it is still in memory giving this type.
    i can not read all of your code as i am missing all the commands and functions.

     

Log in to post a comment.