# Read/Write Memory - Four Register Write Command (31)

{% hint style="info" %}
When large values are processed using different data formats (e.g., **float32** vs. **int64**), minor differences may occur due to internal calculation methods, typically less than **1/10,000**, and are considered normal.

This command applies **only to memory items with a register length of 4**. Refer to the [parameter list](/qr/fu-es-echosense-instruction-manual/communication/modbus-rtu-protocol/read-write-memory-ram/read-write-memory-read-list.md#read-write-memory-list) for details.
{% endhint %}

#### Function Code 31

The Four Register Write command (Function Code 31) writes 4 consecutive registers (64-bit), supporting Int64 or other 64-bit values. It is recommended for writing large parameters such as: D11 Total Target (64-bit), C04 Dosing Target (64-bit)

{% hint style="info" %}
A standard 32-bit floating-point number (Function Code 30) has a precision of about **7 significant digits**. When the value exceeds ten million, using 32-bit floats may cause **accuracy loss and rounding errors**.

In such cases, it is recommended to use **Function Code 31** with **64-bit integers (Int64)** to ensure the data is accurately stored in memory without any rounding errors.
{% endhint %}

####

![](/files/OtYwoUBWBeeWd4E998Eu)

Function Code 31 uses a mirror-response mechanism. When the write is successful, the RX response frame from the slave will exactly match the TX request in both format and content.

#### Read/Write Memory – Four Register Write Command (Function Code 31) Format

This example demonstrates how the **master** uses **Function Code 31** to write a target value of **+999,999,999** to the parameter **C04 Dosing Target**.

* **Register Address:** 02 83
* **Register Length:** 4 (4 consecutive registers, 64-bit)
* **Data Type:** Int64

#### 1. Value Conversion and Data Preparation (Hex Data)

* Target Value: `999,999,999` (decimal)
* Hex Conversion: `3B 9A C9 FF`。
* Packed in Int64 Format (8 Bytes):\
  Since Function Code 31 requires 8 bytes, prepend zeros:\
  Complete 64-bit Data:  `00 00 00 00 3B 9A C9 FF`

#### **2.** Master Sends Write Command (TX Frame)

```
TX： 01 31 02 83 00 00 00 00 3B 9A C9 FF 0B 7A
```

* Slave Address: `01`  (Flow meter address)
* Function Code: `31` (Write 4 Registers)
* Starting Register Address: `02 83` (C04 Dosing Target 64-bit memory address)
* Data to Write: `00 00 00 00 3B 9A C9 FF` (C04 Dosing Target 64-bit value)
* CRC: `0B 7A`  (Calculated CRC for error checking)

#### 3. Slave Response (RX Frame)

When the write is successful, the slave echoes the TX frame for verification.

```
RX: 01 31 02 83 00 00 00 00 3B 9A C9 FF 0B 7A
```


---

# 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-write-memory-ram/read-write-memory-four-register-write-command-31.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.
