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模拟的从机:
求解决