a0135600 / nmodbus

Automatically exported from code.google.com/p/nmodbus
0 stars 0 forks source link

Error in ReadInputRegisters (SerialRTU) #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
During reads to the input registers when using the ModbusSerialMaster in
RTU mode, the values that come back are from the Holding registers instead.
 I have looked through the source and noticed that the ReadHoldingRegisters
is missing from the overrides in the RTU module.  However, when I attempted
to implement them, the changes didn't fix the problem.  I am too busy to
look into the solution now, but will when I have a chance.

Original issue reported on code.google.com by kain...@gmail.com on 22 Nov 2006 at 2:09

GoogleCodeExporter commented 8 years ago
I think that I found the issue in the ModbusMaster.cs file.  It seems that the
ReadInputRegisters function called the internal ReadRegisters function, that 
used a
constant function value of Modbus.ReadHoldingRegisters.  For this function 
alone, I
have fixed it as:

public ushort[] ReadInputRegisters(byte slaveAddress, ushort startAddress, 
ushort
numberOfPoints)
{
  ReadHoldingInputRegistersRequest request = new
ReadHoldingInputRegistersRequest(Modbus.ReadInputRegisters, slaveAddress,
startAddress, numberOfPoints);
  ReadHoldingInputRegistersResponse response =
Transport.UnicastMessage<ReadHoldingInputRegistersResponse>(request);

  return CollectionUtil.ToArray<ushort>(response.Data);
}

Original comment by kain...@gmail.com on 22 Nov 2006 at 7:29

GoogleCodeExporter commented 8 years ago
Wow, that's a big bug. It was introduced by a refactoring performed for version 
0.0.2 and it also affect ReadInputs. I will release a fix shortly.

Thanks!

Scott Alexander

Original comment by sja...@gmail.com on 30 Nov 2006 at 4:07

GoogleCodeExporter commented 8 years ago
Kainous,

Thanks for the heads up. The fix has been added to the trunk. I push the 
binaries to 
the website tonight hopefully.

Thanks.

Scott Alexander

Original comment by sja...@gmail.com on 1 Dec 2006 at 6:00

GoogleCodeExporter commented 8 years ago
There is same problem in tcp master. Looks like serial fix was just overlooked 
to be 
updated in tcpmaster.

To Fix:
in ModbusTcpMaster.cs

Problem Function:
     public ushort[] ReadInputRegisters(ushort startAddress, ushort numberOfPoints)
     {
     return base.ReadHoldingRegisters(Modbus.DefaultTcpSlaveUnitID, startAddress, 
     numberOfPoints);
     }

Fixed Function:
     public ushort[] ReadInputRegisters(ushort startAddress, ushort numberOfPoints)
     {
     return base.ReadInputRegisters(Modbus.DefaultTcpSlaveUnitID, startAddress,
     numberOfPoints);
     }

Original comment by came...@calacosolutions.com on 17 Jan 2007 at 10:13

GoogleCodeExporter commented 8 years ago

Original comment by sja...@gmail.com on 2 Dec 2007 at 1:35