Have not tried it... What you suggest would be very interesting though.
A way to get what you want would be using an interface that should be implemented in all your function blocks. Then the interface should have a method or variable that would return what you are interested.
Hope this helps.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
INTERFACEItfBaseEXTENDS__System.IQueryInterfaceMETHODmbase : BOOLEND_METHOD/////////////////////////////////////////////////////////////////////INTERFACEItfDerived1EXTENDSItfBaseMETHODmderived1 : BOOLEND_METHOD/////////////////////////////////////////////////////////////////////INTERFACEItfDerived2EXTENDSItfBaseMETHODmderived2 : BOOLEND_METHOD/////////////////////////////////////////////////////////////////////PROGRAMMPOUVAR
 itfderived1 : ItfDerived1;
 itfderived2 : ItfDerived2;
 bTest1, bTest2, xResult1, xResult2: BOOL;END_VARxResult1 :=__QUERYINTERFACE(itfbase, itfderived1); // variablen vom Type ItfBase bzw ItfDerived1xResult2 :=__QUERYINTERFACE(itfbase, itfderived2); // variablen vom Type ItfBase bzw ItfDerived2IF(xResult1=TRUE)THEN
 bTest1 :=itfderived1.mderived1();ELSIFxResult2THEN
 bTest2 :=itfderived2.mderived2();END_IF
QUERYPOINTER ==>
INTERFACEItfEXTENDS__System.IQueryInterface/////////////////////////////////////////////////////////////////////FUNCTION_BLOCKFBVariantIMPLEMENTSITFMETHODm1 : BOOLVAREND_VAR
 m1 :=TRUE;END_METHOD/////////////////////////////////////////////////////////////////////PROGRAMMPOUVAR
 itf1 : Itf;
 insV : FBVariant;
 xResult, xTest : BOOL;
 pVar: POINTERTOFBVariant;END_VARitf1 :=insV;xResult :=__QUERYPOINTER(itf1, pVar);IFxResultTHEN
 xTest :=pVar.m1();END_IF
