Bootproject, TCP Server and booting

JorTec
2016-11-30
2017-01-13
  • JorTec - 2016-11-30

    Hi all,

    I have an application which has uses the function block TCP_Server3 from WagoLibEthernet_01.lib. I'm using the Wago 750-881.
    When I login and start the program in Codesys, TCP communication works.
    After I created and transferred the bootproject while logged in, I log out and disconnect power from the PLC and reconnect power after a few seconds. I see that my program works because I'm increasing and decreasing an analog output every second. But if I try to send a TCP message (using Packet Sender), the PLC does not respond on this message.

    I find it very weird that my program only works partially when using the boot program.

    Is there anything I forgot to do?

    Edit: I just figured out that my bootproject only works fully when I connect power when the Mode Selector Switch is in the center position (stop program processing) and I move it to the top position (start program processing) while powered on. When I connect power if the switch is in the top position, my program does not work 100%.

    Any ideas?

     
  • JorTec - 2017-01-13

    Hi all,

    For weeks I haven't been able to solve my issue and would really appreciate your help. Ich looked into it further and changed my PLC, but no succes. I'm now working with Function Block TCP_Server from WagoLibEthernet_01.lib with the Wago 750-880. When I load my project with Online -> Login and start afterwards, everything works fine. However, when I create this program as bootproject, I have the following results:
    1)
    PLC is booted with 24V and the Mode Selector Switch is in the middle position (STOP). After the PLC has booted (all LEDs are or blink green), I move the Mode Selector Switch in the upper position (RUN). If I perform these steps, I have no issues and I can communicate perfectly via TCP.

    2)
    PLC is booted with 24V and the Mode Selector Switch is in the upper position (RUN). All functionality of my code seems to works, except TCP communication. For debug puposes I wrote the error codes from TCP_Server in a CSV file. TCP_Server always returns error 16#8001 (No socket descriptor available). If i change the Mode Selector Switch to the STOP position and back to RUN, this doesn't effect the result. I keep getting error 16#8001.

    At the end you will find my code.
    I've tried multiple solutions, but somehow I'm unable to fix this... I assume I'm doing something wrong or that I have to wait until the PLC has initialized something before I may call TCP_Server?

    I really hope you can help me.

    FUNCTION_BLOCK TCPServer_FB
    VAR_INPUT
    END_VAR
    VAR_OUTPUT
    END_VAR
    VAR
        tcpServ: TCP_Server;
        receivedData : ARRAY [0..MAX_RECEIVE_TCP_SERVER] OF BYTE;
        transmitData : ARRAY [0..MAX_SEND_TCP_SERVER] OF BYTE;
        startSend : BOOL;
        transmitCount : WORD;
        receiveCount : DINT;
        dataWrite: STRING;
        index: DINT;
        result : BOOL;
    END_VAR
    
    tcpServ(xEnable  :=  TRUE,
    wPortNumber := 2455,
    ptSendData := ADR(transmitData),
    diSendCount := transmitCount,
    xStartSend := startSend,
    aReceiveBuffer := receivedData,
    diReceiveCount := receiveCount
    );
    IF tcpServ.diError > 1 THEN
        dataWrite := 'Error';
        dataWrite := CONCAT(dataWrite, DINT_TO_STRING(tcpServ.diError ));
        dataWrite := CONCAT(dataWrite,ASCIIBYTE_TO_STRING(13)); (*CR*)
        dataWrite := CONCAT(dataWrite,ASCIIBYTE_TO_STRING(10)); (*LF*)
        CSV_writeData('S:\Logging\EthernetError.csv', LEN(dataWrite), ADR(dataWrite));
    END_IF
    IF receiveCount >= 10 AND tcpServ.xClientConnected = TRUE THEN
        (*At least 6 bytes need to be received (minimum of Lemnatec Communication Protocol*)
        dataWrite := 'Received Data: ' ;
        dataWrite := DINT_TO_STRING(receiveCount);
        dataWrite := CONCAT(dataWrite,ASCIIBYTE_TO_STRING(13)); (*CR*)
        dataWrite := CONCAT(dataWrite,ASCIIBYTE_TO_STRING(10)); (*LF*)
        CSV_writeData('S:\Logging\EthernetLog.csv', LEN(dataWrite), ADR(dataWrite));
        IF receivedData[0] = cStartHeader AND receivedData[receiveCount-2] = cEndMessage  THEN
            (*Valid message header, process data*)
            result := processCommand( (receivedData[1] + receivedData[2]*256), receivedData[3], (receivedData[6] + receivedData[7]*256), ADR(receivedData[8]) );
            processResponse( (receivedData[1] + receivedData[2]*256), receivedData[3], ADR(transmitData[0]), ADR(transmitCount), BOOL_TO_BYTE(result));
            startSend := TRUE;
        END_IF
    END_IF
    IF receiveCount > 0 THEN
        (*Clear receive buffer*)
        dataWrite := 'Buffer clear' ;
        dataWrite := CONCAT(dataWrite,ASCIIBYTE_TO_STRING(13)); (*CR*)
        dataWrite := CONCAT(dataWrite,ASCIIBYTE_TO_STRING(10)); (*LF*)
        CSV_writeData('S:\Logging\EthernetLog.csv', LEN(dataWrite), ADR(dataWrite));
        FOR index := 0 TO receiveCount BY 1 DO
            receivedData[index] := 0;
        END_FOR
        receiveCount := 0;
    END_IF
    

    And my PLC_PRG

    PROGRAM PLC_PRGVAR
        test :    TCPServer_FB;
    END_VAR
    
    test();
    
     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3
    Talk.ru: 7
    Talk.ru: 8

  • JorTec - 2017-01-13

    Solved. I added a TON of 5 seconds on the beginning. When timer was finished, I started to call TCP Server. This works for me.

     

Log in to post a comment.