cancel
Showing results for 
Search instead for 
Did you mean: 

Sensor detecting attribute

Builder
Builder

Hello community

 

I am trying to write a sensor control to sort the Mu's based on their attributes.

A set of Mu's has same attribute name with different values, when a sensor detect their attribute name then have to move to certain destination. for example if attribute name is PP for 5 Mu's then those mu's move to line near to it.

how could i write a program for it?

Could anyone help me please

 

Thank you 

 

 

best regards

11 REPLIES

Re: Sensor detecting attribute

Legend
Legend

inspect PP

When FirstValue then

@.move(Line);

when SecondValue then

@.move(Line1);

end;

Re: Sensor detecting attribute

Builder
Builder

Thank you very much Alessio for you reply.

 

Actually in my model I want to read only Attribute name not it's value. Mu's with same attribute name have single destination.

My main line has 3 sensors and  

i tried to write following program but it's not helping me. 

is
sensorID:integer;
do
if sensorID=1 then
if @.getattribute(PP) then
@.move(line);
end;
elseif sensorID=2 then
if @.getattribute(GA) then
@.move(line1);
end;
elseif sensorID=3 then
if @.getattribute(PF) then
@.move(line2);
end;
end;

 

Could you help me where i am doing errors or is this completely wrong way?

 

Thank you

best regards

Re: Sensor detecting attribute

Siemens Genius Siemens Genius
Siemens Genius

Hello gopi,

 

you can use the getAttrNo function to check if a certain user defined attribute exists. But it probably would be easier to use a certain attribute with different values to determine where a MU should be moved.

Example Code:

is
   AttributeName:string;
do
   AttributeName:="PP";
   if @.getAttrNo(AttributeName)/=0 AND (...) then
        --User defined attribute with the name "PP" exists
       @.move(...);
    end;
end;

Re: Sensor detecting attribute

Builder
Builder

Thank you very much TIM 

 

Sorry for late reply

I tried to use your method but it is not working as i intended. 

Could you tell me how can i use both attribute and it's value to move the MU.

 

previously Alesso suggested one method but i didn't get what is the firstvalue in that method. could you help me if you can

 

thank you very much

 

best regards

Re: Sensor detecting attribute

Legend
Legend

First value was meant to be the actual value of your attribute (integer, string, ...., depending on your needs)

Tim gave you the solution, you need to understand what kind of datatype you need (let's say integer), change the value at some point in simulation and then read the value (you can refer to Tim post).

I suppose you're at the beginning with the sw, I suggest to try creating a small model and then post it here if you will be still in trouble.

Re: Sensor detecting attribute

Siemens Genius Siemens Genius
Siemens Genius

Hi,

note that the suggested algorithm only works for user defined attributes.

for using both the existence of a user defined attribute and it's value, I would suggest the following procedure: 

is
   attributeNo:integer;  --Number of user defined attribute
   attributeValue:any;  --Value of the attribute
   attributeName:string; --Name of the user defined attribute, you want to test
do
   --Reuse this algorithm to go through all of you attributes
attributeName:="PP"; attributeNo:=@.getAttrNo(attributeName); if attributeNo/=0 then --the attribute exists attributeValue:=@.getAttrValue(attributeNo); --Check the attribute Value and determine where to move the MU
inspect attributeValue case "value1" then moved:=@.move(...) --define destination for "..." case "value2" then moved:=@.move(...) else --standard case end; if moved then
--the mu has been moved, no need to go through further attributes return; end;
end; --Check different attributes and combinations / reuse the above procedure for a different AttributeName end;

Here you have to define your "cases" and the "destination". This Method would require you to hard code all of the possible combinations of AttributeNames, AttributeValues and destinations.

The method does have another major problem:

if a MU has more than one of the possible attributes and if the attributes are of different data types, it will crash, because the datatype of "attributeValue" will be determined by the first check attribute.

In conclusion, this will only work if all of the attributes are of the same datatype OR every MU can only have one of the attributes.

For a more sophisticated algorithm you would have to check for the attributeValue in a second method and should use lists/tables with all possible AttributeNames and all possible "values"/"destinations" for every attribute.

I hope this helps you to get an understanding, of how your problem could be handled.

Otherwise, I would go with Alessio's suggestion and advice you to post a small expample of what exactly you are trying to achieve.

Regards,

Tim

Re: Sensor detecting attribute

Builder
Builder

Thank you very much for your valuable time Tim

 

I tried your method for each sensor and it worked perfectly, But when i include a single method for all sensors by mentioning sensorID, it is not working. could you please have a look at attached model.

 

thank you once again

 

Best regards

Re: Sensor detecting attribute

Siemens Genius Siemens Genius
Siemens Genius

Hi,

I'm sorry, but I can't open your (non-commercial) model.

Can you upload a screenshot of your code and/or the debugger with the error message?

Regards,

Tim

Re: Sensor detecting attribute

Builder
Builder

Thank you Tim 

I am trying to write following method, but only problem is sensorID when i put it it's not working.

when i write a method individual methods and put it in sensors  control then it is working. i think only problem is with sensorID.

Please give your suggestions if you can

thank you

 

is
sensorID:integer;
attributeNo:integer;
attributeValue:any;
attributeName:string;
Attributename1:string;
Attributename2:string;
do
if SensorID =1 then
Attributename:= "PP";
attributeNo:=@.getAttrNo(attributeName);
if attributeNo/=0 then
attributeValue:=@.getAttrValue(attributeNo);
inspect attributevalue
when "a" then
@.move(PP_line);
when "b" then
@.move(PP_line);
when "c" then
@.move(PP_line);
when "d" then
@.move(PP_line);
when "e" then
@.move(PP_line);

end;
end;
elseif SensorID =2 then
Attributename1:= "PF";
attributeNo:=@.getAttrNo(attributeName1);
if attributeNo/=0 then
attributeValue:=@.getAttrValue(attributeNo);
inspect attributevalue
when "a" then
@.move(PF_line);
when "b" then
@.move(PF_line);
when "c" then
@.move(PF_line);
when "d" then
@.move(PF_line);
end;
end;
elseif SensorID =3 then
Attributename2:= "GA";
attributeNo:=@.getAttrNo(attributeName2);
if attributeNo/=0 then
attributeValue:=@.getAttrValue(attributeNo);
inspect attributevalue
when "a" then
@.move(GA_line);
when "b" then
@.move(GA_line);
when "c" then
@.move(GA_line);
when "d" then
@.move(GA_line);
when "e" then
@.move(GA_line);
when "f" then
@.move(GA_line);
end;
end;
end;