# New robot class and file input

Until now we used delays to wait until a robot program has completed processing. This is not reliable, because some programs may take longer than others. The class below features `ProgramRunning` that solves shortcomings of the delay approach.

You can use it in your project or copy parts of it.

## `Robot` class
The following diagram is a summary of the `Robot.cs` at the bottom.

:::{mermaid}
classDiagram
    class Robot {
        +bool ProgramRunning
        +bool Connected
        +string RobotMode
        +Robot(string ipAddress, int dashboardPort, int urscriptPort)
        +Connect() void
        +PowerOn() void
        +BrakeRelease() void
        +Disconnect() void
        +SendDashboard(string command) void
        +SendUrscript(string program) void
        +SendUrscriptFile(string path) void
        +ReadLineDashboard() string
    }
:::

:::{literalinclude} ../code-wi/ISv3RealRobot/Robot.cs
:language: cs
:::

:::{card} ⚡ Live programming
Using the class and waiting until a program finishes using `ProgramRunning`.

Note, a short delay is required as follows:
```{literalinclude} ../code-wi/ISv3RealRobot/MainWindow.axaml.cs
:language: cs
:start-at: SendUrscript(string.Format
:end-at: }
```

:::

## File input

If your robot program grows in size, it may be more convenient to work on a separate file. URScript files use typically `.script` suffix.

You can read a whole program into a string as follows: 

```cs
using System.IO;
string Program = File.ReadAllText("file.txt") + Environment.NewLine;
```

:::{warning}
If the URScript program does not have a newline after the last `end`, PolyScope silently ignores the program.
:::

## Copying an input file to the output folder in Rider

If you want to read a file in Rider, copy the file automatically to the same folder where your program is executed. You can do this as follows:

1. Add the file to your project
1. Right-click on the file.
1. Click `Properties`.
1. Modify `Copy to output directory` to `Copy if newer`.

Now you can now directly read files as follows: 


:::{activity}
Read a file and print its contents on the console.
:::