Hi all, this is a long one, so there's a TL;DR at the bottom
I have a situation where I'm dragging data from an external database into a UDT in a Control Logix PLC. The only problem is, the only way I can get the data to come in is by arraying the UDT elements, instead of arraying the UDT itself. By which I mean, the normal way I would do it is to create a UDT as follows:
ID, DINT
Name, STRING
Speed, DINT
Temperature, REAL
...
...
and then I would create an array of this UDT, so that I have:
Recipe[0].ID
Recipe[0].Name
Recipe[0].Speed
Recipe[0].Temperature
Recipe[1].ID
Recipe[1].Name
Recipe[1].Speed
Recipe[1].Temperature
Recipe[2].ID
Recipe[2].Name
...
...
Recipe[99].Speed
Recipe[99].Temperature
But I can't do that. I have to create the UDT like this:
ID, DINT[100]
Name, STRING[100]
Speed, DINT[100]
Temperature, REAL[100]
...
...
Which means I then create a single instance of this UDT, which is populated from my DB, and looks like this:
Recipe.ID[0]
Recipe.ID[1]
...
...
Recipe.ID[99]
Recipe.Name[0]
Recipe.Name[1]
...
...
Recipe.Name[99]
Obviously this is a pain for a lot of reasons, but I can live with it for now. However, what I'd like to do is create a UDT the "proper" way, and when the operator calls for a recipe, copy the data from the relevant database fields into that one UDT for loading into the line parameters. So if they call for recipe 12, I copy Recipe.ID[12] into RecipeUDT.ID, Recipe.Name[12] into RecipeUDT.Name, and so on.
I'm fine with the concept of indirect addressing, but what I'd like to do is use structured text to iterate through each element of the array instead of having to manually code a copy for each element of the array. I'm a complete novice at ST, so I'm not sure how to approach it, but I would imagine that it would look something like:
Am I close to the mark? Is there anyone who's a more familiar with ST that can give me a nudge in the right dance floor?
Thanks!
TL;DR - from a UDT where each element is arrayed, can I copy the data from one array element into a UDT with an identical structure but with single (not arrayed) elements?
I have a situation where I'm dragging data from an external database into a UDT in a Control Logix PLC. The only problem is, the only way I can get the data to come in is by arraying the UDT elements, instead of arraying the UDT itself. By which I mean, the normal way I would do it is to create a UDT as follows:
ID, DINT
Name, STRING
Speed, DINT
Temperature, REAL
...
...
and then I would create an array of this UDT, so that I have:
Recipe[0].ID
Recipe[0].Name
Recipe[0].Speed
Recipe[0].Temperature
Recipe[1].ID
Recipe[1].Name
Recipe[1].Speed
Recipe[1].Temperature
Recipe[2].ID
Recipe[2].Name
...
...
Recipe[99].Speed
Recipe[99].Temperature
But I can't do that. I have to create the UDT like this:
ID, DINT[100]
Name, STRING[100]
Speed, DINT[100]
Temperature, REAL[100]
...
...
Which means I then create a single instance of this UDT, which is populated from my DB, and looks like this:
Recipe.ID[0]
Recipe.ID[1]
...
...
Recipe.ID[99]
Recipe.Name[0]
Recipe.Name[1]
...
...
Recipe.Name[99]
Obviously this is a pain for a lot of reasons, but I can live with it for now. However, what I'd like to do is create a UDT the "proper" way, and when the operator calls for a recipe, copy the data from the relevant database fields into that one UDT for loading into the line parameters. So if they call for recipe 12, I copy Recipe.ID[12] into RecipeUDT.ID, Recipe.Name[12] into RecipeUDT.Name, and so on.
I'm fine with the concept of indirect addressing, but what I'd like to do is use structured text to iterate through each element of the array instead of having to manually code a copy for each element of the array. I'm a complete novice at ST, so I'm not sure how to approach it, but I would imagine that it would look something like:
Code:
For each element in Recipe (
COP element[pointer] RecipeUDT.element 1
)
Am I close to the mark? Is there anyone who's a more familiar with ST that can give me a nudge in the right dance floor?
Thanks!
TL;DR - from a UDT where each element is arrayed, can I copy the data from one array element into a UDT with an identical structure but with single (not arrayed) elements?