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 Vs. GPIB

I have created a number of drivers for GPIB devices (voltmeters, generators and whatnot) using labview and it has always been pretty simple - just a matter of finding the right table in the instrument's manual and saving the right device-specific code as a string and passing it through a VISA write.

 

Well, I now have to create a driver for a GS3-2025 Durapulse variable speed drive, but it communicates via Modbus, not GPIB, and I have been having some difficulties.

 

For starters, I have downloaded nimodbus.mnu and placed it in my user.lib folder, and have the modbus example vis (though they havent done me much good).

I have also tried reading the introduction to Modbus at http://www.ni.com/white-paper/7675/en

However, the introduction has been little help for the same reason the GPIB introductions gave me little help when I was learning to write a GPIB device driver - it is a complete generalized introduction to how the communications system works, even though much of the functions described are handled by the VISA vis automatically - rather than a 'what you need to know to make a driver' type of instruction.

 

So, specifics:

http://www.automationdirect.com/static/manuals/gs3m/ch5.pdf

The above link is to the manual for the GS3 series of variable speed drives.

 

I guess my first question is:

In the pdf manual for the GS3, there are 3 columns, Hexadecimal, Modbus decimal, and Octal, and I am not sure which column (if any) represents the actual commands I need to send the device.

 

Second question: the NI Modbus library vis - do they take the place of the VISA functions, or are they to work WITH the VISA functions?

 

3rd question: if you scroll past the tables in that GS3 programming manual, (page 5-23) there are some codes listed that don't match up with the tables in the beginning.  All of the V20XX codes in that grey bubble dont seem to match anything in the tables, so I am not sure what they are.

 

The problem with being so new to Modbus - I am not exactly sure what are the right questions to ask, let alone the answers, so if you noticed a fundamental misunderstanding I seem to have about the way Modbus works, feel free to point it out.  My main goal is to get a driver for this variable speed drive so I can write a program in LabVIEW to control it, and I am having problems figuring out which codes I need to actually program it, and the syntax to use in LabVIEW. 

 

 

0 Kudos
Message 1 of 14
(4,138 Views)

1.  Use the Modbus decimal functions.  However drop the initial digit.  Also, the address of the register to use in LabVIEW is generally one less than the address in the manual.  So for parameter 2.00 Volts/Hz settings which says Modbus decimal 40513, you will use 512 as the address in the modbus command.

 

