# Modbus學習紀錄I *傻傻分不清楚 Client/Server & Master/Slave*
###### tags: `modbus`
Copyright 2021, [月下麒麟](https://hackmd.io/@YMont/note-catalog)
---
## Objectives
筆者在研讀Modbus不同的Specification時,
不同規格書上,出現提及的角色有Client/Server或Master/Slave,
對於這些角色應用場域有些困惑與疑問,
故寫下此筆記<u>助於釐清</u>並<u>詳細說明來由</u> 。
**文章開頭會<u>引用一些網路文章論點</u>,
接著,利用以上述的論點,
進而<u>查證規格書上的闡述</u>。**
**最後才會透過<u>簡短的舉例</u>,
能更清楚明白角色在實際場域是如何被扮演著。**
## Quote
A **master** is a device that is actively polling for data from one or multiple devices using a serial communication protocol.
A **slave** is the counterpart of the master. It is a passive device, waiting for the master to poll for data to actually send it.
>Some examples of devices or protocols using master/slave communication are Modbus® RTUs,
>IEC 60870-5-101, DNP 3.0, PROFIBUS, and HART.
---
A **client** is a device that is actively polling for data from one or multiple devices.
A **server** device is the passive component, waiting for the client to poll for data to actually send it.
>Modbus TCP/IP, 60870-5-104, IEC 61850,
>and PROFINET are some protocols using client/server communication.
**歸納:**
>**<u>Basically, the master/client gives orders, the slave/server acts – just like in a restaurant</u>**
> **<u>client 比擬為 master,server 則比擬為 slave</u>**
以上為引述網路上的文章論點
Reference:[Crash Course: Client/Server/Master/Slave](https://www.prosoft-technology.com/insights/technology-focus/Crash-Course-Client-Server-Master-Slave)
Reference:[【Maker電子學】認識 Modbus協定 ](https://makerpro.cc/2019/08/modbus-protocol/)
---
## Understanding

</br>

上面兩張圖示是Spec上提到的,可分別從這兩張圖片發現,
其Modbus在應用層上會比較像是網路層TCP/IP那樣,存在著Client/Server關係
至於Master/Slave的應用,設備(Master)會連結著實體裝置(Slave),
並持續地收集裝置的資訊。
簡短表達如下:
<u>Client/Server屬應用層的Protocol應用
Master/Slave屬實體層、資料連結層的protocol應用,</u>
Reference:[Specification and Implementation Guide for MODBUS over serial line](https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf)
---
## Summary
以下是筆者的理解,
此筆記並未提及到有關硬體RS-232、485、422,
與軟體Modbus RTU、ASCII,TCP/IP等等的通訊細節,
比較著墨在應用上的角色扮演,
<u>搞清楚關係後,再來瞭解各自詳細的應用會更加速學習效率</u>。
最後,舉兩個IIoT的應用例子,
**PLC(Master)連結到多個溫控設備(Slave)**,
故PLC會規律的Polling多個client device。
**PLC(Server)連結到SCADA(Client)**
,故SCADA會規律的Polling PLC device。

圖片引自MOXA的Manual Specification,並做部分修改
Reference:[引用自MOXA's Manual](https://cdn.logic-control.com/docs/datasheets/moxa/thingspro_version_2_user______s_manual_manual-8.pdf)
Reference:[透過Modbus開發應用項目](https://www.ni.com/zh-tw/innovations/white-papers/14/application-development-with-modbus.html)
關於Modbus的應用關係釐清就說明到這裡~