> For the complete documentation index, see [llms.txt](https://docs.lorric.com/qr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lorric.com/qr/fu-tx320-english-v1/communication/modbus-rtu-protocol/read-write-memory-ram/read-write-memory-four-register-write-command-31.md).

# 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-tx320-english-v1/communication/modbus-rtu-protocol/read-write-memory-ram/read-write-memory-read-listx.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 %}

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

![](https://content.gitbook.com/content/fX3l9RzQpCUpspFteU5B/blobs/hdBIm8WDhcX34ft3nkwv/modbus-31-TX-diagram-en.png)

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.

***

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

### Example — C04 Dosing Target

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)

Required Scaling: this parameter must be multiplied by ×100,000 before conversion

```
999,999,999 × 100,000 = 99,999,999,900,000
Hex (Int64, 8 bytes): 00 00 5A F3 10 78 B9 60
```

* Target Value: `999,999,999` (decimal)
* Required Scaling: <mark style="color:$danger;">`[VERIFY]`</mark> <mark style="color:$danger;">C04 Dosing Target is understood to be stored internally as a fixed-point value with 5 decimal places of precision, so the raw register holds the display value × 10⁵ (×100,000)</mark>
* Hex Conversion: 99,999,999,900,000 = `5A F3 10 78`。
* 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 5A F3 10 78 B9 60 49 4F
```

* 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 5A F3 10 78 B9 60` (C04 Dosing Target 64-bit value, scaled)
* CRC: `49 4F`  (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 5A F3 10 78 B9 60 49 4F
```

**Write Failure — Exception Response**

As with Function Code 30, a failed write returns a 5-byte exception frame instead of an echo: Slave Address | Function Code | 0x80 | Exception Code | CRC. Example: exception code `0x03` indicates the value is out of rang<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.lorric.com/qr/fu-tx320-english-v1/communication/modbus-rtu-protocol/read-write-memory-ram/read-write-memory-four-register-write-command-31.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
