LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Modbus Registers indpednantly ?

Hello,

I have noticed something when using DSC Modbus I/O servers to communicate with a Modbus slave. I am reading probably 100 or so registers form one consecutive range of holding resisters and I need to read 2 from another range of holding registers. The latter 2 registers are not consecutive (separated by 5 registers) and the registers in between are not accessible and return a Modbus error in system manager (or in modscan) if I try to read them. Basically Labview is doing a read of length 6, which reads the registers in between.

 

If I reduce the Holding registers “Maximum Data Points Per Command” in the “Advanced Settings” of the I/O Server to 4 or less the last 2 registers can be read properly with, one Modbus read (of length 1) per register, but this increases the total number of Modbus reads required to read the first 100 registers.

 

Is the best solution to this to create two Modbus I/O servers? The first one can read the first 100 registers, by doing a read of length 100, and the second I/O server can do 2 reads of length 1, to obtain the last 2 variables.

 

Thanks

Chris  

 

 

0 Kudos
Message 1 of 5
(3,637 Views)

Hi Chris,

 

What I would suggest is creating one Modbus I/O Server and specifying 3 different register ranges (see the picture here).

 

modbusranges.png

 

The first range would contain 100 items and the other two ranges would only contain 1 item each and would have the register of interest specified under "Data Item" in the "Add range" dialog box. Even though the last two registers are individual you still need to add them with the "Add range" button in order to get them to reference properly. Let me know if this helps, I would be interested to hear about how well your workaround works.

 

Tim W.

Applications Engineering

National Instruments

http://www.ni.com/support 

0 Kudos
Message 2 of 5
(3,591 Views)

HI, thanks for your help.

But, when I follow your steps I am observing basically the same results as before.

I am using a network analyzer (Wireshark) to look a the modbus packets going to the device. I still find that Labview/Share Variable Engine is trying to read the two singular registers with one modbus read(of length 6). Again this causes an issue because the slave device has several registers between these two that are unreadable (for some reason), and therefore the slave responds with a modbus error.  It makes sense that labview would try to optimize the number of reads and do things this way.

 

I can reduce the maximum number of holding register per command setting in the "Advanced" section of the I/O Server properties. This will inhibit the SVE from making long modbus reads and force it to make two reads to read the 2 non consecutive registers. But again this causes the other 100 holding registers to be read with short modbus reads (not optimal).

 

So to answer your question, having two modbus I/O servers seemed to work. The first one contains the first 100 shared vaibles bound to their respective registers with the maximum holding register per command left at the default 123, the second I/O server contains the 2 other shared variables bound to their respective Modbus registers, but the maximum holding registers per command is set to 2.

 

Its a workaround, but really the problem is the way our serial device set up its registers.

Thanks

 

Chris

  

 

 

 

 

Firstly, My work around seems to work, its not a really elegant way to solve the problem but it seems

0 Kudos
Message 3 of 5
(3,585 Views)

Hi Chris,

 

Thanks for posting more info on your workaround, I would be interested in seeing the error details you receive when trying to do the reads in the normal way.

 

Tim W.

Applications Engineering

National Instruments

http://www.ni.com/support 

0 Kudos
Message 4 of 5
(3,582 Views)

Hi Tim,

See screen shots of system manager and a test.vi that I made to show the error associated with reading the shared variables, for simplicity I only used 26 registers (rather than 100) in the 450001 range and my other 2 registers are 410403 and 401408.

 

Using Wiresharks it is easy to see that Labview is doing two modbus reads. (Function code 3). The first one is of length 26 starting at address (4)50001 and the the slave device responds correctly, with the appropriate data. The second Modbus read command is of length 6 starting at address (4)10403. The slave responds with a Modbus Exception:( Illegal data address). Because  registers  410404-410407 are not set up as being readable, in the slave device. Therefore 410403 and 401408 both show up with errors.

 

Using my work around, and looking at the packets using wireshark, It can be seen that labview is doing 3 Modbus reads (Function Code 3), the first one being the 26 registers, then it does a read of  length 1 to get the 401403 register and then a another read of length 1 to get the data from the 401408 register.

 

From a modbus traffic perspective this is the optimal way to acquire the data, given the functionality of the slave device. Having 2 modbus I/O servers may create a small amount of extra overhead on the master side but the network traffice doenst seem to be increased. System Manager.JPGErrors.JPG  

 

 

 

0 Kudos
Message 5 of 5
(3,574 Views)