Rob
Rob

Reputation: 11798

How to get the correct values from this Modbus address?

I have a MOXA Modbus TCP module (M-4210 in combination with the NA-4010 networking module that also has some other modules attached) that works as a 2-channel analog output, each with voltages from 0 to 10 Volts.

In my C# application I need to get the current values of these outputs, which is not as easy as I'm quite new to the whole Modbus thing.

In my code I already have a working modbus tcp client that does its job, I tested it by reading and writing single coils of another digital output module. The analog output module however seems to work with registers instead of coils.

To start from the beginning, these are the modbus settings for the two channels within this module (taken from the MOXA ioAdmin Tool):

enter image description here

and the addresses:

enter image description here

And here's another screenshot from the web interface:

enter image description here

So I tried to read the values like this:

ModbusClient c = new ModbusClient();
c.Connect("172.17.6.15", 502);
int[] r = c.ReadHoldingRegisters(2048, 1);
for (int i = 0; i < r.Length; i++)
{
    textBox1.Text += r[i].ToString() + System.Environment.NewLine;
}

This code returns one value, it changed as follows:

I seem to be on the right track, but I don't quite understand the offsets and how to separate the channels when the value comes back. It would be great if someone could shed some light on this, thanks in advance!

Upvotes: 0

Views: 2235

Answers (2)

Ronaldo
Ronaldo

Reputation: 635

Is your client handling Modbus endianess correctly? Modbus is big endian.

1140 is 0x474, 29696 is 0x7400. 1139 is 0x473, 29440 is 0x7300. I can see a pattern. It seems that your Modbus client is setting the LSB to 0 and taking the MSB by shifting the received LSB to the left.

Try changing the channel's value to 1141, you'll probably read 29952 in your client. That will confirm my suspicion.

Upvotes: 3

Kevin Herron
Kevin Herron

Reputation: 7015

Try reading Holding Register 2047 and see if you get the value you're looking for...

Although it seems like the value you're after is shifted by 1 byte, not 2, so you might need to read 2047 and ask for 2 registers and do the shift yourself. Very strange.

Upvotes: 0

Related Questions