Cancel
Showing results for 
Search instead for 
Did you mean: 

Expressions in logic block parameters

Hi,

 

I have created a logic block (TxPlcLogicBehavior), populated it with Entries and Exits and attached them to robot signals which works as expected.

When I add parameters with expressions (for test purposes simply setting it to the value of an entry), this appears to work OK, there are no errors, but the value of the parameter (as viewed in Simulation Panel) is not updated.

If I inspect it using "Edit Logic Resource" in the GUI, the values of the expressions are displayed correctly, and *after* I have viewed them, and OK'd the "Edit Logic Resource" form, the Simulation panel updates the values correctly. It appears that there is some change that is made when OKing the "Edit Logic Resource" form which finalises the expression insertion.

 

The code which creates the parameter and expression is:

              // Create expression, and use it in creation of parameter
              TxPlcExpressionBuilder eb = new TxPlcExpressionBuilder();
              eb.Add("entry1");
              ITxPlcLogicBehaviorParameterCreationData parameterCreationData = new TxPlcLogicBehaviorExpressionValueParameterCreationData("param1");
              ITxPlcLogicBehaviorParameter param = myLB.CreateParameter(parameterCreationData);

What would I need to add to the code to mean that I don't have to view and "OK" every parameter in the GUI?

7 REPLIES

Re: Expressions in logic block parameters

Update:

I think I have tracked it down to my use of the expression builder - it seems it is not effective to use text directly as a parameter of TxPlcExpressionBuilder.Add(...).

 

Further update:

For the benefit of anyone else trying to create logic blocks from the API, my attempt so far has involved finding named Entry signals from within the logic block (could similarly get Parameters or Exit signals), and building up an expression piecemeal using these:

 

private TxPlcLogicBehaviorEntry GetEntry(TxPlcLogicBehavior LB, string Name)
        {
            TxPlcLogicBehaviorEntry GetEntry=null;
            foreach (TxPlcLogicBehaviorEntry LBE in LB.Entries)
                if (LBE.Name == Name) GetEntry = LBE;

            return GetEntry;
        }

 

 

 

This is then used something like this:

 

 

   ITxPlcLogicBehaviorEntry LBEntry1= GetEntry(LB, "R1_ReqToEnter1");
   ITxPlcLogicBehaviorEntry LBEntry2= GetEntry(LB, "R2_ReqToEnter1");
   TxPlcExpressionBuilder eb = new TxPlcExpressionBuilder();
eb.Add(LBEntry1); eb.Add(TxPlcExpressionOperator.And); eb.Add(TxPlcExpressionOperator.Not); eb.Add(TxPlcExpressionOperator.LeftParenthesis); eb.Add(LBEntry2); eb.Add(TxPlcExpressionOperator.RightParenthesis);

ITxPlcLogicBehaviorParameterCreationData parameterCreationData = new TxPlcLogicBehaviorExpressionValueParameterCreationData("MySignal", eb.Expression);
ITxPlcLogicBehaviorParameter param = LB.CreateParameter(parameterCreationData);

 

 

This seems to work, but it requires that the entries/parameters used to create the value exist before they are used, so if A depends on B then B cannot also depend on A. With the GUI this is possible, as a parameter can be created and then its value edited after creation of other parameters - with the API it seems the expression can only be set within the creationdata, and there is no possibility to modify it after creation.

 

If anyone has any pointers on the effective use of the expression builder in such cases, that would be appreciated.

Re: Expressions in logic block parameters

