# Read-Only Memory – Read Command (04)

{% hint style="info" %}
**ⓘ** When reading large values using different data formats (e.g., **Float32** or **Int64**) and performing conversions, **very small differences** may occur due to internal calculation methods. These differences are typically **less than 1/10,000** and are considered **normal**.

A single read command can access up to **40 registers**. Requests exceeding this length will be ignored.
{% endhint %}

### Function Code 04

**Purpose:** This memory area is specifically used to store the device's **real-time status**, **measurement results**, and **flow-related memory**.

**Characteristics:** The data is **read-only** and can only be accessed via the **Read command**. Values **cannot be modified** using write commands.

### Read-Only Memory – Read Command (04) Format <a href="#kong-zhi-duan-fa-zhi-ling-04-ge-shi" id="kong-zhi-duan-fa-zhi-ling-04-ge-shi"></a>

<div align="left"><figure><img src="https://4028902321-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSBz5Tlpy8GCIkK4ygkgZ%2Fuploads%2FxIseykk7hDSu6Xb0VUSe%2Fmodbus-04-TX-diagram-en.png?alt=media&#x26;token=02ebbb72-dff9-44a2-97c3-2ee1fc9523e1" alt="" width="563"><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://4028902321-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSBz5Tlpy8GCIkK4ygkgZ%2Fuploads%2FojmCseMSW2HU3bVR3fSt%2Fmodbus-04-RX-diagram-en.png?alt=media&#x26;token=4a2c11f9-9b91-4d2d-a6cb-b197a4ef5038" alt="" width="563"><figcaption></figcaption></figure></div>

### Modbus RTU – Example of Read-Only Memory Read Command (04)

Using the **Read-Only Memory Read Command (04)** as an example, this section explains how to send a command and parse the returned data into a decimal value when the **totalized flow** is **20,000.5 liters**.

**Master Sends Read Command (TX Frame)**

According to device specifications, the accumulated flow is stored in **Float32 format**, occupying **2 registers (4 bytes)**; therefore, the quantity to read should be set to **00 02**. The master must send Modbus function code 04 (Read Input Registers) to read 2 registers starting from address 0000.

```
TX: 01 04 00 00 00 02 71 CB
```

* Slave Address = 01
* Function Code = 04
* Starting Register Address = 00 00
* Quantity to Read = 00 02 (2 registers)
* CRC Checksum = 71 CB

**Slave Response Data (RX Frame)**

After receiving the read request, the slave returns the internally stored **20,000.5 liters (Float32)** data, packaged as **4 bytes** according to **Modbus Register Big Endian** (high byte first) and **IEEE 754 Float32** format.

```
RX: 01 04 04 45 9C 40 00 E2 56
```

* Slave Address = 01
* Function Code = 04
* Byte Count (Number of Data Bytes) = 04 (4 Bytes)
* Data (Data Field) = 45 9C 40 00
* CRC Checksum = E2 56

**Data Parsing and Conversion (Back to Decimal)**

**Step A: Arrange the Data**\
Since the device uses **Big Endian** format, the most significant byte comes first. Therefore, the 4 bytes are kept in the received order and combined as:\
`459C4000₁₆`

**Step B: Decode the Float32 Structure (SEM: S = Sign, E = Exponent, M = Mantissa)**\
Convert `459C4000₁₆` into a 32-bit binary number for IEEE 754 Float32 interpretation.

![](https://4028902321-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSBz5Tlpy8GCIkK4ygkgZ%2Fuploads%2F0e1rmsXiCgx3TxOHBdYW%2Fimage?alt=media\&token=6e0a52b2-1fd7-41f7-8c3a-100dc74d710e)

**Partial Binary Value Explanation**

* **S (Sign bit)** = 0 (1 bit) → 0 means a positive number
* **E (Exponent bits)** = `10001011` (8 bits) → 139₁₀\
  Actual exponent = 139 − 127 = **12**
* **M (Mantissa bits)** = `001110001...` (23 bits) → the significand is **1.M**

**Step C: Calculate the Value**

According to the IEEE 754 Float32 format, the calculation is as follows.\
The exponent bits `10001011₂` equal 139₁₀, so the actual exponent is 139 − 127 = 12.

* The mantissa bits are 0011100100000000000000，, giving a significand of 1.001110001...

After shifting the binary point 12 places to the right and converting to decimal:

Value = 2¹⁴ + 2¹¹ + 2¹⁰ + 2⁹ + 2⁵ + 2⁻¹\
\= 16384 + 2048 + 1024 + 512 + 32 + 0.5\
\= 20000.5

Therefore, the Modbus RX response data `01 04 04 45 9C 40 00 E2 56` represents a cumulative flow value of **20000.5 liters**.

{% embed url="<https://codepen.io/philo_lorric/embed/BagqoRj>?" %}

A Modbus format converter tool is available at: <https://codepen.io/philo\\_lorric>


---

# 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.lorric.com/qr/fu-es-echosense-instruction-manual/communication/modbus-rtu-protocol/read-only-memory-rom/read-only-memory-read-instruction-04-and-memory-lists.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.
