Step7 Array Operation

douyi

Member
Join Date
Aug 2005
Location
Toronto
Posts
123
There is a problem in array function. If I define an array as Integer like Arrary1[0..99], I can access this array as an Int datatype, but I can't access in Bits, and I don't want to map it to a middle address, because that's too much.

Is there any better idea to do that?

Thanks.
 
Still cannot do that

I tried and it doesn't work. What I did is define a symbol "HMI_Bits" in DB as a DWORD (or DINT), and I want to access like this:

A "HMI_Bits".0
A "HMI_Bits".1
= "HMI_Bits".2


I can do that by build another UDT as "32 Bits" which include 32 Boolean datatype in it, but I can't give a direct number to that element to initialize or for drive many outputs in just one rung.

Maybe I misunderstood how to access the DWORD datatype variables. Is there someone used this kind of function before?

Thanks.
 
i do not know how to do it with symbolic addressing

but with absolute addressing u can do it

if db1.aa[1] is db1.dbw0

then the first bit is db1.dbx0.0

also u can define the array type as a struct

and define the bits accordindly

if the aaray name is abc and the first element is bit0

then type a db1.abc[1].bit0
 
That's what I've done.

I know I can do it in absolute addressing, and I defined an array of UDT which is 32bits together. But I cannot access these bits as Dint at the same time.

Let's say I want to initialize these bits as 1111_0011_1100_0000_1111_1111_1111_0000 then you will have too much work to do. Instead of that, if I can only give a value to this element (now is a UDT which I cannot do that) like move a number to it, it will be simple and fast.

That's the reason I want to use it as a Dint datatype in Symbolic Addressing.

Any better ways to do that? Thanks in advance.
 
douyi said:
There is a problem in array function. If I define an array as Integer like Arrary1[0..99], I can access this array as an Int datatype, but I can't access in Bits, and I don't want to map it to a middle address, because that's too much.

Is there any better idea to do that?

Thanks.

Could you specify what you need to achieve in more detail ?
 
I see what you are trying to do, and it is not possible with pure symbology. That said, there is a pretty decent work-around that I use all the time. To address a doubleword that is made up of an array of bools, just use the starting address of the array to create a pointer. For instance, if you determine that the start of the "HMI Bits" array is at DB10.DBX34.0 (this can be done dynamically), then you could transfer P#34.0 to AR1 and then address DBD[AR1,P#0.0] in your code.

Like I say, this pointer can be calculated (there are already other threads that describe this), and will be the most graceful solution.
 
Original question In Detail

I defined a symbolic named array in shared DB named HMI_Comm_Words, it has 100 elements in DINT datatype.

What I want to use these DINT is communicate with HMI. Some of the elements are control bits, some of them are values. In control bits, I want to access like this:

A HMI_Comm_Words[10].1
A Motor.Ready
= HMI_Comm_Words[30].1

And these bits are not accessable by symbolic way.

The question is "If I want to do these things in this way, how can I do that?"
 
For instance, if you determine that the start of the "HMI Bits" array is at DB10.DBX34.0 (this can be done dynamically), then you could transfer P#34.0 to AR1 and then address DBD[AR1,P#0.0] in your code.

Yes, that's right. But the problem is, if I use UDT and I modified the structure of the udt, after I update the DB, the address of the start address of the array will change. But anyway, that's a solution, or I have to put that in first line, so it will never change.

Another thing is: The pointer will never know the address you access if excess the array or not, or by the pointer, you may get next varible's value if you put wrong number in it. Is that right?
 
And I tried ...

And I defined two variables, one is INT, the other is WORD just want to test that function. And I found it's not because of array, even a single variable have the same problem. That means I cannot access "Var_1.1" directly.

and Var_1 is an INT or WORD, Var1.1 suppose to be the second bit of it.

Shall I do that the same way by accessing AR register or we have alternative way to do that?
 
But the problem is, if I use UDT and I modified the structure of the udt, after I update the DB, the address of the start address of the array will change.

That's why the adress needs to be determined dynamically. Then, you will never have the wrong address. Again, there are other threads that explain how you can do this. Do a search on "UDT".
 

Similar Topics

Hello all.... I'm still coming to terms with Siemens PLC programming after many years of only knowing AB, so be gentle - :rolleyes: I've got an...
Replies
11
Views
4,336
Hi' I am trying to make a "lookup" in an table I have created in an array. My tabel looks like this: 0,920 21,75 200,1 0,00047 0,910 24,99...
Replies
3
Views
3,698
Hey Guys.. Here's my problem. I have an array of 9 characters, a "part number". I need to compare this array to another part number that is...
Replies
10
Views
6,604
Hello, I have created a FB and in the declaration, added an array of bools as a stat and cannot figure out how to add a comment to individual...
Replies
5
Views
3,387
I've got an application where a robot is running 10 objects one after another past a camera so I need to buffer the result of the camera test...
Replies
20
Views
9,322
Back
Top Bottom