# modbus

http://www.modbus.org/specs.php

# Варианты запросов

01 (0x01) Read Coils

    Request:  01 bbbb NNNN
    Response: 01 nn <data>
    Error:    81 ee

02 (0x02) Read Discrete Inputs

    Request:  02 bbbb NNNN
    Response: 02 nn <data>
    Error:    82 ee

03 (0x03) Read Holding Registers

    Request:  03 bbbb NNNN
    Response: 03 nn <data>
    Error:    83 ee

04 (0x04) Read Input Registers

    Request:  04 bbbb NNNN
    Response: 04 nn <data>
    Error:    84 ee

05 (0x05) Write Single Coil

    Request:  05 aaaa vvvv (0000 or FF00)
    Response: 05 aaaa vvvv (0000 or FFFF)
    Error:    85 ee

06 (0x06) Write Single Register

    Request:  06 aaaa vvvv
    Response: 06 aaaa vvvv
    Error:    86 ee

07 (0x07) Read Exception Status (Serial Line only)

    Request:  07
    Response: 07 vv
    Error:    87 ee

08 (0x08) Diagnostics (Serial Line only)

    Request:  08 .......
    Response: 08 .......
    Error:    87 ee

15 (0x0F) Write Multiple Coils

    Request:  0F bbbb NNNN nn <data>
    Response: 0F bbbb NNNN
    Error:    8F ee

16 (0x10) Write Multiple registers

    Request:  0F bbbb NNNN nn <data>
    Response: 0F bbbb NNNN
    Error:    8F ee

# Группировка

1. coils: r-1, w-15/5
2. discrete inputs: r-2
3. holding registers: r-3, w-16/6
4. input registers: r-4

# Настройки устройства

1. max quantity of HOLDING registers in a reading request
2. max quantity of INPUT registers in a reading request
3. don't use WRITE_SINGLE_COIL command 0x05
4. don't use WRITE_SINGLE_REGISTER command 0x06
5. max size of gap in a reading request

# Настройки тега

1. region:
   - COILS
   - DISCRETE_INPUTS
   - INPUT_REGISTERS
   - HOLDING_REGISTERS
2. address
3. data type
4. access:
   - read
   - write
   - rw
5. byte rearrangement
6. forced write with command 6

# Conf

    module.owen1:
      enable:     on
      type:       'owen_trm210'
      mode:       [rtu] / ascii / tcp
      portnum:    1
      netaddr:    1
      retrial:    3
      emulated:   off
      descr:      good old owen trm

    modbustype.owen_trm210:
      enable:     on

      # максимальное количество регистров в команде
      func.reg.limit:
        1:  1 .. [175]
        2:  1 .. [175]
        3:  1 .. [175]
        4:  1 .. [175]
        15: 1 .. [175]
        16: 1 .. [175]

      # максимальный разрыв для команд записи
      func.write.gap:
        15: [0] .. 175
        16: [0] .. 175

      tag.reg1:
        enable:   on
        type:     bool
                  int     size: 1 / [2] / 4
                  [uint]  size: 1 / [2] / 4
                  float
                  double
                  string  1..~240
        size:     1 / [2] /  ... n
        reorder:  [[]] / [0,1,2,3] / [1,0,3,2] / ...
        addr:     2001
        addrwr:   2002
        access:   r / w / [rw]
        coderd:   1 / 2 / 3 / [4]
        codewr:   5 / [6]
        codegr:   15 / [16]
        req:      [off] / on  # если on, то создает два доп тега:
                              #    reg1.req
                              #    reg1.cnt

        reqgr:    [''] / 'mytestgroup'  # если не '', то создает теги:
                                        #   modname.mytestgroup.req =1
                                        #   modname.mytestgroup.cnt

        bittags:
          current.error0:  b0    # [b0] .. 8*size / [1] .. 32
          current.error1:  b0/2
          current.error2:  b1