> For the complete documentation index, see [llms.txt](https://stage-precision.gitbook.io/grid/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stage-precision.gitbook.io/grid/scripting/api-reference/io-api/udp.md).

# UDP

### Accessing a UDP Object

UDP Objects are accessed through their Scripting ID.

For example:

```python
sp.UDP1
```

If multiple UDP Objects exist in the project, each Object uses its own Scripting ID:

```python
sp.UDP1
sp.UDP2
```

The UDP Object's configured network settings are used when sending data from scripting.

### `send_ascii()`

Sends a String through the UDP Object.

#### Syntax

```python
sp.UDP1.send_ascii(message)
```

#### Parameters

| Parameter | Type  | Description     |
| --------- | ----- | --------------- |
| `message` | `str` | Message to send |

#### Returns

`None`

#### Example

```python
sp.UDP1.send_ascii(
    "Hello"
)
```

### `send_hex()`

Sends a hexadecimal String through the UDP Object.

#### Syntax

```python
sp.UDP1.send_hex(message)
```

#### Parameters

| Parameter | Type  | Description         |
| --------- | ----- | ------------------- |
| `message` | `str` | Hexadecimal message |

#### Returns

`None`

Both spaced and compact hexadecimal Strings have been verified as valid inputs.

#### Spaced Hexadecimal String

```python
sp.UDP1.send_hex(
    "48 65 6C 6C 6F"
)
```

#### Compact Hexadecimal String

```python
sp.UDP1.send_hex(
    "48656C6C6F"
)
```

### `send()`

`send()` is a generic UDP send function.

The following input types have been verified:

* `str`
* `bytes`
* `list`

#### Syntax

```python
sp.UDP1.send(data)
```

#### Returns

`None`

#### String

```python
sp.UDP1.send(
    "Hello"
)
```

#### Bytes

```python
sp.UDP1.send(
    b"Hello"
)
```

#### List

A list of integer values is accepted:

```python
sp.UDP1.send(
    [72, 101, 108, 108, 111]
)
```

{% hint style="info" %}
The supported Python inputs above have been verified. The internal conversion behavior of `send()` is not covered by this reference.
{% endhint %}

### `sendBytes()`

`sendBytes()` accepts data for transmission through the UDP Object.

The following input types have been verified:

* `bytes`
* `list`
* `str`

#### Syntax

```python
sp.UDP1.sendBytes(data)
```

#### Returns

`None`

#### Bytes

```python
sp.UDP1.sendBytes(
    b"Hello"
)
```

#### List

```python
sp.UDP1.sendBytes(
    [72, 101, 108, 108, 111]
)
```

#### String

```python
sp.UDP1.sendBytes(
    "Hello"
)
```

{% hint style="info" %}
The accepted input types have been verified. The exact internal conversion of the supplied value is not covered by this reference.
{% endhint %}

### `sendHex()`

`sendHex()` accepts a hexadecimal String.

#### Syntax

```python
sp.UDP1.sendHex(message)
```

#### Parameters

| Parameter | Type  | Description         |
| --------- | ----- | ------------------- |
| `message` | `str` | Hexadecimal message |

#### Returns

`None`

Both spaced and compact Strings have been verified.

```python
sp.UDP1.sendHex(
    "48 65 6C 6C 6F"
)
```

or:

```python
sp.UDP1.sendHex(
    "48656C6C6F"
)
```

### Choosing a Send Function

For a String message, use:

```python
sp.UDP1.send_ascii("Hello")
```

For hexadecimal data, use:

```python
sp.UDP1.send_hex("48 65 6C 6C 6F")
```

For other data representations, the generic functions `send()` and `sendBytes()` are also available.

### Quick Reference

| API                   | Verified Input         | Returns |
| --------------------- | ---------------------- | ------- |
| `send_ascii(message)` | `str`                  | `None`  |
| `send_hex(message)`   | `str`                  | `None`  |
| `send(data)`          | `str`, `bytes`, `list` | `None`  |
| `sendBytes(data)`     | `bytes`, `list`, `str` | `None`  |
| `sendHex(message)`    | `str`                  | `None`  |
