cancel
Showing results for 
Search instead for 
Did you mean: 

Referencing an Object attribute for a waituntil statement

Genius
Genius

Hi,

 

I am trying to use a waituntil statement based on the changing of an object's user-defined attribute (of type boolean). I know this is possible if you do something like this:

 

waituntil ?.wait_for_clear = true

 

However, I am writing a method where I have to lookup what the name of the attribute is in a table first. Here is my code:

PLC_Bits.setCursor(0,0)
if PLC_Bits.find({"PS Object.Sensor",*},?.name+".sensor_"+SensorID)
    row := PLC_Bits.CursorY
    var Att : string := PLC_Bits["PS Obj Attribute", row]	--get attribute name
end

if ?.getAttribute(Att) = false
    waituntil ?.getAttribute(Att) = true
end

I know that I can't do this because <path>.getAttribute() is a method, and I know you can't use methods in a waituntil statement. But I can't think of how to do this. I need something like a c++ pointer to reference to the user-defined attribute. I've tried setting the attribute to a variable of type object because that type seems to work like a pointer, but this did not work.

 

Has anyone worked with something like this before. Any ideas?

 

Thank you!

7 REPLIES

Re: Referencing an Object attribute for a waituntil statement

Genius
Genius

This seems to be a work around, but I know it is not good practice because it keeps the method awake and burns resources:

 

repeat
       wait 0.5
until ?.getAttribute(Att) = true

Re: Referencing an Object attribute for a waituntil statement

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Hi EMM,

 

What springs to my mind is that you can create and execute source code in a dynamic way. The command is called execute and takes a string with your source code as an argument. It is a bit tricky, but it could work.

 

Here is an (untested) example:

 

var MyCode: string
var MyResult: boolean

MyCode:="->boolean return SingleProc.Occupied"
MyResult:=execute(MyCode)

Yet, at the same time, I wonder if you couldn't simply use an event-based principle. A TableFile comes with an attribute called Changed. You can observe it and trigger a method when information in the table has changed. It needs to be reset to false manually. But it allows you to scan the table and attributes in a more efficient manner.

 


Gert Nomden
Senior Consultant | Tecnomatix Product Manager
cardsplmsolutions.com

Re: Referencing an Object attribute for a waituntil statement

Genius
Genius

Hi Nomden,

 

Thank you for the ideas. I'm not sure how I could implement the execulte method in place of a waituntil. I need a value that I can observe. Using the execute method would just return the value at that given moment. If I'm missing something, please explain.

 

Your idea to observe a value in the table could work. I didn't know I could observe table cell values. I'd have to change how I've designed the model to do it though. The reason why I built out user-defined attributes was because I knew those could be observed... but it looks like I can't do this dynamically.  That might be a better solution.

 

It just seems like there should be a way to reference this attribute for the waituntil statement. Doesn't it? I'm more interested in this possibility at this point because to switch to observing the table value would mean a lot of rework.

 

Thanks again.

Re: Referencing an Object attribute for a waituntil statement

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom
You cannot observe individual cells, the Changed attribute only indicates if there was any change to the table.

But Simtalk also offers the byref option, it can do what you ask for.




Verzonden vanaf mijn Samsung-apparaat

Gert Nomden
Senior Consultant | Tecnomatix Product Manager
cardsplmsolutions.com

Re: Referencing an Object attribute for a waituntil statement

Siemens Phenom Siemens Phenom
Siemens Phenom

I would advise to use the solution using the execute statement.

The code would look like this:

var Att : string := PLC_Bits["PS Obj Attribute", row]	--get attribute name
execute("param o:object"+chr(10)+"waituntil o."+Att, ?)

Re: Referencing an Object attribute for a waituntil statement

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom
Hi Michael,

If the waituntil in the execute-statement also suspends the main method, this should work.

Gert Nomden
Senior Consultant | Tecnomatix Product Manager
cardsplmsolutions.com

Re: Referencing an Object attribute for a waituntil statement

Genius
Genius

Ah! Now I see! How cool is that?! Works like a charm! Thank you!