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: 

Modbus serial communication

Solved!
Go to solution

Hi everyone,

I am trying to read holding registers values off an Omega USB DAQ device using a virtual serial port that uses Modbus RTU protocol. First, I have, what I think is a timing problem. I have attached the portion of VI in question. The error I keep getting, which comes from the "Read Holding Registries VI," is: Error 56, 

RTU Data Unit.lvclass:Read ADU Packet.vi:5030001

 

Can anyone help me resolve this? I know that the serial port configuration is correct because I can read the registers with the software provided by Omega. 

 

One additional question: The DAQ manual states that the Modbus query delay be 0ms and the response delay be 3ms. It is not obvious to me if this can be set using the Modbus VI library. Is this a standard setting, or can I change the values?

 

Thanks for any help.

0 Kudos
Message 1 of 12
(8,298 Views)

Are you sure you've got the serial port settings correct?

You haven't wired anything into the configure, so you are using all the defaults.  You should also disable the terminal character.  But I don't think you need to use the Serial Configure because all of the settings should be handled by the New Serial Master subVI.  (It uses a default of 9600 baud since nothing is wired in.)

 

But  the problem I see is with your Modbus Read.  You have a number 40049 wired in.  While modbus talks about registers such as 40049, in the actual communication protocol, you drop the prefix 4, and subtract one (because the real addresses are zero based.)

 

So change 40049 to 48 and see what happens.

 

As for your query delays, I've never needed to worry about them.  And those numbers are low enough that the device should work just fine.

 

One more thing.  Don't use VISA Close.  Use the Modbus Shutdown VI that is in those palettes.  It will close out the VISA Resource and also clean up all the stuff associated with the modbus class wire.

0 Kudos
Message 2 of 12
(8,287 Views)

Thanks for the quick reply RavensFan, quick update:

 

I changed the register address, but I still get the same error.

 

When I deleted "VISA Close," the port is left open. I can't access it from the Omega software I mentioned earlier. I have to keep "VISA Close" in there in order for the other software to be able to access the port. Maybe this is a bug in the Shutdown VI?

 

In terms of the port settings, I checked them again and the defaults are the same as the Omega software except for flow control. In the other software, flow control is set to "RTS only", and it doesn't read correctly if I change it to RTS/CTS. In LabVIEW, I noticed that "RTS only" is not an option. Is this the same as "none"? I don't know much about this particular serial setting...

 

Who Dey!

0 Kudos
Message 3 of 12
(8,279 Views)

Hello

 

Sometimes it's a small detail that makes the difference between working and not working. And If I was in your situation my approach would be simple sniffer to the two applications. Create an application that is always receiving and the  write with both (one of a time) and compare.

 

Br,

Jorge Amaral

 

Software developer
www.mcm-electronics.com





PORTUGAL
0 Kudos
Message 4 of 12
(8,262 Views)
Solution
Accepted by topic author nschweit302

@nschweit302 wrote:

Thanks for the quick reply RavensFan, quick update:

 

I changed the register address, but I still get the same error.

 

When I deleted "VISA Close," the port is left open. I can't access it from the Omega software I mentioned earlier. I have to keep "VISA Close" in there in order for the other software to be able to access the port. Maybe this is a bug in the Shutdown VI?

 

Strange, I would have thought it would close it down.  Perhaps there is a bug, or they never programmed it to.  It is hard to know because those VI's are password protected.

 

Take a look and try an older Modbus library given here. MODBUS Library for LabVIEW

I used that from early on before the newer ones came out and has always worked for me.  It is completely unlocked so you can drill into the subVI's and see what is happening.

 

In terms of the port settings, I checked them again and the defaults are the same as the Omega software except for flow control. In the other software, flow control is set to "RTS only", and it doesn't read correctly if I change it to RTS/CTS. In LabVIEW, I noticed that "RTS only" is not an option. Is this the same as "none"? I don't know much about this particular serial setting...

 

Who Dey!


One other thing about the older library I use is that the VISA wire continues throughout and doesn't get hidden within the object/class wire that the purple headered library uses.  One other thing is that I don't use the MB Init on that older library and always set the serial settings myself using the Serial Config like you have at the beginning of this VI.

 

I have never heard of "RTS Only" flow control, and NI-VISA doesn't have that as an option.  Only RTS/CTS.  But honestly, it is very unusual to see any devices nowadays that require hardware flow control.

Message 5 of 12
(8,240 Views)

Thanks RavensFan. Not sure why the newer library did not work, but switching over to the older library worked!

 

One reason could be with the read VI from the older library, it was obvious to me where I could set the slave address. I don't think I did this with the newer library VI because I could not find the option. Could have been there, I just didn't see it.

0 Kudos
Message 6 of 12
(8,201 Views)

nschweit302 wrote:

One reason could be with the read VI from the older library, it was obvious to me where I could set the slave address. I don't think I did this with the newer library VI because I could not find the option. Could have been there, I just didn't see it.


To set the slave address in the newer Modbus library, use Set Unit ID in Modbus -> Modbus Master -> Utilities.In that same palette there is Set Timeouts which you can use to set the delays mentioned in your original post.

0 Kudos
Message 7 of 12
(8,191 Views)

hi,

i'm using modbus serial communication for read the data continuously. when i freshly open the program to run the program its fine. reading are shown. when i stop the program then run then program its not fine.reading didn't shown.

 

That means whenever open the program first time run is fine. When i stop the program then i run the program is crate the error. can you help me?

0 Kudos
Message 8 of 12
(7,550 Views)

Please show us your code. Do you get any specific error? If so, which error?

0 Kudos
Message 9 of 12
(7,544 Views)

hi,

here i had attach the my program image.

0 Kudos
Message 10 of 12
(7,532 Views)