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

Socket Connection

orpheus
2010-01-25
2010-02-14
  • orpheus - 2010-01-25

    Does anyone have experience using the Sockets library with TCP/IP and CoDeSys V3.3? I am trying to develop a TCP/IP application for the first time and I was wondering if someone could post me an example about Client/Server Communication over CoDeSys V3.3.

    Thanks a lot

     
  • Avgur - 2010-01-26

    I have used only SysLibSockets library for Codesys 2.3. Try to find TcpIp example in Codesys FTP folder http://3s-software.com/index.shtml?sample_projects

    PS. Call Codesys support to get password for the download area.

     
  • orpheus - 2010-01-28

    Thanks Avgur for the answer.

    I'm Calling Codesys support to get password for the download area ........

    thanks again

     
  • Anonymous - 2010-01-30

    Originally created by: crthomas1234

    Hello,

    I have been working on a similar project and after lots of trial and error, I have data being sent over UDP to a specified port.

    The socket interface mirrors the Unix/Windows socket programming with a few changes.

    Here is the code that I am using to send some simple some incrementing integers to a a receiver program on my PC that I wrote using c#.

    CoDeSys V3 supports 2 types of socket layer management. The first is a basic control where you create a socket handle and then write data to that socket. The second is the Asynchronous socket management where you create a task manager to handle all requests and then project the task handler with the function calls so that it can be much more efficient in applications where you are opening, closing, and exchanging data on a lot of different connections.

    I hope this code helps. You will need the following libraries added:

    SysSocket.lib

    SysTypes.lib

    CmpErrors.lib

    ----------------------- DECLARATION ------------------------------------

    VAR

    My_Data: ARRAY[0..4] OF BYTE := [0,1,2,3,4];
    
    Socket_Create_Result: POINTER TO RTS_IEC_RESULT;
    
    Socket_Create_Handle: RTS_IEC_HANDLE;
    
    bFirst: BOOL := TRUE;
    
    Socket_Send_Result: POINTER TO RTS_IEC_RESULT;
    

    END_VAR

    -------------------------- CODE --------------------------------------------

    IF bFirst THEN

    bFirst := FALSE;
    
    Socket_Create_Handle := SysSockCreate(SOCKET_AF_INET, SOCKET_DGRAM, SOCKET_IPPROTO_UDP, ADR(Socket_Create_Result));
    

    END_IF

    My_Data[0] := My_Data[0]+1;

    My_Data[1] := My_Data[1]+1;

    My_Data[2] := My_Data[2]+1;

    My_Data[3] := My_Data[3]+1;

    My_Data[4] := My_Data[4]+1;

    SysSockSendToUdp(

    hSocketUdp := Socket_Create_Handle, // handle to socket
    
    diPort := SysSockHtons(300), // Socket to send to
    
    szDestAddress := '192.168.1.200',  // IP address to send to
    
    pbyData := ADR(My_Data),  // Pointer to data array
    
    diDataSize := 5,   // size of data
    
    pResult := ADR(Socket_Send_Result));
    
     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3

  • Avgur - 2010-02-01

    orpheus hat geschrieben:
    I am trying to develop a TCP/IP application for the first time...

    Read "Beej's Guide to Network Programming Using Internet Sockets" http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html.

    It's a great thing to understand socket programming for beginners!

     
  • DaveW - 2010-02-01

    Hi,

    Hello I am completely new to CoDeSys

    I am in a simular position to Orpheus, investigating creating a TCP socket. Then waiting for a connection. Trying to recieve data, then to reply.

    The example I found was of little help as it was for V2.3 and so converting it to V3.3 required more knowledge than I have at the moment.

    Has anyone a V3.3 example for TCP ?

     
  • orpheus - 2010-02-04

    Thank you very much crthomas1234.........

    Unfortunatly my application can't work with UDP connection because the server is a "Customer Server" and he always use TCP connection...

    Thanks again

     
  • Anonymous - 2010-02-11

    Originally created by: crthomas1234

    Hello, I am sorry, I missed the part about TCP/IP in your orignal post. The functions in the SysSocket.lib are also available for TCP connections.

    But from what I have been told my 3S Support, the TCP functions aren't working well yet.

    I have not tried them myself.

     
  • orpheus - 2010-02-14

    Don't worry.....There is no problem...

    Thanks anyway for your post.

     

Log in to post a comment.