Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

can I send data over udp/tcp in simulation mode?

drdolittle
2016-06-01
2016-06-05
  • drdolittle - 2016-06-01

    hi, I am trying to apply the tcpudp.pro example project I found on this project to send and receive tcp or udp data from a Codesys simulation of a peice of structured-text code to a C# tcp server or udp server(I will choose between TCP and UDP later, now I just want to get something working).

    I am having no luck with the example, is there a trick to making this work?

    I have tried adding a cyclica task with UDPProducer, and I am guessing I shoudl be setting diSOcket=0 to make the code run UdPOpenSendSocket(iPort)?

    I have set up a UDP server on my computer on port 5000 run the following code, but diSendSocket =0 continously:

    PROGRAM UDPProducer
    VAR
    diSendSocket : DINT :=0;
    iPort : INT:=5000;
    stDestIPAddress : STRING := '127.0.0.1';
    diRecvSocket: DINT;
    bySend : ARRAY[0..10] OF BYTE := 0,1,2,3,4,5,6,7,8,9,10;
    bSent: BOOL := TRUE;
    bActive: BOOL := TRUE;
    END_VAR

    IF bActive THEN
    IF diSendSocket = 0 THEN
    diSendSocket := UdpOpenSendSocket(iPort);
    END_IF

    IF diSendSocket > 0 AND bSent THEN
        bSent := FALSE;
        UdpSendData(diSendSocket, iPort, stDestIPAddress, ADR(bySend), SIZEOF(bySend));
    END_IF
    

    END_IF

     
  • shooter - 2016-06-05

    in simulation this does not work, as the target is not the asame.
    so it does not know how to deal with it.

     

Log in to post a comment.