# Stopping and starting the program

**URL:** <https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099>\
**Category:** URCap Development\
**Created:** [August 4, 2022, 12:16pm UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099 "2022-08-04T12:16:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon5418811](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon5418811](https://forum.universal-robots.com/u/anon5418811)\
**Post date:** [August 4, 2022, 12:16pm UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099/1 "2022-08-04T12:16:04Z")

</div>

Hello !  
How do urscript stop the robot’s motion and restore it?  
stop after the beep and start the program after the second beep  
What commands support programmatic suspend and restart of the program  
Thank you

---

<div class="post-metadata">

**Author:** ![terryc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/terryc/32/3006_2.png) [@terryc](https://forum.universal-robots.com/u/terryc)\
**Post date:** [August 4, 2022, 5:00pm UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099/2 "2022-08-04T17:00:59Z")

</div>

urscript can only stop the program with halt but not pause, play, or resume.

![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/c/c4580fc9ce139c946e8c74d6e1580a8dbd36b1a1.png)

The dashboard server can do any of the above:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/5/5f18370b2646701726f1d06f64ec05d33258c24d.png)

A play/stop button can also be wired into the controller.

There are a bunch of ways, if you can describe your goal in more detail, I’m sure the community can help you out.

---

<div class="post-metadata">

**Author:** ![anon5418811](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon5418811](https://forum.universal-robots.com/u/anon5418811)\
**Post date:** [August 4, 2022, 5:47pm UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099/3 "2022-08-04T17:47:35Z")

</div>

```auto
while i > 0:

        #string_from_server = socket_read_string("socket",prefix="",suffix=" N")
        #string_from_server = socket_read_string("socket")
        sleep(2)

        set_standard_digital_out(1, True)                    
    end

```

I want to loop the program  
in the loop read socket At this time, I want to stop the execution of the program  
When the condition with scek = “ok” is fulfilled, I run the program and exit the loop

---

<div class="post-metadata">

**Author:** ![terryc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/terryc/32/3006_2.png) [@terryc](https://forum.universal-robots.com/u/terryc)\
**Post date:** [August 4, 2022, 7:25pm UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099/4 "2022-08-04T19:25:34Z")

</div>

This seems more like a question on basic usage of the urscript library and control structures. Have you reviewed control structures in the script manual?

---

<div class="post-metadata">

**Author:** ![anon5418811](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon5418811](https://forum.universal-robots.com/u/anon5418811)\
**Post date:** [August 4, 2022, 8:06pm UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099/5 "2022-08-04T20:06:48Z")

</div>

```auto
i = 2

        while (i > 0):
            socket_open(ip_extruder,100, "socket")
            sleep(2)   
            socket_send_string("M109 S50","socket")
            sleep(2)
    
            string_from_server = socket_read_string("socket")
            leep(2)

            #set_standard_digital_out(1, True)

            socket_close("socket")
            sleep(2)
                 
            #popup("zamykam")    
        end

```

I want to call the REPEAT cycle until the condition is met  
The above program freezes (blocks) the UR3 operation of the program

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [August 4, 2022, 8:41pm UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099/6 "2022-08-04T20:41:01Z")

</div>

If you have any typos, calls to the socket will lock the pendant up. For example, you have “leep(2)” instead of “sleep(2)”. Sockets are also super laggy, so if you’re repeatedly making calls to it, prepare to lag out anyway

---

<div class="post-metadata">

**Author:** ![cags](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/cags/32/6304_2.png) [@cags](https://forum.universal-robots.com/u/cags)\
**Post date:** [August 5, 2022, 9:37am UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099/8 "2022-08-05T09:37:39Z")

</div>

You need to run the open and close socket functions once only.  
And use the while loop for the send and read functions.

You also need to have all the code (open, close, read, send) within a try/catch statement, to handle an unexpected connection lost from the other side without your code crashing.

---

<div class="post-metadata">

**Author:** ![anon5418811](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon5418811](https://forum.universal-robots.com/u/anon5418811)\
**Post date:** [August 5, 2022, 12:47pm UTC](https://forum.universal-robots.com/t/stopping-and-starting-the-program/23099/9 "2022-08-05T12:47:00Z")

</div>

```auto
zmiena_e = str_cat("M109 S50","\n")

```

problem solved !!!  
the cause was a missing line break