You do have to have all of the other objects created in the Logic block beforehand before using the expression builder.  Create an Logic Block Behavior object and pass it to a method that will build each component of the expression for the expression builder to add. They all have to exist in the logic block FIRST!  You cant use a string as any addition to the expression builder, they are only "placeholders".  You have to build it by adding objects. See below.  Then make the Logic Block Expression equate the Expression Builder Expression.  Also one note this builder has some funky behavior.  If you step through the code while it is adding object the builder will lose the last object added in iteration.  For each loop the last loops addition dissapears, so at the end only the last loop's addition sticks in the array in the builder.  This particular issue had me stuck FOREVER lol.  Put a break point after the loop, don't step through and watch each one get added!!!!

 

 if (ExpList[i] is TxPlcExpressionOperator)
                    {
                        eb.Add((TxPlcExpressionOperator)ExpList[i]);
                    }
                    else if (ot == "Tecnomatix.Engineering.Plc.TxPlcLogicBehaviorExpressionValueParameter")
                    {
                        eb.Add((TxPlcLogicBehaviorExpressionValueParameter)ExpList[i]);
                    }
                    else if (ExpList[i] is TxPlcLogicBehaviorAtPoseSensorParameter)
                    {
                        eb.Add((TxPlcLogicBehaviorAtPoseSensorParameter)ExpList[i]);
                    }
                    else if (ExpList[i] is TxPlcLogicBehaviorEntry)
                    {
                        eb.Add((TxPlcLogicBehaviorEntry)ExpList[i]);
                    }
                    else if (ExpList[i] is ITxPlcSignal)
                    {

                        eb.Add((ITxPlcSignal)ExpList[i]);
                    }
                    else if (ExpList[i] is ArrayList)
                    {
                        ArrayList AL = ExpList[i] as ArrayList;
                        TxPlcExpressionFunctionType type = (TxPlcExpressionFunctionType)AL[0];
                       

                        AL.Remove(type);
                        eb.Add(type, AL);
                    }
                    else if (ExpList[i].ToString() == "(")
                    {
                        //eb.Add(" ");
                        TxPlcExpressionOperator op = TxPlcExpressionOperator.LeftParenthesis;
                        eb.Add(op);
                    }
                    else if (ExpList[i].ToString() == ")")
                    {
                        TxPlcExpressionOperator op = TxPlcExpressionOperator.RightParenthesis;
                        eb.Add(op);

                    }
                }
            }

            Expression = eb.Expression;
        }

Re: Expressions in logic block parameters

Hi Cliff,

Thanks for your comments - I've now got a semi-automated solution where the entries, exits and parameters are created when I can, and use text otherwise. The user then needs to go through in the GUI removing inverted commas, and it works (if a bit messy). It's not something that will need to be done often (only when we start working on a new standard) so not too much of a problem.
I'd struggled for a while with the same issue you did stepping through the code: I think it is not actually the stepping through that is the problem but monitoring the values. It seems like the "get" method actually resets the value, and this is obviously called by the watch window if it is contained in an expression you are watching!

Best Regards,

Andrew

Re: Expressions in logic block parameters

Where are you having trouble and need to use the string add method?  I am asking because I have managed to do it without ever having to resort to using a string placeholder, and I can probably point you in the right direction to fix whatever issues you are having.

Re: Expressions in logic block parameters

I can create entries, exits and parameters, so long as they do not have any mutual inter-dependence: I have a parameter A which depends on parameter B, but parameter B also depends on parameter A.
If I could go back and re-edit A to include the B reference *after* creating B (as I can in the GUI) this would work, but since the expression has to be set at the time the parameter is created, this is not possible.
Any help would be appreciated ...

Re: Expressions in logic block parameters

Sounds almost like you have a circular reference situation here.  The logic blocks I have created so far for FCA's Event Based Platform avoid these dependent expressions as a rule.  I find when I look at ones I have written that have mutual dependencies I could write them better to eliminate them.

 

I would suggest 3 things.

 

One, try to write expressions that are not mutually dependent instead.

Two, reorder the parameters so that the first ones needed to make the later ones work are processed first.

Three, write some recursive methods that will determine the order in which the expressions need to be created.  This is the most complicated solution.

Re: Expressions in logic block parameters

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi Cliff,

 

We are aware of the debugging issue that you found and will resolve it in the next versions.

 

Best Regards,

DianaG