2.  The NI modbus library uses the VISA functions.  (You can drill down through the subVI's and look at the underlying code.)

 

3.  The top of page 5-23 talks about the "V" numbers being in octal, and to convert them to hex to find them.  But that is very strange because no one ever uses octal for anything.  Beyond that, I wouldn't be surprised if there were some errors in those diagrams.  Actually if you look at the "bubbles" on page 5-23 and compare them to the chart on 5-11, they look like all the numbers listed in the octal column of that chart except that the digit 4 in the middle of the octal number is missing.  So the bubbles look like they all have editing mistakes where the digit "4" in the middle of the number disappeared.

Message 2 of 14
(4,110 Views)

Don't mind the delay, this project has ended up on the back burner a little bit, but I have another question:

 

On page 5-6 you can see a list of the different parameters, however, what you don't see, are instructions to assign a value to those parameters.

 

So, for example, Parameter P4.00 defines the source of the frequency command.  Parameter P4.00 can have 6 different values.

When P4.00 = 1, frequency is determined by digital keypad up/down.

When P4.00 = 2, the frequency is determined by 0 to +10V input.

When P4.00 = 5 (this is the one I want) the frequency is determined by the RS-485 input.

 

Note: P4.00 = 5 is not the same as P4.05

 

So, the modbus decimal function for P4.00 is 41025.  As RavensFan said, I should drop the initial 41 and subtract 1, and I get 024 as the address in the modbus command.

 

I have a guess as to continue, but I am not sure:

The 'MB Serial Master Query Read Coils (poly).vi' has inputs labeled "Starting address" and "Quantity"

My guess is in order to set the drive to P4.00 = 5, then I would wire the number '024' to the "Starting address" input and the number '5' to the "Quantity" input.

 

I am also not sure if the .vi should be set to 'write (single/multiple) coils' or 'write (single/multiple) register'.

 

0 Kudos
Message 3 of 14
(4,038 Views)

Actually I realize that last guess is wrong:

The input "quantity" refers to the number of coils you want to read/write, and that they only take a value of true or false.

 

Maybe I just need some more explination of the Modbus library .vis, for some reason the detailed help comes up blank for me.  Can anyone give me an explination of what the inputs "starting address", and "serial parameters" are for?

 

Serial parameters gives me 2 controls, 1 for Mode (RTU or ASCII, fairly self explanitory) and one for Slave Address (0-9. A-F).

 

I am also not entirely sure what the "coils" refer to - before I likened them to the individual serial bus intputs in a GPIB controller, but I am not so sure.

0 Kudos
Message 4 of 14
(4,022 Views)

Quantity refers to the number of registers you want to write to in a row if you are doing a multiple register read or write.  If you want only one register, than it should be a quantity of one.  You would put the 5 as a single element within a 1-D array of values

 

Coils refers to boolean registers which have a true or false value.  You would put a true or false into each element of the 1-D array of booleans.  How many elements you use in that array is determined by how many coils you want to write to.

 

Starting address is the number for the first of the registers you want to read or write.  Serial parameters define things about the slave you are trying to talk to such as the slave address (to distinguish it from other slaves that might be listening on a multidrop network) and RTU/ASCII which determines the structure of the messages being sent.

 

If are trying to write to a register that takes a number, then you don't want "coils".  You want to use either input register or holding register.  One is read/write, the other is read only.  Off hand I don't remember which is which.

 

None of this has anything to do with GPIB bus inputs.

Message 5 of 14
(4,007 Views)

Thanks for being patient, I have been having some trouble understanding the ModBus language.

 

I compiled a graphic of the ModBus library .vis in labview, (attached) that shows and labels the inputs.

 

There is one .vi with "holding registers" that is an output only - this must be the 'read only' you were talking about, but I do not see an "input registers" control.

 

Maybe I should start a little more general to give you an idea of what it is I am trying to accomplish:

 

We have a variable speed drive that I want to be able to communicate to.  The full manual is available here.

The drive comes with a controller with basic functions that I need to replicate - run/stop/reset, as well as up/down arrows that control the frequency when the parameter P4.00 is set to 1 (which is the default).  When the parameter P4.00 is set to 5, the frequency can be controlled by the RS-485 input, which is the goal.

 

As I said before, the modbus decimal function for P4.00 is 41025, as shown in chapter 5 page 6, which should translate to 024 (as per your previous post, RavensFan).

 

I am not sure which modbus .vi (shown in attachment) and which inputs to use to set the parameter P4.00 to the value of 5.

 

 

 

 

 

Side note: I only brought up the individual GPIB bus inputs as an analogy, it may have been wrong, but it seemed to me like the 'coils' are the individual bit-by-bit inputs for ModBus, just like the individual 'pins' in the GPIB bus.

 

 

 

 

0 Kudos
Message 6 of 14
(3,986 Views)

Is it possible I will have to dive into one of the modbus library .vis and edit it so that it has the inputs that I am looking for?

0 Kudos
Message 7 of 14
(3,985 Views)

Hi Lars,

 

If I understand your question correctly, you would use the Modbus Serial Master Query (poly) VI and select the dropdown of Single Register Write.

 

ModbusSingleRegisterWriteExample.PNG

For the Holding Register input, enter the value you would like to write to that register (41024/P4.00).

 

Note that if you wanted to do multiple register writes, you would select the Write Multiple Registers dropdown and the polymorphic Holding Registers input would accept an array of the values to be written to the respective registers. 

Joey S.
Senior Product Manager, Software
National Instruments
Message 8 of 14
(3,969 Views)

I've dug into my references on Modbus a bit.

 

A holding register is one that you can read or write to.  It has addresses beginning with a 4, so 40012 for example.  (Drop the 4 and subtract 1, and you'd use 11 in LabVIEW.)  You read it using function code 3.  To write to the registers, you use either function code 6 for a single register, or 16 for multiple registers.

 

An input register is one that is read only.  (Of course the slave device has its internal programming that can assign a value to the register.)  They begin with a 3, so 30015 for example.  (Drop the 3 and subtract 1, and you'd use 14 as the address in LabVIEW).  You read it using function code 4.

 

(I do remember that the numbering scheme vs. function code seemed backwards.  Code 4 to read 30000 series registers, and code 3 to read 40000 series registers.)

 

You should not need to edit any of the modbus VI's to get them to work.  (Note that some people have come across a couple bugs that should be fixed, but they have never caused me problems.)  I haven't used the newer version posted on the NI website which is now using polymorphic VI's.  I started my programming with an earlier version of the VI's.  So I've kept the older version installed on my machine and have not installed the polymorphic version.  One day if I do a major revision on my programs that use these (and I have a few), I'll upgrade the Modbus library to the polymorphic version.  If you can't find the type of register you are look for, right click on the Query VI and see if there is another instance of the polymorphic version that is correct for you.

 

For more details on modbus, go to the Modbus organization website and look at their papers.  http://www.modbus.org/specs.php

Message 9 of 14
(3,965 Views)

Thanks guys, you both have been a big help.  I've got to spend some time with automation direct technical support for a couple specific questions regarding the variable speed drive itself, but I'll keep your suggestions in mind and probably come back to this thread in a few weeks when I have some more questions.  It looks like you guys have given me a pretty good place to start.  Thanks again!

0 Kudos
Message 10 of 14
(3,956 Views)