Example VI to communicate with Modbus equipment
#1
Posted 29 April 2010 - 02:46 PM
Thank you.
#2
Posted 29 April 2010 - 03:05 PM
#3
Posted 29 April 2010 - 03:11 PM
What about it didn't work out? Can you share the code that you wrote that doesn't work?I tried the NI Modbus library but it did not work out, so I'm not sure what I'm missing.

#4
Posted 29 April 2010 - 04:14 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 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.
register def.txt 1.13K
616 downloads
#5
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
"If this was easy our kids would be doing it." - Coworker
#6
Posted 29 April 2010 - 07:48 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.
Thanks.
#7
Posted 29 April 2010 - 07:51 PM
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
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
"If this was easy our kids would be doing it." - Coworker
#9
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
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
"If this was easy our kids would be doing it." - Coworker












