How to compare a variant type? - TIA Portal

russg

Member
Join Date
Aug 2012
Location
UK
Posts
275
Hi,

I'm just trying to work out how to compare a variant type.

The variant input parameter needs to be compared with a min and max limit. If it is below or above it, it then needs to make it equal the limit.

The parameter could be a REAL, INT, DINT, etc. So I want a block that can read the parameter and two limits as variants and then output the parameter.

I've managed to do the move block variant, but struggling to work out how to do the compare.

IF TypeOf(#Parameter) = TypeOf(#MaxLimit) AND TypeOf(#Parameter) = TypeOf(#MinLimit) THEN
#RT := MOVE_BLK_VARIANT(SRC := #Parameter, COUNT := 1, SRC_INDEX := 0, DEST_INDEX := 0, DEST => #tempInParameter);
#RT := MOVE_BLK_VARIANT(SRC := #MinLimit, COUNT := 1, SRC_INDEX := 0, DEST_INDEX := 0, DEST => #tempInMinLimit);
#RT := MOVE_BLK_VARIANT(SRC := #MaxLimit, COUNT := 1, SRC_INDEX := 0, DEST_INDEX := 0, DEST => #tempInMaxLimit);
#Type := 0;
ELSE
#Type := 1;
END_IF;


Any ideas?

Thanks
 
I think you are on the right path.

I would not check #Parameter twice. Instead I would check if #MaxLimit and #MinLimit are the same type. If they are not it cannot work and exit the function with an error code.

If input parameters are basic data types, you can also write
IF TypeOf(#Parameter) = REAL THEN ...
 
I think I would do it like this:

Code:
IF TypeOf(#Parameter) = REAL AND TypeOf(#MinLimit) = REAL AND TypeOf(#MAxLimit) = REAL THEN 
... // do REAL instructions
ELSE_IF TypeOf(#Parameter) = INT AND TypeOf(#MinLimit) = INT AND TypeOf(#MAxLimit) = INT THEN 
... // do INT instructions
ELSE_IF TypeOf(#Parameter) = DINT AND TypeOf(#MinLimit) = DINT AND TypeOf(#MAxLimit) = DINT THEN 
... // do DINT instructions
ELSE
.. // error, parameters are not same type

END_IF;
 
I think I would do it like this:

Code:
IF TypeOf(#Parameter) = REAL AND TypeOf(#MinLimit) = REAL AND TypeOf(#MAxLimit) = REAL THEN 
... // do REAL instructions
ELSE_IF TypeOf(#Parameter) = INT AND TypeOf(#MinLimit) = INT AND TypeOf(#MAxLimit) = INT THEN 
... // do INT instructions
ELSE_IF TypeOf(#Parameter) = DINT AND TypeOf(#MinLimit) = DINT AND TypeOf(#MAxLimit) = DINT THEN 
... // do DINT instructions
ELSE
.. // error, parameters are not same type

END_IF;

Thank you Jesper.

I already got there with your first reply.

I've started creating this kind of code for each type and then doing a basic compare and move in the next network:

IF #TypeMatch = 1 AND TypeOf(#Parameter) = Int THEN
#RT := MOVE_BLK_VARIANT(SRC := #Parameter, COUNT := 1, SRC_INDEX := 0, DEST_INDEX := 0, DEST => #tempInParameter_INT);
#RT := MOVE_BLK_VARIANT(SRC := #MinLimit, COUNT := 1, SRC_INDEX := 0, DEST_INDEX := 0, DEST => #tempMinLimit_INT);
#RT := MOVE_BLK_VARIANT(SRC := #MaxLimit, COUNT := 1, SRC_INDEX := 0, DEST_INDEX := 0, DEST => #tempMaxLimit_INT);
#Type := 1;
END_IF;

Thanks again
 
I then output back to the variant parameter:

IF #TypeMatch = 1 AND #Type = 1 THEN
#RT := MOVE_BLK_VARIANT(SRC := #tempInParameter_INT, COUNT := 1, SRC_INDEX := 0, DEST_INDEX := 0, DEST => #Parameter);
END_IF;
 

Similar Topics

Help please. Im new to Omron and have a machine down. I have a compare = for barcode label scan. I've attached two pics. On the Mnemonics you can...
Replies
4
Views
599
Hi everyone! Accidentally closed it and it wont appear again. Checked and unchecked the option and seem to make no difference. Running v7.10.00...
Replies
16
Views
1,813
I'm working on an array that contains a UDT of 5 Items Array[4] DataType[0] - Part 1 - Part 2 - Part 3 - Part 4...
Replies
1
Views
813
Hi. I have 2 files where I would like to see the ladder logic differences (similar to the Rockwell compare function). I am using TISoft Siemens...
Replies
1
Views
1,228
Hello experts, I am just starting with AB programing, I have a questions regarding a compare done in an old RSlogix500 and causing me issues when...
Replies
5
Views
1,913
Back
Top Bottom