Universal Robots Forum

Programming Socketserver with C#

Hey Guys.

I need a SocketServer-Programm that toke informations frome a comandline input (that comandline will start the Server) and save the informations (it will be an text like “Start testing”)

than the Programm will transform this fix Text´s in an array

after that conect with the UR. send him this informations (in the moment i need to send an bit-array [1,1,1,1] later some Text needed to be included)
And after send this Informations to the UR, the UR will send some informations back.

after this backinformation, the Server needed to create an error information that have this information from the UR in it and than the server closed.

And also a other question: how can i Program an DashboardServer or Dashboardclient with C#?
And also can i take an Socketserver and a Dashboardserver in one Programm?
And can a Cobot handel a Dashboardserverconnection and a Socketserver over only one LAN-Cable in the same time?

how can i finde some understandebal informations how to work with socketserver?

Thanks for your help.

i have only an start that is followed skriptet (i have copyed out from Google, but the first test shows it works, if you have some other solutens please let me know):

static void Main(string args]
{
string sHostIpAddress = “10.3.225.1”;
int nPort = 21;

IPAddress = IPAddress.Parse(sHostIpAddress);
IPEndPoint localEndPoint = new IPEndPoint[ipAddress, nPort);

Hi,

Yes you can open several connections between your C# program and your robot.
You can implement the Dashboard server protocol yourself: instantiate a TcpClient, write the commands and parse the return.

You can also use a library that has already implemented this for you, for example : https://underautomation.com (This commercial library is on Nugget, the showcases are open source on Github, all protocols are implemented in .NET : Dashboard server, primary interface, variable reading, file manipulation, …)

using UnderAutomation.UniversalRobots;
...
var ur = new UR();
ur.Connect(“10.3.225.1”);
ur.PowerOn();
ur.ReleaseBrake();
ur.LoadProgram("prg1.urp");
ur.Play();

Thanks for the first help for the Dashboard.

Now i only have the problem how to writh a socketServer witch starts with sending data .
ii have big problems to read and interpred C# so i do not understand the commands and can not handle them well.

So any body can help me with a socketserver witch start sending, and then start listening?
it is also possible to writh in C or Python.

thanks for all your help

can i also send “play” as Bite-code to the UR?

I don’t understand your question.
Maybe this would help, you can also send raw custom dashboard commands :

ur.SendCustomDashboardCommand("play");

i mean: How can i do this without the UnderAutomation.UniversalRoborts Lib.

Hi,

A ‘C’ library for communicating to the UR robot does not exist (at least I have never seen one), so I would not target the C language. There is the C# SDK and it is a commercial product so it probably comes with some support. I would take the advice of androidflorent.

If you want to gain a general understanding of how to remotely control the robot then I would start with this document :
Remote operation of robots
It will point you to Python examples.

@eikefranke try this code :

        System.Net.Sockets.TcpClient tcp = null;
        try
        {
            tcp = new System.Net.Sockets.TcpClient();
            tcp.ReceiveTimeout = 2000;
            tcp.SendTimeout = 500;
            tcp.Connect("10.3.225.1", 29999);
            using (var stream = tcp.GetStream())
            {
                using (var reader = new System.IO.StreamReader(stream))
                {                    
                    reader.ReadLine();// line received after connection
                    var bytes = System.Text.Encoding.UTF8.GetBytes($"play\r\n");
                    stream.Write(bytes, 0, bytes.Length);
                    var answer = reader.ReadLine();
                    Console.WriteLine(answer);
                }
            }
        }
        finally
        {
            tcp?.Close();
        }