This is similar to the IsKindOf...
Hope this helps...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As I understand VAR_STAT variables are only visible from within instances of the function block where they are defined. There is only a single instance of a VAR_STAT variable regardless the number of function block instances. It's the same as a class variable except it's only accessible from within a class instance (i.e. function block).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For that I have to do I need a function with two inputs : The instance to test and a model to test with.
The problem comes with the model to test, options that I could find:
option A: Use var_stat variable. But :
It is not possible to acces an var_stat via Classname.varstat.
I have test to access externally an var_stat variable via an undimensioned pointer and It works. (not modifying it only reading it)
Option B: Use as model test __CRC(nameClass). It works.
Option C: As Joan says using QUERYPOINTER.
QUERYINTERFACE has the same mission and works testing if an FB or interface impelments another interface. Is that I need but it works with interfaces and I need that it works with inherited classes.
QUERYPOINTER is the other solution. But in my CODESYS version don't make the test simply makes a cast. Another question is that I have see 2 pdfs with diferent information.
One from Codesys:
Another from Lenze:
Codesys sasy that you have to test the instance explicitly. And Lenze says that you could cast to any kind of pointer and transforms it ????
And in the other hand Joan show me another examble from Beckoff wich explains another thing.
Obviously Joan otions is the better but I have test it and allways returns true.
Time ago I read the Codesys PDF you have just posted.
This is unclear, and too short in explanations. And lead me to error.
QueryPointer in Schneider help: agrees with lenze.
QueryPointer in Beckhoff help: agrees with lenze too.
So Querypointer is to get the pointer to the interface and be able to keep working from there. Interesting but not what you are after...
But... after re-reading the Codesys PDF... It looks like the QueryInterface could be used to do what you are after... here I'm pasting an example of queryinterface from Schneider:
ExampleinST:INTERFACEItfBaseEXTENDS__System.IQueryInterfaceMETHODmbase:BOOLEND_METHODINTERFACEItfDerived1EXTENDSItfBaseMETHODmderived1:BOOLEND_METHODINTERFACEItfDerived2EXTENDSItfBaseMETHODmderived2:BOOLEND_METHODFUNCTION_BLOCKFB1IMPLEMENTSItfDerived1METHODmbase:BOOLÂ Â mbase:=TRUE;END_METHODMETHODmderived1:BOOLÂ Â mderived1:=TRUE;END_METHODEND_FUNCTION_BLOCKFUNCTION_BLOCKFB2IMPLEMENTSItfDerived2METHODmbase:BOOLÂ Â mbase:=FALSE;END_METHODMETHODmderived2:BOOLÂ Â mderived2:=TRUE;END_METHODEND_FUNCTION_BLOCKPROGRAMPOUVARÂ Â inst1:FB1;Â Â inst2:FB2;Â Â itfbase1:ItfBase:=inst1;Â Â itfbase2:ItfBase:=inst2;Â Â itfderived1:ItfDerived1:=0;Â Â itfderived2:ItfDerived2:=0;Â Â bTest1,bTest2,xResult1,xResult2:BOOL;END_VARxResult1:=__QUERYINTERFACE(itfbase1,itfderived1);//xResult=TRUE,itfderived1<>0Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â //referencestheinstanceinst1xResult2:=__QUERYINTERFACE(itfbase1,itfderived2);//xResult=FALSE,itfderived2=0xResult3:=__QUERYINTERFACE(itfbase2,itfderived1);//xResult=FALSE,itfderived1=0xResult4:=__QUERYINTERFACE(itfbase2,itfderived2);//xResult=TRUE,itfderived2<>0Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â //referencestheinstanceinst2
See at the end when do the __QeryInterface calls fail and when it succeeds... it looks like that it transforms only if the types are equal.
Hope this helps Josep (and sorry for the initial mistake).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dears.
I have test to access a var_stat variable using class name as the path to the variable:
ClassName.variable
But the compiler tell me that the class had to be instantiated.
It is possible in Java.
I am doing something wrong?
Will it be possible in future?
It would help me to implement an instanceof function.
Lo has probado?
Enviado desde mi SM-G930F mediante Tapatalk
Have not tried it... What you suggest would be very interesting though.
A way to get what you want would be using an interface that should be implemented in all your function blocks. Then the interface should have a method or variable that would return what you are interested.
Hope this helps.
All my classes have an string attribute with the class name
Nowadays i made the class text comparing string:
Isinstanceof(pointer,'class_name')
But i dont like it. If i put an wrong string... It will return false.
If i could pass something related with the class :
Classname.var
I will have not error strings
Hi again Josep M,
Wouldn't this help you?
Both are examples from the SoMachine help system:
QUERYINTERFACE ==>
QUERYPOINTER ==>
This is similar to the IsKindOf...
Hope this helps...
Joan
I am sorry, i have read dozens of times querypointer and i cannot find its sense.
One posible solution that I found is use __crc. It accepts this, super and class definition.
I could save crc of an instance on fb init in an internal variable
Mycrc=__crc(this)
Instanceof(pobj:=object,crcclass:=__crc(class))
If (pobj.mycrc=crcclass)return true
If I've not misunderstood your post with the Iskindof...
You are getting exactly that:
You have a function block instance: FBI.
You have an interface itf.
You have a pointer to check if it's of the same kind than FBI.
You are getting true if the pointer is of the same kind than FBI.
Am I wrong?
PS: that is pseudo - code at best, I've not tested it.
If this works, you could put it into a method in all your fb's and then:
Hope this helps.
Joseph,
As I understand VAR_STAT variables are only visible from within instances of the function block where they are defined. There is only a single instance of a VAR_STAT variable regardless the number of function block instances. It's the same as a class variable except it's only accessible from within a class instance (i.e. function block).
Dears:
For that I have to do I need a function with two inputs : The instance to test and a model to test with.
The problem comes with the model to test, options that I could find:
option A: Use var_stat variable. But :
It is not possible to acces an var_stat via Classname.varstat.
I have test to access externally an var_stat variable via an undimensioned pointer and It works. (not modifying it only reading it)
Option B: Use as model test __CRC(nameClass). It works.
Option C: As Joan says using QUERYPOINTER.
QUERYINTERFACE has the same mission and works testing if an FB or interface impelments another interface. Is that I need but it works with interfaces and I need that it works with inherited classes.
QUERYPOINTER is the other solution. But in my CODESYS version don't make the test simply makes a cast. Another question is that I have see 2 pdfs with diferent information.
One from Codesys:
Another from Lenze:
Codesys sasy that you have to test the instance explicitly. And Lenze says that you could cast to any kind of pointer and transforms it ????
And in the other hand Joan show me another examble from Beckoff wich explains another thing.
Obviously Joan otions is the better but I have test it and allways returns true.
PLC Designer__PLC Designer (R3 1)__v4 1__EN.pdf [31.91 KiB]
OOP_in_CODESYS_3_en.pdf [155.54 KiB]
OOP_in_CODESYS_3_en.pdf [155.54 KiB]
PLC Designer__PLC Designer (R3 1)__v4 1__EN.pdf [31.91 KiB]
Hi Josep,
Time ago I read the Codesys PDF you have just posted.
This is unclear, and too short in explanations. And lead me to error.
QueryPointer in Schneider help: agrees with lenze.
QueryPointer in Beckhoff help: agrees with lenze too.
So Querypointer is to get the pointer to the interface and be able to keep working from there. Interesting but not what you are after...
But... after re-reading the Codesys PDF... It looks like the QueryInterface could be used to do what you are after... here I'm pasting an example of queryinterface from Schneider:
See at the end when do the __QeryInterface calls fail and when it succeeds... it looks like that it transforms only if the types are equal.
Hope this helps Josep (and sorry for the initial mistake).