LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NI Modbus 6 digit addressing

I am using NI Modbus library v1.2.0. I use 5 digit address(from 40001) which I am able to read or write. When I switch to 6 digit address(from 400001) I get a timeout error. I am trying to access this register by adding starting address as 1 and function code(Read holding registers) in both the cases. 

Is there any limit to Modbus RTU address range?

How to do 6 digit addressing using this library?

0 Kudos
Message 1 of 6
(3,245 Views)

Hi,

 

How ModBus addresses are specified is always a problem between different levels of accessing ModBus interfaces.

 

If the first address is specified like 40001 it is what we call a DCS address.

This must be translated to the ModBus function and address

40001 is in ModBus Function code 3 and address 0.

 

But 40001 could also be a valid ModBus address.  400001 is beyond the 16bits ModBus addressing. Maybe that is why the first one works, but it is a different address

 

Kees

Message 2 of 6
(3,220 Views)

In addition you also have to consider the base and offset of the address. If it is a so called DCS address it is decimal and the first number indicates the type of object to access which determines the Modbus function code (FC) to use:

 

Address   Access   FC              Operation

0xxxx            R        1                Read Coil (boolean)

0xxxx            W       5                Write Coil (boolean)

1xxxx            R        2                Read Input (boolean)

3xxxx            R        4                Read Input Register (16-bit)

4xxxx            R        3                Read Holding Register (16-bit)

4xxxx            W       6                Write Holding Registers (16-bit)

 

In this mode the address part is normally 1 based, with 0001 specifying the first register, which in the Modbus protocol is actually 0000.

 

There exist many other address naming schemes, the Modbus specification was originally just a spec that Modicon had created for its own PLCs and very liberally published. Because of that, many others adapted it but had their own ideas about how to name things and what sort of notation to use to describe their own protocol implementation.

 

One other common notation is that the register type is specified explicitly (or implicitly if the device only contains numeric registers and no boolean elements, which is often the case for most non-PLC devices such as motor controllers) and the address is just the actual Modbus register address, and therefore 0 based. This address is in this case often documented in sedecimal notation, also often called hexadecimal, but other notations are also possible such as octal or decimal. Which one exactly is used in the documentation is often not specifically documented, you just have to guesstimate and find out by trial and error.

 

The NI library uses explicit register specifications and the 0 based address, just as what is transmitted in the Modbus protocol itself. The maximum address that can be used in that way is 0xFFFF or 65535.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 3 of 6
(3,209 Views)

Thanks for your reply.

 

Actually the device I am communicating with uses 6 digit addressing and for this device 16-bit address is only used from 00001 - 65536. The first digit is anyways the identifier for holding registers(4). So my device only checks last 5 digits for knowing the address. 

 

Can a similar thing be done from LabVIEW end? 

Or 6 digit addressing is not possible with the mentioned library?

0 Kudos
Message 4 of 6
(3,197 Views)

It's simply an interpretation thing! That documentation uses an extended DCS addressing scheme. While a DCS address normally only contains 5 digits and the first is the register type, yours seems to use 6 digits with the first being the register type.

 

So remove the first digit from your address. It is implicit by using the according Read or Write Holding Register VI.

 

The rest seems to need to be adjusted with -1 to end up with the used 0 based addressing mode from the NI library.

 

Et voilà, there you are!

 

If you have a 5 digit DCS address you need to do the same! Do not try to pass 40001 to the NI library. It will accept it since it happens to fit into the 16-bit address that the library uses but it will access a very different register than what you originally intended. Some devices will simply return a random number, others might return an error since they do not know that address!

DCS address 40001 corresponds to the Modbus Holding register 0 and you need to pass 0 to the NI Read (or Write) Holding Register VI.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 5 of 6
(3,182 Views)

Thanks for your reply. 

 

I created a separate VI just to test the 6 digit addressing. I have hard coded the serial parameters. I have attached the image of VI for reference. 

In this case I write the registers 400501- 400512 in my device. So I set the starting address at LabVIEW end as 500 and pass register array of size 11 with required data. 

In this case, sometimes the communication is successful and data that I write is reflected at the respective addresses. 

But in some cases I get a Timeout error(error code 6101). This errors appears randomly and I tried increasing the timeout set. 

My device responds within 300ms. 

And after getting this error, if I stop the VI then LabVIEW doesn't release the COM port.

What could be the issue?

 

0 Kudos
Message 6 of 6
(3,124 Views)