Results 1 to 1 of 1

Thread: UDP Protocol with NETVARUDP_LIB_32.lib

  1. #1
    Join Date
    May 2009

    Default UDP Protocol with NETVARUDP_LIB_32.lib

    First of all Before being able to exchange data via UDP you will have to unable UDP in the Target Settings Screen(TargetSettings.jpg).

    Once set the library NETVARUDP_LIB_32.lib will appear in the library manager.
    Below is the code you can copy, paste in a program to start communicating via UDP.

    You will notice two port 2500 and 3000.
    In case of PLC1 if the Send socket Port is Set to 2500
    In PLC2 then the Receive Socket Port will be set to 2500

    In case of PLC1 if the Receive Socket Port is set to 3000
    In PLC2 then the Send Socket Port is set to 3000

    If you don't use different port, let say you use only port 3000, what will happen if we loose connection with PLC2 for example then PLC1 receive will read the data of PLC1 transmit.

    Hope this code help.

    <<<<<<<<<<<<<<<<<<<<< SAMPLE CODE>>>>>>>>>>>>>>>>>>>>>>>>

    PROGRAM SocketConnection
    IdSendSocket: DINT;
    IdReceiveSocket: DINT;
    aDataToSend: ARRAY[0..9] OF BYTE:= 10,9,8,7,6,5,4,3,2,1;
    aDataReceived: ARRAY[0..9] OF BYTE;
    NbrOfBytesSent: UDINT;
    ClientInfo: CLIENT_REPLY;

    IF init_1 = TRUE THEN
    IdSendSocket:= UdpOpenSendSocket(2500);
    IF IdSendSocket <> 0 THEN
    IdReceiveSocket:= UdpOpenReceiveSocket(3000);

    IF IdSendSocket <> 0 THEN
    NbrOfBytesSent:= UdpSendData(IdSendSocket, 2500, '', ADR(aDataToSend), SIZEOF(aDataToSend));

    IF IdReceiveSocket <> 0 THEN
    ClientInfo:= UdpReceiveData(IdReceiveSocket, 3000, ADR(aDataReceived), SIZEOF(aDataReceived));
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts