LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

modbus read multiple regs array size always 9

Solved!
Go to solution

Hi,

 

I am using modbus read multiple registers. That sends an array. The array is by default 9 variables. If I then do convert array to cluster, its always 9 variables. If I delete 1 then the run button breaks And I guess I cannot have an array with just 8 values, or worse still, more than 9 values. If I want to read say 32 values in a row, I have to to 3 reads in 8 registers?

 

Cheers,

 Steffen

0 Kudos
Message 1 of 21
(3,533 Views)
Solution
Accepted by topic author Steffen01

Some immediate things:

  1. Where's your example VI?
  2. What Modbus API are you using?
  3. When you do the array -> cluster you can specify the size of the cluster (look at the right-click menu). Its like this because, at compile time, LabVIEW has no idea how many items will be in the array but a cluster has a fixed set of known items.
  4. In the Modbus APIs I have used you can read as little as 1 register, 100 and beyond.
Message 2 of 21
(3,523 Views)

here the vi, working on it, so a bit messy.

I did rightclick and create indicator. But even if I make one by hand, it wants to have 9 elements regardless.

The modbus library is this one

https://forums.ni.com/t5/NI-Labs-Discussions/Reading-array-of-holding-address-using-RTU-Modbus/m-p/3...

If it knows the array size on compile, but I cannot compile with the array size it should be.

0 Kudos
Message 3 of 21
(3,517 Views)

Why are you using array to cluster at all?  If you want to display  the array, just create an indicator and make it large enough to show all the elements.  If you want to access the individual elements of the array, then use index array.  Stretch the bottom border down to access more than one element at a time.  Wire up the index input only if you need elements out of order.  (No values gives you elements 0, 1, 2, 3, .... in order.)

 

If you truly do want to turn your array into a cluster than right click on the array to cluster function and set the number of elements you want to have in the cluster.  But I don't recommend that, and is not scalable.  If you later want to have more or fewer elements, then you need to edit your code to change that number, and edit the cluster accordingly.

Message 4 of 21
(3,494 Views)

Its 120 or so values I want to read. Most go into a SQL plus will be displayed. So I want to make a cluster, to unbundle by name later. Easier to handle. Some are in Groups, say 40020-40027 motor 1 to 8 RPM. Then I make a tabbed control for morors 1-8 and in SQL the column names will be 40020 motor 1 rpm, something on that line.

I found this

https://forums.ni.com/t5/NI-Labs-Discussions/Reading-array-of-holding-address-using-RTU-Modbus/m-p/3...

have to check later. Labview PC has no internet plus there are other issues to fix before.

 

0 Kudos
Message 5 of 21
(3,489 Views)

Don't unbundle by name on the cluster.

Index the elements out of an array.

0 Kudos
Message 6 of 21
(3,483 Views)

ubundle by name is just easier for me, because it goes into several vis. Otherwise I have to keep track of the indexes.

The registers on modbus are in no particular order. Might have to attach the register map somewhere

concatenate arrays otherwise I guess. Its like 40020-40027. Then a few registers not acessible. Then 40030-40037. Then some other vallues. And so on. So I have to read various blocks of multiple registers. Then concatenate as one array. cRio book says, dont pass too many variables. So I want to just pass one array from cRio to Host PC

0 Kudos
Message 7 of 21
(3,474 Views)

I can't see how it is any easier.  If you find arrays difficult, then you need to take some more LabVIEW tutorials.

 

Right now, there is no advantage to the cluster because when you convert the array to the cluster, you wind up with  a cluster that says basically 'element (0)'  'element (1)'  element (2)' ... up to 'element (119)'  Guess what?  All names that are generic with an index value in them.

 

Now you can go and bundle it into a cluster where you wire a constant into the top that redefines the names of each element.  Then each element would have a meaningful name.  Make sure you make that cluster a typedef.  But I really wouldn't want to waste my time trying to rename 120 elements in a cluster to give them meaningful names.  Though there should be a way to do that with scripting to make it easier.

 

If you have trouble determining what index means what, then create a second string array that has a name that matches each element in the numeric array 1:1.  That is easy to make if you imported it from a text file or Excel spreadsheet.  If you need to look up something by name, search 1D array on the string array, and use the returned index to index it out of the numeric array.

 


Steffen01 wrote: Then concatenate as one array. cRio book says, dont pass too many variables. So I want to just pass one array from cRio to Host PC

 Event that tells you that you need to work with an array.  It does not say "pass as a cluster".

0 Kudos
Message 8 of 21
(3,464 Views)

can pass cluster or array. Just not good to pass on 120 or so variables.

For unbundle by name of course I have to make a cluster and name each indicator. Then make a typedef. Just really a way to tell them apart later on. Arrays would be easier, but how knows later, which one is item 120? Easier if the wire has a name like 40020 motor 1 rpm.

0 Kudos
Message 9 of 21
(3,460 Views)

As I said, you'll know which item is which because you'll have a 1-D array of strings to serve as a lookup table.

 

I can tell you that in the long run, you are going to have a much harder time to manage your application with a cluster than you will with arrays.  Clusters aren't scalable, arrays are.  But I doubt you are going to believe me until that day you finally run into that problem.

 

In the meantime, you asked a question about why the Array to Cluster function is always 9, and tyk009 gave you the solution on how to change that to another value.  So go ahead, give him a Kudo, and mark his message #2 as the solution to your question.

Message 10 of 21
(3,455 Views)