> 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/fp-as510-paddle-wheel-flowmeter-manual-chinese-v2/communication/rs485-setup.md).

# RS485 與 Modbus RTU 設定

{% hint style="info" %}
RS485 通訊僅在「主畫面」狀態下才會啟用。\
當設備停留在設定畫面或參數編輯畫面時，RS485 將不回應任何 Modbus 指令。
{% endhint %}

## 規格

| 鮑率 Baud    | 9600, 19200, 38400 及 57600     |
| ---------- | ------------------------------ |
| 接線         | 二線式                            |
| 同一網絡中最多節點數 | 32 台（標準單位負載條件下，每台裝置計為 1 個單位負載） |

## 接線

### RS485 二線式配線圖

黑色線：RS485 (B-)、綠色線：RS485 (A+)

本功能必需在DC 電源的棕藍色有供電的情形下，才能工作。為維持圖面易讀性，本圖省略DC供電圖，詳情形見 DC 電源配線圖。

{% hint style="danger" %}
請注意RS485的配線請勿和電源配線接錯，若因誤接導致線路或產品受損，請聯繫 LORRIC 原廠安排機器更換，相關維修費用需由使用者承擔。
{% endhint %}

![](https://2086194569-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LxeY3bBEflHg4JOGyfX%2F-Lxea_AJoFWovC7hLY6w%2F-LxefUpjBvk05qTV5eas%2FRS485.png?alt=media\&token=fc0b9cf7-3c61-4198-aa48-e32956828022)

{% hint style="info" %}

## 配線建議

1. 一般建議使用帶屏敲 24awg 雙絞線，以串接方式連線每台設備，不要使用環狀或放射狀線路。
2. 連線長時，請在 master 及線路最遠端使用終端電阻，終端電阻業界常使用 120Ω，實際數值請參照線材規格計算。
3. 若通訊訊號不穩定，可於總線上的適當位置（通常靠近主站）加裝偵壓電阻，以提升訊號穩定性。
4. 隨貧8芯線，如果使用在 RS485 通訊，請修剪線材長度，盡量使用最短必要線長，以降低雜訊干擾。並將隔離網與主要通訊線屏蕽相連後接地。
5. 在訊號干擾多的地方，軟體可能需要多次詢問才能得到回應，請在通訊程式內建立多次詢問機制，以區別訊號干擾與設備異常離線兩種情形。
   {% endhint %}

## RS485 Modbus RTU參數設定

{% stepper %}
{% step %}

### 設定基本參數

請先完成推薦參數設定流程（語言設定、管路類型等基本設定）。
{% endstep %}

{% step %}

### 設置接線

依照本頁指示將RS485 Modbus RTU配線設置妥當。
{% endstep %}

{% step %}

### E04 Modbus ID 應用傳輸協定

請設定 **E04** 以指定流量計於 **RS485 / Modbus** 網路中的從站位址（Modbus Slave ID）。請確認同一通訊線路上各設備之位址皮為唯一，避免地址重複造成通訊衝突。

本參數不支援使用 RS485 修改。
{% endstep %}

{% step %}

### E05 Baud 鮑率

請設定 **E05 Baud 鮑率** 以指定流量計之 **Modbus 通訊速率（Baud Rate）**。\
主站（Master）與流量計（Slave）必須設定為**完全相同的鮑率**，方可建立正常通訊。

本參數不支援使用 RS485 修改。
{% endstep %}

{% step %}

### 返回到主畫面

請回到主畫面（綠燈），必需在主畫面下，RS485 才會工作。
{% endstep %}

{% step %}

### 如需要，可使用模擬模式測試

請使用參數 F01 及 F02 將主機設定為模擬模式以方便測試。
{% endstep %}

{% step %}

### 測試要讀寫的記憶體

請參考[ Modbus RTU Protocol ](/qr/fp-as510-paddle-wheel-flowmeter-manual-chinese-v2/communication/modbus-rtu-protocol.md)頁面測試要讀寫的記憶體。

|          |                                                                                                                                                                                                                                                |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 通訊格式     | <p>bit order: lsb first</p><p>byte order: big endian</p><p>Data bits:8</p><p>Parity: None</p><p>Stop bits: 1</p><p>Floating point number follows IEEE754-1985. The float32 below stands for 32bits Single precision floating point number.</p> |
| 記憶體定義及功能 | <p>modbus 可操作的記憶體分為兩大類，唯讀型及讀寫型。</p><p>唯讀型主要是流量計狀態相關的記憶體，例如即時流量。這部分也是最常使用的記憶體。唯讀型的記憶體只能使用指 04 來讀取。</p><p>讀寫型主要是流量計設定參數記憶體，寫入操作一次只能改變一個參數，如果目標參數的記憶體長度是 1個 register，使用指令 06，如果目標參數的記憶體長度是 2 register，使用 30。</p>                                  |

{% hint style="info" %}
在 Modbus RTU 通訊中，Register（暫存器）是記憶體通訊的基本單位，其長度為 **2 Byte（16 bit）**；而 Byte（位元組）則是資料傳輸的基本單位，長度為 **8 bit**。
{% endhint %}
{% endstep %}

{% step %}

### 關閉模擬模式

確認測試完成後，請將 F02 關閉，並回到主畫面。完成。
{% endstep %}
{% endstepper %}

<details>

<summary><strong>Modbus RTU 讀取 Float32 數據範例</strong> <em>（點擊展開）</em></summary>

以唯讀型記憶體讀取指令 (04) 為例，說明當累積流量為 5,000.0 公升時，如何發送指令並將回傳數據解析為十進位數值。詳細指令格式請參考 唯讀型記憶體–讀取指令(04) 頁面。

</details>

<details>

<summary><strong>唯讀型記憶體讀取指令</strong> <em>（點擊展開）</em></summary>

**主站發送讀取指令 (TX 訊框)**

依設備規格，累積流量以 **Float32** 格式儲存，佔用 **2 個暫存器 (4 bytes)**，因此讀取數量應設定為 **00 02**。主站需發送 Modbus 功能碼 04（讀取輸入暫存器），從位址 0000 開始讀取 2 個暫存器。

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

* 從站地址 = 01
* 功能碼 = 04
* 起始暫存器位址 = 00 00
* 讀取數量 = 00 02（2 個暫存器）
* CRC 校驗碼 = 71 CB

**從站回覆數據 (RX 訊框)**

從站收到讀取請求後，依 **Modbus 暫存器 Big Endian**（高位元組在前）及 **IEEE 754 Float32** 格式，將內部儲存的 **5,000.0 公升 (Float32)** 數據，包裝為 **4 bytes** 回傳。

```
RX: 01 04 04 45 9C 40 00 1F 66
```

* 從站地址 = 01
* 功能碼 = 04
* 位元組數 = 04（4 bytes）
* 數據內容 = 45 9C 40 00
* CRC 校驗碼 = 1F 66

**數據解析與換算（還原為十進位）**

**步驟 A：排列數據**\
由於設備採用 **Big Endian** 格式，最高位元組在前，因此 4 個 bytes 依收到順序組合為：\
`459C4000₁₆`

**步驟 B：解析 Float32 結構（S=符號、E=指數、M=尾數）**\
將 `459C4000₁₆` 轉換為 32-bit 二進位數，以進行 IEEE 754 Float32 解析。

* **S（符號位元）** = 0（1 bit）→ 0 代表正數
* **E（指數位元）** = `10001011`（8 bit）→ 139₁₀\
  實際指數 = 139 − 127 = **12**
* **M（尾數位元）** = `001110001...`（23 bit）→ 有效位為 **1.M**

**步驟 C：計算數值**

依 IEEE 754 Float32 格式計算如下。\
指數位元 `10001011₂` 等於 139₁₀，故實際指數為 139 − 127 = 12。

* 尾數位元為 00111000100000000000000，有效位為 1.001110001...

將二進位小數點右移 12 位後換算為十進位：

數值 = 2¹²+2⁹+2⁸+2⁷+2³\
\= 4096+512+256+128+8\
\= 5000.0

因此，Modbus 回覆數據 `01 04 04 45 9C 40 00 1F 66` 代表累積流量為 **5000.0 公升**。

</details>

## 進階參數設定（FW 2.3.0 開始提供）

### [E15 Byte format](/qr/fp-as510-paddle-wheel-flowmeter-manual-chinese-v2/parameters.md#e-tong-xun-can-shu-lie-biao)

本參數提供4種 byte 封包格式

| 選項名稱  | 全名                              |
| ----- | ------------------------------- |
| N.8.1 | No parity bit with 1 stop bit   |
| N.8.2 | No parity bit with 2 stop bits  |
| O.8.1 | Odd parity bit with 1 stop bit. |
| E.8.1 | Even parity bit with 1 stop bit |

下圖是各選項的封包圖示，其中 ST 代表 start bit，D0 \~ D7 是資料位元，SP 是 stop bit，

OP 是Odd-parity， EP stands 是 Even-parity。（每個菱形圖示是一個 bit）

<figure><img src="https://2086194569-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxeY3bBEflHg4JOGyfX%2Fuploads%2FqphIPcSL518XHdGLhXKH%2Fuart_byte_format.png?alt=media&#x26;token=d98aac91-0810-47b8-bc9d-1d900586117f" alt=""><figcaption></figcaption></figure>

### [E16 Bit order](/qr/fp-as510-paddle-wheel-flowmeter-manual-chinese-v2/parameters.md#e-tong-xun-can-shu-lie-biao)

本參數可用來調整單個 byte 封包中資料位元的傳輸順序。

LSB 代表 第0位元先傳，MSB 代表第7位元先傳。其中 LSB 是最常使用的格式。以下封包圖示以 N.8.1 舉例：（下圖每個菱形圖示是一個 bit）

<figure><img src="https://2086194569-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxeY3bBEflHg4JOGyfX%2Fuploads%2FyA8KIsuvLvDoWIsaPewr%2FLSBMSB.png?alt=media&#x26;token=d6977415-1072-445a-ab34-e02e048c4f36" alt=""><figcaption></figcaption></figure>

### [E17 Endianness](/qr/fp-as510-paddle-wheel-flowmeter-manual-chinese-v2/parameters.md#e-tong-xun-can-shu-lie-biao)

本參數用來調整 RX (流量計回傳資料) 時每個多 byte 資料的內部 byte 傳輸順序。**modbus ID、指令、CRC及單 byte 資料不受影響。** 例如要傳回傳流量及流速資料假設流量的數據是1000，回傳時，仍會先傳流量再傳流速，但是用來表達1000的這 4 個 byte 的傳輸順序不同，1000表示為16進制是 00007A44，以下是兩個不同格式時的順序。（下圖每個菱形圖示是一個 byte。）

<figure><img src="https://2086194569-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxeY3bBEflHg4JOGyfX%2Fuploads%2FFj32TEsoKva2R6jYv2j0%2Fendianness.png?alt=media&#x26;token=8e8bb1bf-00ff-46ac-96f9-13d4077f064a" alt=""><figcaption></figcaption></figure>

#### 範例

以下是使用 04 指令要求流量計傳回瞬時流速(圖示為FS+數字)及累積流量(圖示為TF+數字)的範例：（下圖每個菱形圖示是一個 byte）

<figure><img src="https://2086194569-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxeY3bBEflHg4JOGyfX%2Fuploads%2Fb2zUPQwOTWHJ5IbjzBIN%2Fendian_example.png?alt=media&#x26;token=cae6594f-7ff4-489f-9d43-1ea15251f148" alt=""><figcaption></figcaption></figure>

第一行是主控端發出的指令。不受本設定影響，詳細請看 modbus 04 指令。

第二行是流量計在 Big Endian 設置下的回覆。從左到右，0x01 到 0x08 及 CRC1到CRC2 不是資料不受本設定影響。瞬時流速(圖示為FS+數字)及累積流量(圖示為TF+數字)回覆順序也不受影響。因為設定為 Big Endian，瞬時流速(圖示為FS3 到 FS0) 的四個 byte 會先從 FS3 開始回覆。累積流量(圖示為TF3 到 TF0) 的四個 byte 會先從 TF3 開始回覆。

第三行是流量計在 Little Endian 設置下的回覆。從左到右，0x01 到 0x08 及 CRC1到CRC2 不是資料不受本設定影響。瞬時流速(圖示為FS+數字)及累積流量(圖示為TF+數字)回覆順序也不受影響。因為設定為 Little Endian，瞬時流速(圖示為FS0 到 FS3) 的四個 byte 會先從 FS0 開始回覆。累積流量(圖示為TF0 到 TF3) 的四個 byte 會先從 TF0 開始回覆。


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lorric.com/qr/fp-as510-paddle-wheel-flowmeter-manual-chinese-v2/communication/rs485-setup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
