Getting Started with KAS UDP Communications
Introduction
Attached is a sample program showing basic UDP communications between two KAS PxMM controllers. The concepts here can easily be applied to communicating between a PxMM controller and a PC or other non-Kollmorgen product.
With PxMM UDP communications:
- a Port is an internal Software structure that is identified as a Port Number
- The udpCreate function is used to create a Socket which is the combination of a IP address and a Port Number.
- Typically a PxMM requires 2 Sockets: one to receive data and the other to send data
The KAS UDP udpSendTo and udpRcvFrom functions are used to send and receive characters between PxMMs or a PxMM and a third party device.
EXAMPLE: 2 PxMMs using UDP communications to transfer data to each other
Controller | IP Address | Client Port (sending data) | Listening Port (receiving data) |
---|---|---|---|
1 | 10.50.67.226 | 0 | 20 |
2 | 10.50.67.95 | 0 | 20 |
Controller 1
PxMM example project: UDP_SendPositionConmmandAndReceiveFeedback
The program SendPosition below sends a position (1001) over UDP using Port 0 (Client_Port) from a PxMM (address 10.50.67.226 ) to another device (Controller 2) with IP address 10.50.67.95. Prior to sending information with the udpSendTo function a socket (udpCreate) and address “add” (udpAddrMake) are created to send information to Controller 2.
The program MonitorPosition below receives a actual motor position from Controller 2 (address 10.50.67.95) over UDP using Port 20 (Listening_Port). Prior to receiving information with the udpRcvFrom function a socket was created (udpCreate) to receive information from Controller 2
Controller 2
PxMM sample project: UDP_ReceivePositionAndSendFeedback
The program ReceivePosition receives a position from Controller 1 (address 10.50.67.226) over UDP using Port 20 (Listening_Port). Prior to receiving information with the udpRcvFrom function a socket was created (udpCreate) to receive information from Controller 1. The program receives a position and places it in a relative motion command (Pipe Network motion function k MLAxisRel).
The program SendFeedback below sends back a parameter (feedback) over UDP using Port 20 (Server_Port) to Controller 1(IP address 10.50.67.226) . Prior to sending information with the udpSendTo function a socket (udpCreate) and address “add” (udpAddrMake) are created to send information to Controller 1.
- For more information on the UDP functions in KAS:
http://kdn.kollmorgen.com/webhelp/kas/#11.TechRefs/UDP/UDPFunctions.htm?Highlight=UDP - For more information on sending/receiving KAS project variables (in an array/structure format) across UDP using the udpRcvFromVar and udpSendToVar functions.
https://www.kollmorgen.com/en-us/developer-network/pxmm-sending-and-receiving-variable-values-udp/
Comments
thanks for your project,it is useful in my work.
However,i will use a software on the Windows system to communicate with PCMM, but both of them can't receive the message from my software . They can send the feedback to my software. So what do you think about this phenomenon?
Look forward to your reply. Thank you!
In the KAS project,the IP:Port are 192.168.0.102:20.
In the windows system the IP:port are 192.168.0.68:20.
So i can use the send function in KAS which the IP:port are 192.168.0.102:0 to send data to the windows system.And the windows system can get the data.One problem is that my software show that the port is not 0 .
On the other hand , when i used the windows system to send message to KAS(192.168.0.102:20),but the KAS can't get message.
In this test,I only used one computer.
And i have no idea about that why kas can't receive my message.
Look forward to your reply. Thank you!
http://curvegen.kollmorgen.com/webhelp/kas/#11.TechRefs/UDP/UDPRcvFrom.htm?Highlight=udpRcvFrom