UDP/IP connection

UDP is a very simple Ethernet connection. UDP data are sent without a mechanism for determining whether the telegram has arrived or not. For UDP communication to work the port number on both sides must be known.

The BX9000 sends data to a VB6 program, which returns the data again.

UDP/IP connection 1:
UDP/IP connection

Step 1: Preparation of the UDP communication

FB_IpStartSession

The function block allocates resources on the controller for the UDP/IP communication. The function block becomes active with bStart. bBusy is set as long as the function block is busy. iDevice should always be set to zero. iPort is used for the local UDP port number of the BX9000. iMaxConnection indicates the maximum number of connections (up to 3). The eSocketType is set to "SOCK_DGRAM". eSocketProtocol must be set to "IPPROTO_UDP" for UDP communication. tTimeOut is not used for UDP communication. The iSession must be linked with the following FB_IpSend and FB_ipReceive function blocks.

Step 2: Sending of UDP frames

FB_IpSend

A UDP frame is sent with a positive edge of bStart. The IP address is described with sRemoteIPAddr and the destination UDP port number with iPortNo. The sender UDP port number was already configured in the FB_IpStartSession. If bBusy is reset by the function block the command was executed.

Step 3: Receiving of UDP frames

FB_IpReceive

This function block is used for receiving data. When the function block is called the block monitors the arrival of UDP frames. Up to 4 UDP frames are cached, further UDP frames are discarded. sRemoteIPAddr can be used to set up an IP address filter to limit data reception to a particular device. To receive all UDP frames enter an empty string or leave the variable open. If an IP address filter was configured the port number can also be filtered. Simply enter the corresponding port number in variable iPortNo. To receive all UDP data leave the variable open
If data are received the variable bValid is set to TRUE. The data are now valid. If the value of the variable cbBytesInStream is not zero, the variable linked with the function block is too small and data remain in the buffer.

Sample program

UDP/IP connection 2:
Sample program

Example

UDP/IP connection 3: Download VB6 program as TCP/IP server zip file (sample file)
UDP/IP connection 4: Download BX9000 TwinCAT project as TCP/IP client, prx file (sample file)

udp server.zip
bx9000_send udp to vb.prx