Jump to content

Recommended Posts

Posted

Hello,

 

I have an integer that contains the position of a bit in an array that I would to set to 1. Entering numbers in array for the position is possible, but entering my integer isn't. Unilogic says that the integer is longer then the array length. 

 

Is there a possibillity to limit my integer (I know that it isn't longer than my array)?

Posted

To clarify, you are trying to set the bit in the array using the index value from the integer?

 

For example if the number in the integer is [6] you want to set the eighth bit in an array. So an array of 8 bits would look like 0 0 1 0 0 0 0 0.

 

Is this correct?

Posted

Yes, however i don't understand the second sentence.

 

I want to set the bit by using the index value. If you got an array bit[0..8] of all zero's and I do: set array[5] the result will be 000010000.

after that set array[3] will create 001010000 

 

I would like to do so with a integer. Then I could store the position of the bit that I would like to set in the integer and then set it by doing set array[integer]. 

Posted

Binary is usually read from right to left which is why I gave the example of setting the 6th bit as 0 0 1 0 0 0 0 0 in an 8 bit array.

 

Which function are you currently using within UniLogic? There is not a set array function.

 

There is not a built in function for the operation you are describing but it may be possible to create a UDFB that can replicate this process. Since bit arrays are normally operated from right to left will this work or do you need it to work in the opposite way?

Posted
            
            BEGIN_RUNG
                register int RLO1, RLO2;

                /* BusBar Inited RLOs */
                RLO1 = RLO2 =  RLO;
                /* BusBar */

                BEGIN_BLOCK
                    /* 1. Direct Contact */
                    ACC_AND(RLO1, _op_op9F23C19D);
                    /* 2. Set Coil */
                    SET(RLO1, _op_op08576FC6[12]);
                    /* 3. Reset Coil */
                    RESET(RLO1, _op_op9F23C19D);
                END_BLOCK
                BEGIN_BLOCK
                    /* 4. Find in Array */
                    FIND_IN_ARRAY(RLO2, _op_op08576FC6, 20, 0, 1, _op_op7DDFD44C);
                    /* 5. Store */
                    _ERROR_IN_ELEMENT(Error in Element ID = 855f5872-dd58-4b3c-83cb-9ceac16033c3, Message = Error during operand compile )
                END_BLOCK
                /* End Junction */
            END_RUNG

Can you see what I display here? Don't know another way to display. 

 

I just want to store a certain value in an array by entering not a number but an integer between the [ ]

 

Maybe writing a UDFB could be the solution, but is it also possible for multiple arrays?

Posted

Hi,

The Arrays in UniLogic works in a way that you can give a name to items inside an array.

Given that, assume the following situation:

 

Array_Int with Member:

Hello  // index 0

World // Index 1

 

Now, the lexer let you access a cell in the array by either:

Array_Int[0]

or

Array_Int[Hello]

 

 

UniLogic prevents the existance of 2 tags with the same name, on the same scope (You can have 2 local tags, each on a different function with the same name, but having a global tag with that name would create a conflict, because the compilier will not know to which tag you actually refer).

 

 

Now, consider the following scenario:

I also have a tag called Hello.... So if I write Array_Int[Hello], then I want to access index 0, or the index with the value of the Hello Tag?

 

 

This is one of the resons why we don't allow indirect access to array cells in the way ou have mentioned.

About the error you got.

The Compiler/Lexer looks for a member called Integer_Tag (or what ever your tag is named), but since it can't find any array member with that name, then it gives you that error (which is in this case, not clear and not accurate).

 

 

 

So wait, that means that you can't access an array cell indirectly??

Well, you can, but not in the way you've tried.

 

 

Try using "Load from Array" for getting a value indirectly from an array, and "Store in Array" for setting a value indirectly to an array.

 

:-)

  • Upvote 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.