Professional Documents
Culture Documents
UR robot can communicate with outside equipment through TCP/IP protocol. In this article, we will introduce how robot can
communicate with PC ,Robot will be the Client using URScript and PC will be the server.
Now, we will write C# code with VS2010 running in PC as the server listening client, Server’s IP is local 127.0.0.1,Port is
21.Then start the client with SocketTest. Otherwise we will also start the client as an example in the Polyscope.
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace URServer
{
class Program
{
// The following names are used in the PolyScope script for refencing the
// three working points:
// Name of an arbitrary work point 1
const string csMsgPoint1 = "Point_1";
// Name of an arbitrary work point 2
const string csMsgPoint2 = "Point_2";
// Name of an arbitrary work point 3
const string csMsgPoint3 = "Point_3";
if (sMsgAnswer.Length > 0)
{
Console.WriteLine("Sending message answer: " + sMsgAnswer);
// Convert the point into a byte array
byte[] arrayBytesAnswer = ASCIIEncoding.ASCII.GetBytes(sMsgAnswer+'\n');
// Send the byte array to the client
stream.Write(arrayBytesAnswer, 0, arrayBytesAnswer.Length);
}
}
else
{
if (tcpClient.Available == 0)
{
Console.WriteLine("Client closed the connection.");
// No bytes read, and no bytes available, the client is closed.
stream.Close();
}
}
}
}
}
}
}
Client program
We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. Learn more ✖
(/support/)
Firstly, start the server, then connect the client. Server will send client data ,once server receive the data from clent. Here
Server can only receive “Point_1”,”Point_2” and “Point_3”.
Program:
We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. Learn more ✖
(/support/)
Program
BeforeStart
open≔socket_open("127.0.0.1",21)
Loop open≟ False
open≔socket_open("127.0.0.1",21)
targetPos≔p[0,0,0,0,0,0]
counter≔0
Robot Program
sendToServer≔'send to server'
socket_send_string(sendToServer)
receiveFromServ≔socket_read_ascii_float(6)
Loop receiveFromServ[0]≠6
Wait: 0.3
receiveFromServ≔socket_read_ascii_float(6)
Loop counter<6
targetPos[counter]=receiveFromServ[counter+1]
counter≔counter+1
MoveJ
targetPos
counter:=0
Please pay attention, if we using URScript “socket_read_ascii_float” to receive the data, the data format sent from server to
client in Polyscope is strict.
In this case, when enter “Point_1” in the Polyscope, then send to server, server will send back "(0.4, 0, 0.5, 0, -3.14159,
0)"+’\n’. Using URScript “socket_read_ascii_float(6)” to receive data from server. Normally,receiveFromServ will be “[6,0.4, 0,
0.5, 0, -3.14159, 0]”. receiveFromServ[0] means how many data unit is sent from server. We can take receiveFromServ[0] as
the checking code.
Example: If server send “(0,0,0.1)”+’\n’, client will receive “[3,0,0,0.1]; If server send “(0.3)”+’\n’, client will receive “[1,0.3]”;
We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. Learn more ✖
(/support/)
We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. Learn more ✖
(/support/)