首页 新闻 会员 周边 捐助

NMobus4.netcore读寄存器报错 Function Code: 131

0
悬赏园豆:20 [已关闭问题] 关闭于 2024-07-29 09:41

using SerialPort sport = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
//NModbus4实例
using ModbusMaster master = ModbusSerialMaster.CreateRtu(sport);

//打开串口
sport.Open();

var data=master.ReadHoldingRegisters((byte)1, (ushort)2, (ushort)2);

Function Code: 131
Exception Code: 2 - The data address received in the query is not an allowable address for the server (or slave). More specifically, the combination of reference number and transfer length is invalid.For a controller with 100 registers, the PDU addresses the first register as 0, and the last one as 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 4, then this request will successfully operate(address-wise at least) on registers 96, 97, 98, 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 5, then this request will fail with Exception Code 0x02 “Illegal Data Address” since it attempts to operate on registers 96, 97, 98, 99 and 100, and there is no register with address 100.
用modsim模拟的从机:

求解决

李三超的主页 李三超 | 初学一级 | 园豆:154
提问于:2024-07-27 16:32
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册