Ali_dotNet
Ali_dotNet

Reputation: 3279

read multiple modbus addresses with one request

I'm reading a MODBUS device using C#, VS2010, I'm working on a telemetry application, my device has several hundred addresses, and I need to read something at address x and another at address x+130, currently I'm using following code to read 135 bytes, while I only need two addresses, but it is not efficient, is there any way to read two separate addresses using one MODBUS request? My current code is:

bd[0] = Convert.ToByte("01");
bd[1] = Convert.ToByte("03");
bd[2] = Convert.ToByte("00");
bd[3] = Convert.ToByte("135");
bd[4] = Convert.ToByte("00");
bd[5] = Convert.ToByte("87");
bd[6] = Convert.ToByte("180");
bd[7] = Convert.ToByte("29");
port.Write(bd, 0, 8);

I write these bytes to my COM port which is attached to the MODBUS device.

Upvotes: 0

Views: 2880

Answers (1)

avra
avra

Reputation: 3730

There are many libraries to help you with MODBUS in C# (if there isn't some special reason why you deal with the bytes directly at the low level?). MODBUS can read single register or multiple registers range if registers are one after the other (as you have found out), but it doesn't allow you to read registers that are not one after the other in a single function call. You have to use more function calls for that. Saying this, it would be more efficient to read 2 registers with 2 function calls then to use 1 function call to read 135 bytes (there are simply less bytes and therefore faster). And one last remark, MODBUS function 3 that you have used in your example reads 87 registers (174 bytes) starting from register 135 from slave number 1. Not at all what you described you wanted it to do.

Upvotes: 3

Related Questions