# YuParse

**YuParse** is a lightweight and efficient ASCII/text parser designed for real-time data extraction on the edge. It is a core component of the **YuDash Axon** processing engine and is optimized for structured sensor output from industrial instruments such as weather stations, weighing scales, and transmitters.

YuParse uses a **pattern-matching approach** where users define a template string with token identifiers (like `#D1`, `#I2`, `#T`, `#A1`, etc.) to extract specific fields from continuous or formatted ASCII inputs. It is tolerant to inconsistent whitespace and supports both data capture and structural matching.

YuParse simplifies the challenge of parsing vendor-specific ASCII formats by providing a flexible yet deterministic framework that decouples pattern logic from parsing code. It enables high-throughput, low-overhead data structuring — critical for scalable IIoT deployments.

The values extracted by YuParse can be directly utilized in various downstream pipelines. Parsed fields can be published to MQTT or HTTP endpoints. Additionally, these values can be fed into YuDash’s built-in Modbus RS485 or TCP/IP server, enabling seamless SCADA or PLC integration. This makes YuDash a powerful edge converter — capable of translating vendor-specific ASCII outputs into json payloads or  Modbus-readable registers.

Following are the steps to use YuParse Engine:

### 1) Reading text data from RS485/RS232 device

The reading of text data from RS485 (or RS232) port is handled as custom "Modbus" registers, as explained here. Refer to documentation of [String Read in RS485/RS232](/dc/df/modbus/string.md).  The string is provided as input (inputVar) to YuParse engine which will be matched with "pattern" string.

### 2) YuParse Pattern

This the pattern string which will be used to parse the inputVar.

* YuParse matches the `inputVar` (ASCII string) against the provided **`pattern`**.
* By default, whitespace is ignored during matching for both inputVar and pattern. Extra spaces, tabs, or inconsistent spacing do not affect parsing. For strict parsing of inputVar, there is an option (described later).
* The pattern is composed of:
  * **Tokens** (e.g., `#D1`, `#A2`) used to capture values.
  * Tokens without a numeric index (e.g., `#D`, `#S`) are treated as **match-only** and **not stored** in the output.
  * **Static strings** (e.g., `TEMP=`, `RH=`, `(Gross)`) that must match exactly
* **Matching is case-sensitive** for static strings (`TEMP` ≠ `temp`).
* YuParse performs a **best effort left-to-right match**, allowing partial parsing when some fields are missing or invalid.
* Parsing stops when:
  * The pattern is fully matched
  * Or the input string ends unexpectedly or mismatches

<table data-header-hidden><thead><tr><th width="159"></th><th width="161"></th><th width="115"></th><th></th></tr></thead><tbody><tr><td>Pattern Element</td><td>Type</td><td>Stored?</td><td>Description</td></tr><tr><td>#D1, #D2</td><td>Decimal/Float</td><td>✅ Yes</td><td>Parsed as float</td></tr><tr><td>#I1, #I2</td><td>Integer</td><td>✅ Yes</td><td>Parsed as integer</td></tr><tr><td>#T1</td><td>Timestamp</td><td>✅ Yes</td><td>Epoch timestamp</td></tr><tr><td>#S1, #S2</td><td>String</td><td>✅ Yes</td><td>Any text until next whitespace</td></tr><tr><td>#A1, #A2</td><td>Alphanumeric</td><td>✅ Yes</td><td>Strictly alphanumeric (letters and digits only)</td></tr><tr><td>#Sx</td><td>String ending with fixed character</td><td>❌ No</td><td><p>Any text until a known character (x). </p><p>x may be mostly a "," or "=" etc.</p></td></tr><tr><td>#D, #S, #A</td><td>Match-only</td><td>❌ No</td><td>Used for pattern alignment; parsed but not stored</td></tr><tr><td>#N</td><td>New line</td><td>❌ No</td><td>Match a new line (\n) or carriage return (\r). </td></tr><tr><td>Non-token word</td><td>Literal Match</td><td>❌ No</td><td>Must exactly match input, ignoring extra whitespace</td></tr></tbody></table>

