I have initiated a function block several times and want to loop through to check for a variable.
VARCONSTANT
  numOfGensets    : BYTE :=2;END_VARVAR
  gen1, gen2    : fbGenset;
  gensets      : ARRAY[1..numOfGensets] OFfbGenset := [gen1, gen2];END_VAR;
.... Mainprog....
gen1();gen2();//LoopthroughallinitiatedgensetsFORi :=1TOnumOfGensetsDO
  IFgensets[i].breakerStatus()=BREAKER_STATUS.TRIPPEDTHEN
    tripped :=TRUE;
  END_IFEND_FOR
METHODbreakerStatus : BREAKER_STATUS//Checkstatusofcircuitbreaker/generatorbreakerIFclosedTHEN
  breakerStatus :=BREAKER_STATUS.CLOSED; // ClosedELSIFNOTclosedTHEN
  breakerStatus :=BREAKER_STATUS.OPEN; // OpenELSIFtrippedTHEN
  breakerStatus :=BREAKER_STATUS.TRIPPED; // TrippedEND_IF
This dosent work as desired as gen1 and gen2 isnt updated cyclically in the array.
How should this be done the proper way without having to update the array every scan?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-03-16
Originally created by: Viacheslav Mezentsev
programPLC_PRGvarconstant Â
  numOfGensets: byte :=2;end_varvar
  i: byte;
  gen1, gen2: ton;
  gensets: array [ 1 .. numOfGensets ] ofpointertoton := [ adr(gen1), adr(gen2) ];  end_var//------------------gen1(pt :=t#10s);gen2(pt :=t#20s);//Loopthroughallinitiatedgensetsfori :=1TOnumOfGensetsdo
 Â
  ifgensets[i]^.pt=t#10sthengensets[i]^.pt :=t#55s; end_if
 Â
end_for
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Zitat:
Is it possible to have a variable shared between declared instances, not beeing in a GVL?
It is possible, but why you need this? (you can use var_stat... end_var in FB_A)
function_blockFB_Avar_input
  value: int :=0;  end_varvar_stat
  m_index: int :=0;
  m_instances: array [ 0 .. 1000 ] ofpointertoFB_A;end_var-----------------------methodpublicFB_Init : boolvar_input
  bInitRetains : bool; // initializing of retain-variable
  bInCopyCode : bool; // instance is copied to copy-codeend_varm_instances[ m_index ] :=this;m_index :=m_index+1;-----------------------methodGetInstAt : pointertoFB_Avar_input
  index: int;end_varGetInstAt :=m_instances[ index ];-----------------------function_blockFB_BextendsFB_A-----------------------programPLC_PRGvar
  bFirstCycle: bool :=true;
  f1: FB_A;
  f2, f3, f4: FB_B;
  p: pointertoFB_A;end_varifbFirstCyclethen
  f1.value :=1;
  f2.value :=2;
  f3.value :=3;
  p :=f1.GetInstAt(3);
  ifp<>0thenp^.value :=4; end_if // Check f4.value online
  bFirstCycle :=false;
 Â
end_if
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Reason behind the looping is to monitor the state of a variable in FB_A (aswell as FB_B which extends FB_A). Normally I'd do this as proposed by you in a earlier post, but this dosent work when I also need to include both FB_B and FB_A.
Reasons behind shared variable is because I want a interlock between declared instances. Say FB_A has a method for controlling something external (relay for example) and if any of FB_A (aswell as FB_B which extends FB_A) has this output active none of the others shouldnt be able to actuate the external output.
Maybe you have a better solution to this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-04-04
Originally created by: Viacheslav Mezentsev
There is a library with synchronization elements: with BOLT and SEMA. To use them you need to know more precisely what you want.
Interlocking - what does this mean in your opinion? How should this work? Other fbs must wait or do nothing or return error state?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Each FB has a variable to start a sequence (action), if any of the FBs has say "BREAKER_STATUS.CLOSED" active (from first post), then the others should not be able to activate the closing sequence.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello
I have initiated a function block several times and want to loop through to check for a variable.
This dosent work as desired as gen1 and gen2 isnt updated cyclically in the array.
How should this be done the proper way without having to update the array every scan?
Originally created by: Viacheslav Mezentsev
Brilliant, thanks!
New but similar question.
Assume two FBs where FB_B extends FB_A.
Lets say I have declared some instances of FB_B and a few of FB_A.
How can I loop through all of the declared instances of both FB_B and FB_A to do something thats declared in FB_A?
Question 2:
Is it possible to have a variable shared between declared instances, not beeing in a GVL?
Originally created by: Viacheslav Mezentsev
Online help.
It is possible, but why you need this? (you can use var_stat... end_var in FB_A)
Hmm. Ok. Not sure how to do that.
Reason behind the looping is to monitor the state of a variable in FB_A (aswell as FB_B which extends FB_A). Normally I'd do this as proposed by you in a earlier post, but this dosent work when I also need to include both FB_B and FB_A.
Reasons behind shared variable is because I want a interlock between declared instances. Say FB_A has a method for controlling something external (relay for example) and if any of FB_A (aswell as FB_B which extends FB_A) has this output active none of the others shouldnt be able to actuate the external output.
Maybe you have a better solution to this?
Originally created by: Viacheslav Mezentsev
There is a library with synchronization elements: with BOLT and SEMA. To use them you need to know more precisely what you want.
Interlocking - what does this mean in your opinion? How should this work? Other fbs must wait or do nothing or return error state?
Each FB has a variable to start a sequence (action), if any of the FBs has say "BREAKER_STATUS.CLOSED" active (from first post), then the others should not be able to activate the closing sequence.
Any more tips?