LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus RTU Reading Issue with LabVIEW 2024

Solved!
Go to solution

Hi everyone,
I'm working on an application using LabVIEW 2024 with Modbus RTU communication over RS-485, and I'm having trouble reading data from a signal transmitter (indicator).

Current setup:

  • I'm using a simple Modbus master-slave configuration just to try to read values.

  • I'm still trying to fully understand the device’s protocol, so I might be misinterpreting something.

Transmitter configuration:

  • Baud rate: 9600

  • Data bits: 8

  • Stop bit: 1

  • Parity: None

  • Scan rate: 0

  • Sent rate: 0

  • Communication module: Modbus RTU

  • Unit ID (slave address): 1

  • Scale: 0

The issue:
I'm not able to read the indicator values properly. Communication seems to be happening, but the data I receive doesn't make sense (or I just get zero). I suspect I might be reading the wrong registers or not interpreting the protocol correctly.

Below, I’m attaching:

  • The transmitter’s Modbus protocol document

  • MarcusP_0-1745496719305.pngMarcusP_1-1745496735041.png

     

  • A screenshot of my LabVIEW application

If anyone has experience with this kind of setup or has any tips (especially around correctly reading registers or setting up the communication), I’d really appreciate your help!

Thanks in advance!

0 Kudos
Message 1 of 15
(1,537 Views)
Solution
Accepted by topic author MarcusP.

I just took a brief look at the VI you attacked and at least two things stood out (no guarantee that there are not other things);

 

First off you try to write two doubles to holding holding register 0, which in this case means registers 40001-40006 in the supplier's specification, which are defined as read only...So you probably get an error back on that, which affects the next step where you try to read 6 registers from 40036, which you for some reason interpret into a 9-element (!) cluster of U16's which does not make sense as they come in as 6 U16s already and you can just use array index to get to the U16 you try to display. 

 

Strip away the write, skip the loop and set the read to address 0 and the number of holding registers to e.g. 1 and just see if that returns something (display the error cluster in the loop to see any errors as they come). Tell us what it says if you want further support...

 

If that returns OK you can start to add more and loop things. Use a third party master to verify that you should be able to do this with your software (make sure you close LabVIEW before so the serial port is not blocked...), and if needed compare the poll command sent on the serial port form that software with the one you generate (if any) with your LabVIEW code...Once they match you can expect your code to work too.

PS. I have never used the NI library for Modbus (we write our own instead to have more low level control) so I may have overlooked other things here...If you want to try a nice alternative here is one with quite a nice design:

https://www.vipm.io/package/mb_master/

 

 

0 Kudos
Message 2 of 15
(1,517 Views)

Alright, so I tried to keep things as simple as possible and I managed to get valid results — values are displaying correctly on the indicator now. When the value is negative, it shows up as 65535, which I assume is due to unsigned interpretation — but that basically solves my issue for now!

At this point, it's mostly about adjusting the zero offset on the physical device, but for testing purposes, it’s good enough and I can finally start doing at least a very basic analysis.

Here’s what I ended up using:
- Starting address: 0
- Number of inputs: 1

(I might try to convert this into a continuous array later, but I think I can figure that part out — or I’ll just be back here asking for help again 😄)

Thanks again!

PS. I forget to add the .vi, sorry 

0 Kudos
Message 3 of 15
(1,486 Views)

Hi,

 

Reading address 40001 is a DCS notation in my world.

For the actual ModBus usage this address 0000 using function code 3 (or 4)

This may look strange but connecting DCS to a ModBus slave this normal practice.

 

Kees 

 

0 Kudos
Message 4 of 15
(1,470 Views)

Okay, so I don't know what to do. For some reason, now it just shows this error no matter what.

MarcusP_0-1745950515384.png

Maybe it's the driver, I just don't know. I tried uninstalling everything and reinstalling it, but in the end, nothing changed — and I just don't know what else I can do.

 

0 Kudos
Message 5 of 15
(821 Views)

This is not a ModBus problem. ;Your serial link is not working.

 

RS-485 is a very good interface if it is setup correctly.

Can you show me the connection. How long are the wires between the device and the computer.
Have you tried to swap the A and B (or + and -) wire ?

Some manufacturers use notations as A- and B+. Very confusing.

 

Kees

0 Kudos
Message 6 of 15
(812 Views)

This seems like a TCP terror, have you accidently changed the type from serial RTU to Modbus TCP?

0 Kudos
Message 7 of 15
(804 Views)

Alright, I'm going to post everything I can to try to figure out this issue:

  • I'm using the same settings that were already working last week.

  • [Image of the HK]

  • This one is using Modbus Test Master.

  • [Image of the Master]

Now, regarding the question about the wiring — I wasn’t the one who set it up, but according to my colleague, he hasn’t touched the cables since the first installation.

  • [Photo of the RS485 wiring]

  • [Photo of the device]

  • [Photo of the Transmitter]
0 Kudos
Message 8 of 15
(763 Views)

There was a broken wire in the RS485 connection.
After fixing it, everything is working properly now. Thanks for the help!

The only issue now is with negative numbers — for some reason, it's showing 65554, and I don’t know why.

0 Kudos
Message 9 of 15
(725 Views)

65554 is larger than 16 bits.

 

If it is 65535 than it could also be -1

Depends on the number format.

 

Kees

0 Kudos
Message 10 of 15
(686 Views)