From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read registers from two Modbus slaves

Solved!
Go to solution

Hello,

 

I have a question regarding the Modbus communication with more than one slave using the NI MODBUS Library.

 

I started with a simple point-to-point connection with a power analyser. That worked perfectly. Now I added a HART-Modbus Gateway to get the measured values from two mass flow meters. I tested this communication on its own and this worked well, too.

 

In the next step I wanted to get the data from the power analyser and the gateway within the same program. Therefore, I simply combined the two VIs and added the Set Unit ID VI to change the targeted Modbus slave.

 

I get the right values from the power analyser, but not from the gateway. This register stays empty most of the time and sporadically it is filled with zeroes. Since there are also no error messages that could give me any hint, I hope somebody from the community has a tip for me.

 

Attached you can find the three programs as VIs and pictures.

0 Kudos
Message 1 of 6
(3,366 Views)
Solution
Accepted by topic author Matthias_Gi

You can't run them in parallel like that.  You are sharing a modbus reference and changing the the unit ID.  That winds up affecting both paths.

 

You can create two Modbus entities.  Set each one to its own slave ID.  I assume they are still sharing the same serial port.  I would recommend serializing the communication with the error wire so that you only work with one at a time.

 

I myself would probably use just a single modbus reference, then in the loop set slave ID 1, read/write from that device, set slave ID 2, read/write from that device.  Do it in series and repeat every iteration.

0 Kudos
Message 2 of 6
(3,346 Views)

Thank you for the quick reply. Is this the serial solution that you had in mind?

 

Modbus_combined_serial.png

 

I just tested it and get the following error message when reading from the second device:

 

Error 56 occurred at RTU Data Unit.lvclass:Read ADU Packet.vi:5030001

Possible reason(s): LabVIEW: (Hex 0x38) The network operation exceeded the user-specified or system time limit.

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

Yes.  That is what I was talking about.  (These two devices do share the same serial port, correct?)

 

Try making sure you can communicate with each one individually with its own program.

 

While I have used the Modbus library with the purple header, I've used an older version for much longer.  What I like about that one is it works much more directly with the serial port and settings aren't hiding underneath the class wire of the the newer library.  While I would expect the new one to work okay, I don't know the underlying details of the class setup.  And much of that is hidden behind password protect VI's.

 

The older library is available here.  I sure a regular VISA Serial Configure subVI with the older library rather than the one they put in there.

https://www.ni.com/example/29756/en/

 

 

If you still have a problem with a device when trying it just by itself, then it is probably some other setup problem.

If they both work individually, but not with the VI you showed, you might want to try the older library set up in a similar serial manner.

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

Thank you very much. I found the mistake and it probably had nothing to do with the Modbus Library. Somehow reading the registers from the Power Analyser (UMG96RM-E from Janitza) triggers a restart of the HART-Modbus-Gateway (HRT-310 from ICPDAS). While the program tried to read the registers from the gateway, it was in an initialisation phase and therefore it could not read any values.

 

I tried around a bit and found that this does not happen as long as I do not read 120 registers or more at once. I have absolutely no clue why that is the case. Reading 119 registers is no problem. If I had to get the values of just 100 registers, I would not even have encountered that problem at all.

 

I now split the reading of the 120 registers into two separate ones with 60 registers each and everything works perfectly.

0 Kudos
Message 5 of 6
(3,232 Views)

It's probably a limitation of the device or the modbus protocol.

 

I think I read that ideally messages are less than 255 bytes.  Of course some bytes are overhead (command, number of registers, checksum, ...)   120 registers at two bytes per register would be 240 bytes just on register data.  Remarkably close to 255 when you add in overhead bytes.

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