Closed GoogleCodeExporter closed 9 years ago
NModbus only supports reading 16 bit holding registers as there is no Modbus
function
code for reading 32 bit holding registers. If your microcontroller supports 32
bit
values, simply read it in two 16 bit chunks, then perform the a conversion to
your 32
bit integer or float.
There are already conversion helper methods in Modbus.Util.ModbusUtil -
GetSingle
And ToUInt32 which take two 16 bit values and return a float or integer
respectively.
For more conversion methods check out Mono’s DataConvert class which replaces
.NET’s
System.BitConvert http://www.mono-project.com/Mono_DataConvert
Does this answer your question?
Scott
Original comment by sja...@gmail.com
on 19 Jul 2007 at 3:18
Hello Scott
How do I address the second 16 bit chunk? as there is 32bits in holding
register
7101 and 32 bits in 7102. so if I read holding register 7101 i get the first 16
bits
but I don’t know how to address the other 16 bit? is it possible?
my basic reading code is below that reads holding register 7101 into an ushort[]
can you show me how to read the second 16bit chunk?
using (TcpClient client = new TcpClient(sIPAddress, 502))
{
Modbus.Device.ModbusTcpMaster master = Modbus.Device.ModbusTcpMaster.CreateTcp
(client);
string sMenu = "71";
string sStartParameter = "01";
string sStartAddress = sMenu + sStartParameter;
int iStartAddress = (Convert.ToInt32(sStartAddress) - 1);
ushort usStartAddress = (ushort)iStartAddress;
int iNumParameters = 1;
ushort numInputs = (ushort)iNumParameters;
ushort[] inputs = master.ReadHoldingRegisters(usStartAddress, numInputs);
}
Regards Clinton Storer.
Original comment by clinto...@iprimus.com.au
on 19 Jul 2007 at 11:30
Original comment by sja...@gmail.com
on 2 Dec 2007 at 1:32
Original issue reported on code.google.com by
clinto...@iprimus.com.au
on 19 Jul 2007 at 6:05