| **Input String (inputVar)**        | **YuParse Pattern (pattern)**   | **Parsed Values**            |
| ---------------------------------- | ------------------------------- | ---------------------------- |
| `TEMP=23.4 RH=65.2`                | `TEMP=#D1 RH=#D2`               | `D1=23.4`, `D2=65.2`         |
| `STATUS=(OK) VALUE=99.8`           | `STATUS=(#A1) VALUE=#D1`        | `A1=OK`, `D1=99.8`           |
| `Device=ABC TEMP=45.0 UNIT=C`      | `Device=#A TEMP=#D1 UNIT=#S`    | `D1=45.0`                    |
| `Device=ABC TEMP=45.0 UNIT=C`      | `#S=#A1 TEMP=#D1 UNIT=#A2`      | `A1=ABC, D1=45.0 A2=C`       |
| `t=21.5 , humid=(64.2)%`           | `t=#D1 , humid=(#D2)%`          | `D1=21.5`, `D2=64.2`         |
| `(Gross) 125.67 kg (Tare) 5.00 kg` | `(Gross) #D1 kg (Tare) #D2 kg`  | `D1=125.67`, `D2=5.00`       |
| `TEMP:23.4,HUMIDITY:55.6`          | `TEMP:#D1,HUMIDITY:#D2`         | `D1=23.4`, `D2=55.6`         |
| `S/N=SNX123 Value=7.89`            | `S/N=#A1 Value=#D1`             | `A1=SNX123`, `D1=7.89`       |
| `Sensor1=OK Pressure=102.56 mbar`  | `Sensor1=#A1 Pressure=#D1 mbar` | `A1=OK`, `D1=102.56`         |
| `DATA: A23 B56 C99`                | `DATA: #A1 #A2 #A3`             | `A1=A23`, `A2=B56`, `A3=C99` |
| `WSpd=5.2 Dir=NW Temp=21.3`        | `WSpd=#D Dir=#A1 Temp=#D2`      | `A1=NW`, `D2=21.3`           |

### **3) Mapping Tags to Variable Names**

After parsing the input string using the pattern, YuParse assigns values to temporary tags such as `D1`, `A2`, `S1`, etc. These tags must then be **mapped to user-defined variable names** to make them meaningful and usable in further processing.

* Mapping is defined using the `tagArray` field in your configuration.
* Each entry maps a **token tag** (e.g., `"D1"`) to a **custom variable name** (e.g., `"temperature"`).
* These variable names are similar to other variables read by YuDash devices. They can be published to MQTT/HTTP or used in Modbus server (only for numeric numbers)

## YuDash JSON APIs for Axon

### 1) Enabling YuDash Axon

* Axon must be **explicitly enabled** using `"axon": 1`
* The `axonSettings` block is ignored unless Axon is active
* **Axon is supported only on selected YuDash models**&#x20;

```json
"dotFourSettings": {
  ...
  "axon": 1,
  ...
}
```

### 2) YuParse Settings within axonSettings&#x20;

```json
{
  "dotFourSettings": {
    // ... other flags and features
    "axon": 1
  },

  "axonSettings": {
    "parseArray": [
      {
        "inputVar": "sensor_string",
        "pattern": "TEMP=#D1 RH=#D2",
        "tagArray": [
          { "tagName": "D1", "varName": "temperature" },
          { "tagName": "D2", "varName": "humidity" }
        ]
      }
    ]
  },

  // ... other settings like mqttSettings
}
```

### Syntax of the Json blocks

<table><thead><tr><th width="129">Key</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>inputVar</code></td><td>string</td><td>Name of the input variable holding the ASCII string to be parsed. This is typically read through Modbus module.</td></tr><tr><td><code>pattern</code></td><td>string</td><td>YuParse-compatible pattern using tokens like <code>#D1</code>, <code>#A1</code>, etc. This will be matched with the inputVar.</td></tr><tr><td><code>tagArray</code></td><td>array</td><td>List of mappings between token tags and output variable names. </td></tr><tr><td><code>tagName</code></td><td>string</td><td>The token ID from the pattern (e.g., <code>"D1"</code>, <code>"A2"</code>, <code>"T"</code>)</td></tr><tr><td><code>varName</code></td><td>string</td><td>Custom variable name to use in downstream logic, MQTT, Modbus, etc.</td></tr></tbody></table>

### Explanation of the json

* `sensor_string` is assumed to be an ASCII input like:

  ```
  TEMP=23.4 RH=56.2
  ```
* The `pattern` uses tokens `#D1` and `#D2` to extract two decimal numbers
* These are mapped to final variable names `temperature` and `humidity` via `tagArray`
* These variables can then be used in the payload.

## **Whitespace-Sensitive Parsing**

By default, YuParse **ignores all whitespace** (spaces, tabs, etc.) in the input string when matching against a pattern.

To enable **strict whitespace matching**, set `"whiteSpace": 1` inside a `parseArray` block.

#### 🔖 **Special Token for Whitespace-Sensitive Mode**

