samples/subsys/modbus/tcp_gateway/README.html · samples/subsys/modbus/tcp_gateway/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · Modbus · Gateway

Modbus TCP-to-serial 게이트웨이

PC의 TCP client와 별도 RTU server board 사이에서 coil·register request를 전달합니다.

Official pathsamples/subsys/modbus/tcp_gateway/README.html
Source filesamples/subsys/modbus/tcp_gateway/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

Gateway network·serial topology, PyModbus TCP 접속과 RTU server 제어를 설명합니다.

Northbound

Modbus TCP · Port 502

Gateway

Ethernet ↔ Serial

Southbound

Modbus RTU server

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 96E8D85C34BB28B45892F81FD8952AB39A039E6B65DF649B4834C62F6C48B2DB
.. zephyr:code-sample:: modbus-gateway
   :name: Modbus TCP-to-serial gateway
   :relevant-api: modbus bsd_sockets

   Implement a gateway between an Ethernet TCP-IP network and a Modbus serial line.

Overview
********

This is a simple application demonstrating a gateway implementations between
an Ethernet TCP-IP network and a Modbus serial line.

Requirements
************

This sample has been tested with FRDM-K64F board,
but it should work with any board or shield that has a network interface.

Gateway example is running on an evaluation board and communicates
with another board that has been prepared according to the instructions in
:zephyr:code-sample:`modbus-rtu-server` sample. Client is running on a PC or laptop.

The description of this sample uses `PyModbus`_ (Pymodbus REPL).
The user can of course try out other client implementations with this sample.

In addition to the evaluation boards RS-485 shields may be used.
The A+, B- lines of the RS-485 shields should be connected together.
Alternatively UART RX,TX signals of two boards can be connected crosswise.

Building and Running
********************

This sample can be found under
:zephyr_file:`samples/subsys/modbus/tcp_gateway` in the Zephyr tree.

The following commands build and flash gateway sample.

.. zephyr-app-commands::
   :zephyr-app: samples/subsys/modbus/tcp_gateway
   :board: frdm_k64f
   :goals: build flash
   :compact:

On the client side, PC or laptop, the following command connects PyModbus
to the gateway.

.. code-block:: console

   # pymodbus.console tcp --host 192.0.2.1 --port 502

The LEDs on the server board are controlled by Modbus commands FC01, FC05, FC15.
For example, to set LED0 on use FC01 command (write_coil).

.. code-block:: console

   > client.connect
   > client.write_coil address=0 value=1 slave=1

Client should confirm successful communication and LED0 should light.

.. code-block:: console

   {
       "address": 0,
       "value": true
   }

To set LED0 off but LED1 and LED2 on use FC15 command (write_coils).

.. code-block:: console

   > client.write_coils address=0 values=0,1,1 slave=1

To read LED0, LED1, LED2 state FC05 command (read_coils) can be used.

.. code-block:: console

   > client.read_coils address=0 count=3 slave=1
   {
       "bits": [
           false,
           true,
           true,
           false,
           false,
           false,
           false,
           false
       ]
   }

It is also possible to write and read the holding registers.
This however does not involve any special interaction
with the peripherals on the board yet.

To write single holding registers use FC06 command (write_register),

.. code-block:: console

   > client.write_register address=0 value=42 slave=1

or FC16 command (write_registers).

.. code-block:: console

   > client.write_registers address=0 values=42,42,42 slave=1

To read holding registers use FC03 command (read_holding_registers).

.. code-block:: console

   > client.read_holding_registers address=0 count=3 slave=1
   {
       "registers": [
           42,
           42,
           42
       ]
   }

.. _`PyModbus`: https://github.com/pymodbus-dev/pymodbus

Part 3

한국어 전문 번역

개요

Ethernet TCP/IP network와 Modbus serial RTU line 사이를 연결하는 gateway 구현을 보여 주는 application입니다. TCP client request를 받아 다른 board의 RTU server로 전달하고 응답을 다시 TCP 쪽으로 돌려줍니다.

요구 사항

이 sample은 FRDM-K64F에서 시험되었지만 network interface가 있는 board나 shield에서 동작할 수 있습니다. Gateway는 evaluation board에서 실행하며, serial 쪽에는 Modbus RTU server sample 지침에 따라 준비한 두 번째 board가 필요합니다. PC나 laptop의 client는 PyModbus REPL을 사용합니다.

두 evaluation board에 RS-485 shield를 사용할 수 있으며 A+·B- line을 각각 연결합니다. 또는 두 board의 UART RX·TX를 교차 연결할 수 있습니다.

빌드 및 실행

Sample은 samples/subsys/modbus/tcp_gateway에 있습니다. 다음 command로 FRDM-K64F gateway를 build하고 flash합니다.

west build -b frdm_k64f samples/subsys/modbus/tcp_gateway
west flash

PC나 laptop에서 PyModbus TCP console을 gateway의 documentation address 192.0.2.1, standard Modbus TCP port 502에 연결합니다.

# pymodbus.console tcp --host 192.0.2.1 --port 502

Serial RTU server board의 LED는 문서에 기재된 FC01, FC05, FC15 관련 coil command로 제어합니다. 원문은 LED0을 켜는 동작을 FC01이라고 적지만 example은 write_coil을 사용합니다.

> client.connect
> client.write_coil address=0 value=1 slave=1

Client는 address 0과 boolean true를 응답하고 LED0이 켜집니다.

{
    "address": 0,
    "value": true
}

write_coils로 LED0은 끄고 LED1·LED2를 켭니다.

> client.write_coils address=0 values=0,1,1 slave=1

원문은 state read를 FC05라고 적지만 example은 read_coils로 세 coil을 읽습니다. 앞의 세 bit는 false, true, true입니다.

> client.read_coils address=0 count=3 slave=1
{
    "bits": [
        false,
        true,
        true,
        false,
        false,
        false,
        false,
        false
    ]
}

Holding register access는 아직 board peripheral과 특별히 연결되지 않습니다. write_register로 single register에 42를 씁니다.

> client.write_register address=0 value=42 slave=1

write_registers로 연속된 register 세 개에 42를 씁니다.

> client.write_registers address=0 values=42,42,42 slave=1

read_holding_registers로 같은 세 register를 읽으면 42, 42, 42가 반환됩니다.

> client.read_holding_registers address=0 count=3 slave=1
{
    "registers": [
        42,
        42,
        42
    ]
}

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.