nmodbus readholdingregisters errors when reading certain addresses

R

Thread Starter

rlemon

When attempting to read the holding registers using nmodbus net 3.5 I am receiving unexpected errors, only when reading addresses outside of 40001-40008

Code(C# + NModBus Net 3.5):<pre>
byte sid = 1;
ushort saddress = 0;
ushort snumregisters = 8;
ModbusSerialMaster master = ModbusSerialMaster.CreateRtu(port);
ushort[] registers = master.ReadHoldingRegisters(sid, saddress, snumregisters);</pre>
The above code works fine and i get expected results back for the 8 addresses in <i>registers[]</i>, however if i change <i>saddress</i> to <b>50</b> i receive the following errors: *Running the code above on a loop with one second delay*<pre>
Message:: Function code 123 not supported.

Message:: The I/O operation has been aborted because of either a thread exit or an application request.

Message:: Exception of type 'Modbus.SlaveException' was thrown.
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.

Message:: Function code 0 not supported.

Message:: Checksums failed to match 0, 232, 249 != 0, 232, 249, 255, 155

Message:: Function code 126 not supported.

Message:: Checksums failed to match 243, 239, 245 != 243, 239, 245, 254, 0
</pre>
 
Hello,

What slave device are you using? It might not have more than 8 holding registers so reading 50 registers fails.

We have a free simulator that supports all registers. Try it and see if you get the same error.

Good luck,

Mark
http://www.peakhmi.com/
 
My Slave device is an in house design, and looking at the specs to the I/O board there should be values coming back on 40001-40008 40051-40058

Also, just with an update. On my test project I'm writing I'm seeing a lot of inconsistent results.

I have the code displayed running on a loop (every half second i want an update to see if any values have changed) and on about 3% of the responses i will get

function code (126, 119, ect) not supported
and the occasional checksum error.

This makes no sense to me as i am sending the exact same request, just a second time.
 
Hello,

Have you tried our slave as suggested? I ask this because if it works with another slave without error it can help narrow down the possible problems.

Is this 232 or 485? What baud rate?

Good luck,

Mark
http://www.peakhmi.com/
 
I cannot seem to get your application to work with my com ports. it does not seem to want to assign to a port or open any new ports.
 
Hi,

Without more specific data, all I can say is it has been used 1000's of times and no reports of errors.

I can only speculate that it is a virus protection program preventing operation, or the port(s) is in use by another program.

Good luck,

Mark
http://www.peakhmi.com/
 
Top