<table><thead><tr><th width="172">Token</th><th>Meaning</th><th>Notes</th></tr></thead><tbody><tr><td><code>#W</code></td><td>Match <strong>any number</strong> of whitespace characters</td><td>Required only when <code>whiteSpace</code> is <code>1</code></td></tr></tbody></table>

📌 **Note:** The `#N` (newline) token can be used in both whitespace-sensitive and default modes. Newlines are **not ignored**, even when general whitespace is ignored.

#### 🧾 Example **of Whitespace Matching**

```json
{
  "parseArray": [
    {
      "inputVar": "sensor_data",
      "pattern": "VOLT=#D1 #W UNIT=V",
      "whiteSpace": 1,
      "tagArray": [
        { "tagName": "D1", "varName": "voltage" }
      ]
    }
  ]
}
```

***

## YuParse Examples

### **1) Example#1**

**Input String:**

```
tT=(24.5C) RH=(64.3)%
```

#### **YuParse JSON Configuration**

```json

  "axonSettings": {
    "parseArray": [
      {
        "inputVar": "env_data",
        "pattern": "T=(#D1C) RH=(#D2)%",
        "tagArray": [
          { "tagName": "D1", "varName": "temperature_c" },
          { "tagName": "D2", "varName": "humidity_percent" }
        ]
      }
    ]
  }

```

### **2) Example#2**

**Input String:**

```
TEMP=22.3 RH=48.2 STATUS=OK
```

#### **YuParse JSON Configuration**

```json


  "axonSettings": {
    "parseArray": [
      {
        "inputVar": "sensor_raw",
        "pattern": "TEMP=#D1 RH=#D2 STATUS=#A1",
        "tagArray": [
          { "tagName": "D1", "varName": "temperature" },
          { "tagName": "D2", "varName": "humidity" },
          { "tagName": "A1", "varName": "status" }
        ]
      }
    ]
  }

```

### 3) **Example: Parsing Vaisala WXT530 Output**

**🧾 Sample Input String:**

```
Ta=24.7C RH=53.2% P=1007.3hPa Ws=2.3m/s Wd=180D
```

***

#### ⚙️ **Expected Output Variables:**

```json
{
  "temperature": 24.7,
  "humidity": 53.2,
  "pressure": 1007.3,
  "windspeed": 2.3,
  "winddir": 180
}
```

***

#### **YuParse JSON Configuration**

```json

  "axonSettings": {
    "parseArray": [
      {
        "inputVar": "vaisala_string",
        "pattern": "Ta=#D1C RH=#D2% P=#D3hPa Ws=#D4m/s Wd=#D5D",
        "tagArray": [
          { "tagName": "D1", "varName": "temperature" },
          { "tagName": "D2", "varName": "humidity" },
          { "tagName": "D3", "varName": "pressure" },
          { "tagName": "D4", "varName": "windspeed" },
          { "tagName": "D5", "varName": "winddir" }
        ]
      }
    ]
  }
}
```

### 4) **Example:**&#x20;

YuParse supports parsing **multiple input strings simultaneously**, each potentially coming from different sensors or serial sources.\
To enable this, the configuration uses a **`parseArray` array**, where:

* Each item in the array defines a **separate parsing block**
* Each block specifies:
  * An `inputVar` (input string source)
  * A `pattern` to match
  * A `tagArray` to map captured values to usable variable names

This design allows you to process **multiple ASCII inputs in parallel**, even if they come from different instruments or formats.

***

#### 🧾 Input Strings

* `env1_string`:

  ```
  TEMP=23.4 RH=56.2
  ```
* `env2_string`:

  ```
  Ta=24.7C RH=53.2% P=1007.3hPa
  ```

***

#### JSON Configuration

```json

  "axonSettings": {
    "parseArray": [
      {
        "inputVar": "env1_string",
        "pattern": "TEMP=#D1 RH=#D2",
        "tagArray": [
          { "tagName": "D1", "varName": "temperature1" },
          { "tagName": "D2", "varName": "humidity1" }
        ]
      },
      {
        "inputVar": "env2_string",
        "pattern": "Ta=#D1C RH=#D2% P=#D3hPa",
        "tagArray": [
          { "tagName": "D1", "varName": "temperature2" },
          { "tagName": "D2", "varName": "humidity2" },
          { "tagName": "D3", "varName": "pressure2" }
        ]
      }
    ]
  }
}
```

***

#### **Resulting Output Variables**

```json
{
  "temperature1": 23.4,
  "humidity1": 56.2,
  "temperature2": 24.7,
  "humidity2": 53.2,
  "pressure2": 1007.3
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yudash.com/dc/df/axon/parse.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
