fishman - 2023-02-14

Hello everyone I'm a new hand of codesys, I'm learning the tcp/ip of it, I build a simple FB named "make link" which package a tcp client like this:

ip_addr_FB.sAddr := '192.168.0.16';
TCP_Client_FB(
    xEnable := GVL.switch,
    xDone => xDone,
    xBusy => xBusy,
    xError => xError,
    udiTimeOut := udi_timeout,
    ipAddr := ip_addr_FB,
    uiPort := 9999,
    eError => ,
    xActive => xActive);

and then I call it in a signal task, wait another task named "write" call its handle, the task who call it like this:

iMessageSize := SIZEOF(sSqlScript);
IF iMessageSize <= 255 THEN
    FOR index := 0 TO iMessageSize BY 1 DO
        byTcp_wr_data[index] := sSqlScript[index];
    END_FOR

    TCP_Write_FB(
        xExecute := TRUE,
        udiTimeOut := ,
        xDone => xWriteDone,
        xBusy => xWriteBusy,
        xError => xWriteError,
        hConnection := hConnection,
        szSize := SIZEOF(byTcp_wr_data),
        pData := ADR(byTcp_wr_data),
        eError => tcpError);
    TCP_Write_FB.xExecute := FALSE;
    TCP_Write_FB();

ELSE
    eError := TRUE;
END_IF

now I found a question, if I call the "write" FB like this:

wri(sSqlScript:=mylog,hConnection := makelink.TCP_Client_FB.hConnection);

it can't write to server continuously, the xBusy will be true when the first cycle and be false the next cycle come

then I change it like this:

wri(sSqlScript:=mylog,hConnection := makelink.TCP_Client_FB.hConnection);
    wri();

just like the reset of timer, and then it become right, why it need once empty call?