具体协议百度一下,这里只介绍tb相关的点。结合modbus salve(modbus从机模拟)。modbus poll可以读写 modbus salve的数据
- id
- 设备编号:对应modbus.json中的unitId
- function
- 功能代码: 对应modbus.json中的functionCode
- 读数据
- 1 读
线圈[只有开关俩种值] 读写 - 2 读
离散输入只读 - 3 读
多个保持寄存器读写 - 4 读
输入寄存器只读
- 1 读
- 写数据
- 5 写单个线圈
- 6 写单个寄存器
- 15 写多个线圈
- 16 写多个寄存器
- 读数据
- 功能代码: 对应modbus.json中的functionCode
- 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

{"server": {"type": "tcp","host": "127.0.0.1","port": 5020,"timeout": 35,"method": "socket","byteOrder": "BIG","devices": [{"unitId": 1,"deviceName": "Temp Sensor","attributesPollPeriod": 5000,"timeseriesPollPeriod": 5000,"sendDataOnlyOnChange": true,"attributes": [{"tag": "string_read","type": "string","functionCode": 4,"objectsCount": 4,"address": 1},{"tag": "bits_read","type": "bits","functionCode": 4,"objectsCount": 1,"address": 5},{"tag": "8int_read","type": "8int","functionCode": 4,"objectsCount": 1,"address": 6},{"tag": "16int_read","type": "16int","functionCode": 4,"objectsCount": 1,"address": 7},{"tag": "32int_read_divider","type": "32int","functionCode": 4,"objectsCount": 2,"address": 8,"divider": 10},{"tag": "8int_read_multiplier","type": "8int","functionCode": 4,"objectsCount": 1,"address": 10,"multiplier": 10},{"tag": "32int_read","type": "32int","functionCode": 4,"objectsCount": 2,"address": 11},{"tag": "64int_read","type": "64int","functionCode": 4,"objectsCount": 4,"address": 13}],"timeseries": [{"tag": "8uint_read","type": "8uint","functionCode": 4,"objectsCount": 1,"address": 17},{"tag": "16uint_read","type": "16uint","functionCode": 4,"objectsCount": 2,"address": 18},{"tag": "32uint_read","type": "32uint","functionCode": 4,"objectsCount": 4,"address": 20},{"tag": "64uint_read","type": "64uint","functionCode": 4,"objectsCount": 1,"address": 24},{"tag": "16float_read","type": "16float","functionCode": 4,"objectsCount": 1,"address": 25},{"tag": "32float_read","type": "32float","functionCode": 4,"objectsCount": 2,"address": 26},{"tag": "64float_read","type": "64float","functionCode": 4,"objectsCount": 4,"address": 28}],"attributeUpdates": [{"tag": "shared_attribute_write","type": "32int","functionCode": 6,"objectsCount": 2,"address": 29}],"rpc": [{"tag": "setValue","type": "bits","functionCode": 5,"objectsCount": 1,"address": 31},{"tag": "getValue","type": "bits","functionCode": 1,"objectsCount": 1,"address": 31},{"tag": "setCPUFanSpeed","type": "32int","functionCode": 16,"objectsCount": 2,"address": 33},{"tag":"getCPULoad","type": "32int","functionCode": 4,"objectsCount": 2,"address": 35}]}]}}

