# C# Script sent via 30003 port

**URL:** <https://forum.universal-robots.com/t/c-script-sent-via-30003-port/19677>\
**Category:** URScript\
**Created:** [March 4, 2022, 4:43pm UTC](https://forum.universal-robots.com/t/c-script-sent-via-30003-port/19677 "2022-03-04T16:43:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PMonforte](https://avatars.discourse-cdn.com/v4/letter/p/e36b37/32.png) [@PMonforte](https://forum.universal-robots.com/u/PMonforte)\
**Post date:** [March 4, 2022, 4:43pm UTC](https://forum.universal-robots.com/t/c-script-sent-via-30003-port/19677/1 "2022-03-04T16:43:35Z")

</div>

Greetins UR Community,

I am trying to write an URscript on C# which will later be sent to the UR5 via port 30003.

A quick example of a program I wrote is the following:  
string message = “def program():”;  
message = message + “\r\nset\_configurable\_digital\_out(0,True)”;  
message = message + “\r\nsleep(2)”;  
message = message + “\r\nset\_configurable\_digital\_out(0, False)”;  
message = message + “\r\nhalt\r\nend\r\n”;

This is a very simple program which sets an output to to 1 for two seconds and then sets it back to 0

I can run this program perfectly. However, the app I am currently developing is a little bit more sophisticated and I need a socket communication for various reasons. I studied the script manual but I was not successful into getting this done.

This is a short part of the code:

string message = “def program():”;  
message = message + “\r\nset\_configurable\_digital\_out(0, True)”;  
message = message + “\r\nglobal var\_1 = socket\_open(192.168.3.250,10)”;  
message = message + “\r\nwhile(var\_1 == False):”;  
message = message + “global var\_1 = socket\_open(192.168.3.250,10)”;  
message = message + “sleep(0.3)”;  
message = message + “end”;  
message = message + “\global var\_2 = socket\_read\_ascii\_float(6)”;

I am certain this is not the way to do it, but I haven’t found any solution (unlike the former, this one does not run on C#).

Finally, I also struggled with setting a timer:  
string message = “def program():”;  
message = message + “\r\nset\_configurable\_digital\_out(0, True)”;  
message = message + “\r\ntimer\_1 = 0”;  
message = message + “\r\ntimer\_1\_is\_counting = True”;  
message = message + “\r\nsleep(2)”;  
message = message + “\r\ntimer\_1\_is\_counting = False”;  
message = message + “\r\nset\_configurable\_digital\_out(0, False)”;  
message = message + “\r\npopup(timer\_1)”;  
message = message + “\r\nhalt\r\nend\r\n”;

This program runs but timer\_1 is equal to 0 instead of 2.

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![jjbe](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@jjbe](https://forum.universal-robots.com/u/jjbe)\
**Post date:** [March 4, 2022, 8:11pm UTC](https://forum.universal-robots.com/t/c-script-sent-via-30003-port/19677/2 "2022-03-04T20:11:47Z")

</div>

Hi @PMonforte and welcome to the Forum,

1. Did you verify that the script code actually works? I often find it easier to write the raw script code and test it directly on the controller/simulator first before sending it from an external machine/daemon. This way you don’t have 2 layers of code to debug at the same time.

2. If your code-snippets are copied directly from your program it seems like you are missing a few \r\n here and there.

3. In your last example it looks like your are missing the actual timer thread which does the acutal counting.

```auto
  thread Timer_Thread():
    while (True):
      if (timer_1_is_counting):
        timer_1 = timer_1 + get_steptime()
      end
      sync()
    end
  end
  run Timer_Thread()

```

Hope it helps.
