具体协议百度一下,这里只介绍tb相关的点。结合modbus salve(modbus从机模拟)。modbus poll可以读写 modbus salve的数据

    • id
      • 设备编号:对应modbus.json中的unitId
    • function
      • 功能代码: 对应modbus.json中的functionCode
        • 读数据
          • 1 线圈 [只有开关俩种值] 读写
          • 2离散输入 只读
          • 3多个保持寄存器 读写
          • 4输入寄存器 只读
        • 写数据
          • 5 写单个线圈
          • 6 写单个寄存器
          • 15 写多个线圈
          • 16 写多个寄存器
    • address
      • 地址位:对应modbus.json中的address
    • quantity
      • 数量(从address开始连续读几个):对应modbus.json中的objectsCount/registerCount

    图1设置modbus从机的四个属性
    图2三个都是设备1
    第一个是功能码3 读地址位0的保持寄存器 写用功能码6或16
    第二个是功能码4 读地址位1和2的输入寄存器 只读
    第三个是功能码1 读地址位3的线圈 只有0/1 开关量 写用功能码5
    image.pngimage.png

    1. {
    2. "server": {
    3. "type": "tcp",
    4. "host": "127.0.0.1",
    5. "port": 5020,
    6. "timeout": 35,
    7. "method": "socket",
    8. "byteOrder": "BIG",
    9. "devices": [
    10. {
    11. "unitId": 1,
    12. "deviceName": "Temp Sensor",
    13. "attributesPollPeriod": 5000,
    14. "timeseriesPollPeriod": 5000,
    15. "sendDataOnlyOnChange": true,
    16. "attributes": [
    17. {
    18. "tag": "string_read",
    19. "type": "string",
    20. "functionCode": 4,
    21. "objectsCount": 4,
    22. "address": 1
    23. },
    24. {
    25. "tag": "bits_read",
    26. "type": "bits",
    27. "functionCode": 4,
    28. "objectsCount": 1,
    29. "address": 5
    30. },
    31. {
    32. "tag": "8int_read",
    33. "type": "8int",
    34. "functionCode": 4,
    35. "objectsCount": 1,
    36. "address": 6
    37. },
    38. {
    39. "tag": "16int_read",
    40. "type": "16int",
    41. "functionCode": 4,
    42. "objectsCount": 1,
    43. "address": 7
    44. },
    45. {
    46. "tag": "32int_read_divider",
    47. "type": "32int",
    48. "functionCode": 4,
    49. "objectsCount": 2,
    50. "address": 8,
    51. "divider": 10
    52. },
    53. {
    54. "tag": "8int_read_multiplier",
    55. "type": "8int",
    56. "functionCode": 4,
    57. "objectsCount": 1,
    58. "address": 10,
    59. "multiplier": 10
    60. },
    61. {
    62. "tag": "32int_read",
    63. "type": "32int",
    64. "functionCode": 4,
    65. "objectsCount": 2,
    66. "address": 11
    67. },
    68. {
    69. "tag": "64int_read",
    70. "type": "64int",
    71. "functionCode": 4,
    72. "objectsCount": 4,
    73. "address": 13
    74. }
    75. ],
    76. "timeseries": [
    77. {
    78. "tag": "8uint_read",
    79. "type": "8uint",
    80. "functionCode": 4,
    81. "objectsCount": 1,
    82. "address": 17
    83. },
    84. {
    85. "tag": "16uint_read",
    86. "type": "16uint",
    87. "functionCode": 4,
    88. "objectsCount": 2,
    89. "address": 18
    90. },
    91. {
    92. "tag": "32uint_read",
    93. "type": "32uint",
    94. "functionCode": 4,
    95. "objectsCount": 4,
    96. "address": 20
    97. },
    98. {
    99. "tag": "64uint_read",
    100. "type": "64uint",
    101. "functionCode": 4,
    102. "objectsCount": 1,
    103. "address": 24
    104. },
    105. {
    106. "tag": "16float_read",
    107. "type": "16float",
    108. "functionCode": 4,
    109. "objectsCount": 1,
    110. "address": 25
    111. },
    112. {
    113. "tag": "32float_read",
    114. "type": "32float",
    115. "functionCode": 4,
    116. "objectsCount": 2,
    117. "address": 26
    118. },
    119. {
    120. "tag": "64float_read",
    121. "type": "64float",
    122. "functionCode": 4,
    123. "objectsCount": 4,
    124. "address": 28
    125. }
    126. ],
    127. "attributeUpdates": [
    128. {
    129. "tag": "shared_attribute_write",
    130. "type": "32int",
    131. "functionCode": 6,
    132. "objectsCount": 2,
    133. "address": 29
    134. }
    135. ],
    136. "rpc": [
    137. {
    138. "tag": "setValue",
    139. "type": "bits",
    140. "functionCode": 5,
    141. "objectsCount": 1,
    142. "address": 31
    143. },
    144. {
    145. "tag": "getValue",
    146. "type": "bits",
    147. "functionCode": 1,
    148. "objectsCount": 1,
    149. "address": 31
    150. },
    151. {
    152. "tag": "setCPUFanSpeed",
    153. "type": "32int",
    154. "functionCode": 16,
    155. "objectsCount": 2,
    156. "address": 33
    157. },
    158. {
    159. "tag":"getCPULoad",
    160. "type": "32int",
    161. "functionCode": 4,
    162. "objectsCount": 2,
    163. "address": 35
    164. }
    165. ]
    166. }
    167. ]
    168. }
    169. }

    秋千点赞.gif