Jump to content


Photo
- - - - -

Example VI to communicate with Modbus equipment


  • Please log in to reply
9 replies to this topic

#1 Tim8888

Tim8888

    4 more posts to go.

  • Members
  • 6 posts
  • Version:LabVIEW 8.6
  • Since:2004

Posted 29 April 2010 - 02:46 PM

Does someone have an example VI for communicating through Modbus with an equipment with LabVIEW? It'll be great if you can share the code. I tried the NI Modbus library but it did not work out, so I'm not sure what I'm missing.

Thank you.



#2 David Wisti

David Wisti

    Very Active

  • Members
  • PipPipPip
  • 113 posts

Posted 29 April 2010 - 03:05 PM

What kind of Modbus? TCP, Serial, ASCII, RTU, Plus, etc.

#3 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,742 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 29 April 2010 - 03:11 PM

I tried the NI Modbus library but it did not work out, so I'm not sure what I'm missing.

What about it didn't work out? Can you share the code that you wrote that doesn't work?

post-181-1170858537.png


#4 Tim8888

Tim8888

    4 more posts to go.

  • Members
  • 6 posts
  • Version:LabVIEW 8.6
  • Since:2004

Posted 29 April 2010 - 04:14 PM

I would prefer using Serial but there is TCP option as well. It looks like the equipment I am using have the option to select between RTU and ASCII, but the default is RTU.

I ran the example VI in the library and I am getting "Timed out" errors. I'm new to this so not really sure where to start troubleshooting. If there's an existing code that someone has that works on their end, then it will be helpful for me to troubleshoot it.

I have attached a list of register defintion here. I know the serial settings. I do not know how to pass info to the unit and receive feedback. I'm not sure how to format the command or how to incorporate it with the modbus library vi.

Attached File  register def.txt   1.13K   616 downloads

#5 Tim_S

Tim_S

    The 500 club

  • Members
  • PipPipPipPipPip
  • 516 posts
  • Location:Michigan
  • Version:LabVIEW 2011
  • Since:1994

Posted 29 April 2010 - 07:29 PM

I ran the example VI in the library and I am getting "Timed out" errors. I'm new to this so not really sure where to start troubleshooting. If there's an existing code that someone has that works on their end, then it will be helpful for me to troubleshoot it.


I've used to example/library from the NI website with success. The code does work.

Timeout out with serial would tend to indicate to me that there was no response. You should get error messages if you are talking to the device. My first suggestions would be physical. Are you plugged in on both ends? Are you plugged into where you think you are? Do you have a null-modem cable when you need a strait-through or visa-versa? Is the device on?


Tim
Tim

"If this was easy our kids would be doing it." - Coworker

#6 Tim8888

Tim8888

    4 more posts to go.

  • Members
  • 6 posts
  • Version:LabVIEW 8.6
  • Since:2004

Posted 29 April 2010 - 07:48 PM

The machine is on, connections are good. I've tried both straight through and cross cable.

Here is a screen shot of the MB Serial Example Master vi. It times out trying to read discrete inputs. This is the initial hurdle and I'm also stuck on how to send or commands to read/write. Such as in the attached text file above, 005 is to read the software status, how should this command be formatted and inserted in the code.

Thanks.

timeout.JPG

#7 David Wisti

David Wisti

    Very Active

  • Members
  • PipPipPip
  • 113 posts

Posted 29 April 2010 - 07:51 PM

Next thing to find out is if the unit your trying to communicate to is a master or slave. I'm guessing its a slave. The NI Modbus Library supports RTU and ASCII. If you have Labview DCS or RT, you could use the Modbus I/O Servers. I know that Modbus I/O Servers supports RTU but have never used it myself. The examples that ship with the NI Modbus Library are probably not going to work without some modification to the reading and writing.

I would first try to read 1 word at the first address and see if you can get some data from the device. You could use a known Modbus master like Modpoll to help you troubleshoot the communication. Although the register def file is pretty cryptic (a nice secret decoder ring would be nice ), it looks like address 1 through 35 can be accessed with a read function and 201 through 203 from a write holding registers command. I highly suggest you read up a bit on the basics of Modbus first before you dive in and try to communicate. The focus here would not be the entire protocol but just start with understanding the memory map in Modbus and some of the basic function calls. It could be that addresses 1 through can only be accessed from a read input registers command. The equipment you have should have documentation describing which modbus functions should be used to communicate.

Here a good start on Modbus info:

http://www.modbus.org/specs.php
http://en.wikipedia.org/wiki/Modbus

Edited by David Wisti, 29 April 2010 - 08:04 PM.


#8 Tim_S

Tim_S

    The 500 club

  • Members
  • PipPipPipPipPip
  • 516 posts
  • Location:Michigan
  • Version:LabVIEW 2011
  • Since:1994

Posted 29 April 2010 - 09:07 PM

Here is a screen shot of the MB Serial Example Master vi. It times out trying to read discrete inputs. This is the initial hurdle and I'm also stuck on how to send or commands to read/write. Such as in the attached text file above, 005 is to read the software status, how should this command be formatted and inserted in the code.


My best guess is you need to set the address, change from input registers to holding registers, and set the correct number of words you want to read. The Modbus spec (see David Wisti's link) is pretty readable and does contain the error codes you'll get back from the device.

One caveat about Modbus addresses is the address you need to request may not be the one documented by the manufacturer, but it will be near that address (+/- a couple); I've found this to be the case on Festo and Cuttler Hammer equipment (to boot the PLC and PC request different addresses for the same register... arg!).

Tim
Tim

"If this was easy our kids would be doing it." - Coworker

#9 Buddyfares

Buddyfares

    One hit wonder!

  • Members
  • 1 posts
  • Version:LabVIEW 2009
  • Since:2009

Posted 06 May 2010 - 03:26 PM

My best guess is you need to set the address, change from input registers to holding registers, and set the correct number of words you want to read. The Modbus spec (see David Wisti's link) is pretty readable and does contain the error codes you'll get back from the device.

One caveat about Modbus addresses is the address you need to request may not be the one documented by the manufacturer, but it will be near that address (+/- a couple); I've found this to be the case on Festo and Cuttler Hammer equipment (to boot the PLC and PC request different addresses for the same register... arg!).

Tim



I too am looking for a RTU MODBUS example. I need to read and write to a modbus slave. I tried the sample program that uses the MODBUS vi master with no sucsess. I have written seueral programs in VB and am new to LAbView. An example of a vi that can read and write to a 40000 register would be helpfull.

Thanks

#10 Tim_S

Tim_S

    The 500 club

  • Members
  • PipPipPipPipPip
  • 516 posts
  • Location:Michigan
  • Version:LabVIEW 2011
  • Since:1994

Posted 14 May 2010 - 01:13 PM

I too am looking for a RTU MODBUS example. I need to read and write to a modbus slave. I tried the sample program that uses the MODBUS vi master with no sucsess. I have written seueral programs in VB and am new to LAbView. An example of a vi that can read and write to a 40000 register would be helpfull.


The example works, however there is a constant on the block diagram for the register address. You may also need to switch betwen input and holding registers. Appologies that I can't be more helpful right now.

Tim
Tim

"If this was easy our kids would be doing it." - Coworker