You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old September 22nd, 2022, 06:18 AM   #1
russg
Member
United Kingdom

russg is offline
 
Join Date: Aug 2012
Location: UK
Posts: 274
How to compare a variant type? - TIA Portal

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
  Reply With Quote
Old September 22nd, 2022, 06:39 AM   #2
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is online now
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: ᚴᚬᛒᛅᚾᚼᚬᚠᚾ
Posts: 15,562
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 ...
__________________
Jesper
NOTICE:
JesperMP can be impolite, has passive-aggressive tendencies and may use sarcasm !
Also: ᛁᚠ ᚢᚬᚢ ᚴᚬᚾ ᚱᛅᚬᛏ ᚦᛁᛋ ᚦᛅᚾ ᚢᚬᚢ ᚼᚬᚠᛅ ᚴᚬᛁᚾᛅᛏ ᛘᚢ ᚱᛅᛋᛒᛅᚴᛏ
  Reply With Quote
Old September 22nd, 2022, 06:52 AM   #3
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is online now
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: ᚴᚬᛒᛅᚾᚼᚬᚠᚾ
Posts: 15,562
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;
__________________
Jesper
NOTICE:
JesperMP can be impolite, has passive-aggressive tendencies and may use sarcasm !
Also: ᛁᚠ ᚢᚬᚢ ᚴᚬᚾ ᚱᛅᚬᛏ ᚦᛁᛋ ᚦᛅᚾ ᚢᚬᚢ ᚼᚬᚠᛅ ᚴᚬᛁᚾᛅᛏ ᛘᚢ ᚱᛅᛋᛒᛅᚴᛏ
  Reply With Quote
Old September 22nd, 2022, 07:41 AM   #4
russg
Member
United Kingdom

russg is offline
 
Join Date: Aug 2012
Location: UK
Posts: 274
Quote:
Originally Posted by JesperMP View Post
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
  Reply With Quote
Old September 22nd, 2022, 07:43 AM   #5
russg
Member
United Kingdom

russg is offline
 
Join Date: Aug 2012
Location: UK
Posts: 274
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;
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
TIA Portal: change tag value ASF LIVE PLC Questions And Answers 3 September 27th, 2016 01:45 PM
Simulate 1200 screen in TIA portal Siemens Step7 dahnuguy LIVE PLC Questions And Answers 26 June 6th, 2016 04:11 PM
WinCC upgrade or TIA Portal? Confused Chris Taylor LIVE PLC Questions And Answers 10 March 14th, 2016 11:25 AM
IO-Link not configurable with TIA Portal V11 for IM 151-8 CPU spandy16 LIVE PLC Questions And Answers 0 January 29th, 2013 08:21 AM
TIA Portal V11 SP2 - Compile / Compare Bug? msozen LIVE PLC Questions And Answers 12 March 27th, 2012 04:32 AM


All times are GMT -4. The time now is 12:56 PM.


.