Tim8888 Posted April 29, 2010 Report Share Posted April 29, 2010 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. Quote Link to comment
David Wisti Posted April 29, 2010 Report Share Posted April 29, 2010 What kind of Modbus? TCP, Serial, ASCII, RTU, Plus, etc. Quote Link to comment
crelf Posted April 29, 2010 Report Share Posted April 29, 2010 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? Quote Link to comment
Tim8888 Posted April 29, 2010 Author Report Share Posted April 29, 2010 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. register def.txt Quote Link to comment
Tim_S Posted April 29, 2010 Report Share Posted April 29, 2010 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 Quote Link to comment
Tim8888 Posted April 29, 2010 Author Report Share Posted April 29, 2010 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. Quote Link to comment
David Wisti Posted April 29, 2010 Report Share Posted April 29, 2010 (edited) 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 April 29, 2010 by David Wisti Quote Link to comment
Tim_S Posted April 29, 2010 Report Share Posted April 29, 2010 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 Quote Link to comment
Buddyfares Posted May 6, 2010 Report Share Posted May 6, 2010 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 Quote Link to comment
Tim_S Posted May 14, 2010 Report Share Posted May 14, 2010 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 Quote Link to comment
Meriem Ait Posted June 16, 2016 Report Share Posted June 16, 2016 Please how can i have the modbus library for labview Quote Link to comment
LogMAN Posted June 16, 2016 Report Share Posted June 16, 2016 7 hours ago, Meriem Ait said: Please how can i have the modbus library for labview As far as I know there is only one library freely available at NI labs: https://decibel.ni.com/content/docs/DOC-30140 You'll of course not receive any support from NI, but it is a good start. I have never used it btw. Quote Link to comment
ensegre Posted June 16, 2016 Report Share Posted June 16, 2016 Not to mention The MB icons in the screenshot upward in this thread make me think that the OP was referring to the old (not good old) ni-modbus-1.2.1, still available here: http://www.ni.com/example/29756/en/ I have used the latter here and there for simple communication, and while I could make it work, I was not impressed by quality, and vaguely remember bugs and quirks. Quote Link to comment
smithd Posted June 17, 2016 Report Share Posted June 17, 2016 15 hours ago, LogMAN said: As far as I know there is only one library freely available at NI labs: https://decibel.ni.com/content/docs/DOC-30140 You'll of course not receive any support from NI, but it is a good start. I have never used it btw. That library is in the product (RT and DSC, same as the IO servers) as of 2014 and that is officially supported. 15 hours ago, ensegre said: referring to the old (not good old) ni-modbus-1.2.1 Lol, true Quote Link to comment
Shaik Hussain Ali Posted March 28, 2017 Report Share Posted March 28, 2017 Hello, I have have downloaded modbus library in LabVIEW and i am having this device which is 8-digital-inputs-8-digital-outputs-IO-8DIO here i don't know how to use this modbusi have made the connections with rs485 with convertor to 8-digital-inputs-8-digital-outputs-IO-8DIO. Now i want to write/read some data into the registers but i don't know how to write/read data into the respective registers can any one please help me regarding this.Am using Labview 2015 http://www.brainchild.com.tw/en/2-1752-41592/product/8-digital-inputs-8-digital-outputs-IO-8DIO-id147282.html (Datasheet is available here) Quote Link to comment
smarlow Posted March 28, 2017 Report Share Posted March 28, 2017 From the device documentation, it looks like the digital outputs can be written using registers 00017-00024 (assume the addr. are decimal), or using the single register 40003. There are VIs in the library for writing either single or multiple registers. Quote Link to comment
Shaik Hussain Ali Posted April 3, 2017 Report Share Posted April 3, 2017 hello, I am getting error when i run the Vi as error code 56 RTU Data Unit.lvclass:Read ADU Packet.vi:5030001 Quote Link to comment
Tim_S Posted April 3, 2017 Report Share Posted April 3, 2017 Error code 56 is a timeout error. The first thing I always check is that everything is plugged in, powered on and the cable is correct type (crossover or strait through) and not damaged. It's surprising how often one of those is the culprit. ("Of course I turned it on! See... uhhh.... oops...") Quote Link to comment
smithd Posted April 5, 2017 Report Share Posted April 5, 2017 With RTU in particular I've found that there are a lot of devices that don't follow the spec with regard to parity, stop bits, etc. Since its RTU I'd verify the settings from your device's spec sheet and check them against the modbus setting. Section 2.5.1 here http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf Bits per Byte: 1 start bit, 8 data bits, 1 bit for parity completion, 1 stop bit Even parity is required, other modes ( odd parity, no parity ) may also be used. In order to ensure a maximum compatibility with other products, it is recommended to support also No parity mode. The default parity mode must be even parity. Remark : the use of no parity requires 2 stop bits. Theres a decent number of devices out there which use no parity and 1 stop bit, making them not modbus devices. To resolve this with the modbus library, you must use a visa property node to re-set the stop bit after initialization and before talking to your device. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.