WinCC OA tutorial. Part 9. Control script. Not fast, but right. Full ui launch

In the process of creating the valve behavior model, we created (and modified it in the last part) a Model script, in which there were several dpConnect calls and several callback functions. Then I wrote that this is a "fast but wrong way." This pause was necessary to get familiar with the dpQuery function. I propose to go back a little and implement the model slowly and  very boringly  correctly, now using functions of the dpQueryConnect family. Let's open our script Model.





// $License: NOLICENSE
//--------------------------------------------------------------------------------
/**
  @file $relPath
  @copyright $copyright
  @author akcou
*/

//--------------------------------------------------------------------------------
// Libraries used (#uses)

//--------------------------------------------------------------------------------
// Variables and Constants

//--------------------------------------------------------------------------------
/**
*/
main()
{
  dpConnect("OnOpen_CB1", "System1:Flap1.Commands.Open");
  dpConnect("OnOpen_CB2", "System1:Flap2.Commands.Open");
  dpConnect("OnOpen_CB3", "System1:Flap3.Commands.Open");

  for (;;) {
    dpSet("System1:Flap1.Inputs.Flow", rand());
    dpSet("System1:Flap2.Inputs.Flow", rand());
    delay(1);
  }
}

void OnOpen_CB1(string dp1, bool bNewValue)
{
  if (bNewValue)  {
    dpSet("System1:Flap1.Inputs.Position", 90);
  } else {
    dpSet("System1:Flap1.Inputs.Position", 0);
  }
}

void OnOpen_CB2(string dp1, bool bNewValue)
{
  if (bNewValue)  {
    dpSet("System1:Flap2.Inputs.Position", 90);
  } else {
    dpSet("System1:Flap2.Inputs.Position", 0);
  }
}

void OnOpen_CB3(string dp1, bool bNewValue)
{
  if (bNewValue)  {
    dpSet("System1:Flap3.Inputs.Position", 90);
  } else {
    dpSet("System1:Flap3.Inputs.Position", 0);
  }
}

      
      



dpConnect DPE, . dpQueryConnect . , SQL-. , SQL-, : Flap1, Flap2 Flap3. — dpQueryConnectSingle dpQueryConnectAll. - . , . , , DPE . «» , .





, WinCC OA , — , . , , dpQueryConnectSingle . . , Flap4. Flap4 , . , . « ». , , . «», ( Flap1, Flap2, Flap3), ( 4 ). .





«» . SQL-query .





Model main





main()
{
  dpQueryConnectSingle("OnOpenAll_CB",FALSE, "", "SELECT '_original.._value' FROM 'Flap*.Commands.Open'");

  //dpConnect("OnOpen_CB1", "System1:Flap1.Commands.Open");
  //dpConnect("OnOpen_CB2", "System1:Flap2.Commands.Open");
  //dpConnect("OnOpen_CB3", "System1:Flap3.Commands.Open");

  for (;;) {
    dpSet("System1:Flap1.Inputs.Flow", rand());
    dpSet("System1:Flap2.Inputs.Flow", rand());
    delay(1);
  }
}

      
      



dpConnect . dpQueryConnectSingle. OnOpenAll_CB.





. callback- . , , SQL-. , , , , -, , .





— . FlapX, X — . , Position FlapX. , «» . — .





sDPE — , System1:Flap2.Commands.Open





bNewValue — , true false





split — DPE , , , System1:Flap2





« » , , .





OnOpenAll_CB(string s, dyn_dyn_anytype ddaTab)
{ //ddaTab contains DPE and the changed value
  int z; // 
  string sDPE; //  ,   
  dyn_string split; //  DPE
  bool bNewValue; //  
  for(z=2;z<=dynlen(ddaTab);z++) //  ,    -   
  {
    sDPE = ddaTab[z][1]; // DPE,     -  DPE ,  System1:FlapX.Commands.Open
    bNewValue = ddaTab[z][2]; //  ,   
    split = strsplit(sDPE, "."); //  DPE   ,    ,  System1:FlapX
    //DebugN("AGK", sDPE, bNewValue);
    //DebugN("AGK", split);
    if (bNewValue)  { //  ""
      dpSet(split[1] + ".Inputs.Position", 90); //  Position  90 
    } else {
      dpSet(split[1] + ".Inputs.Position", 0); //   
    }
  }
}

      
      



, , Main , .





, . Main QuickTest , . , . ui-.





User Interface. 2 (-num 2), ui — , . , «-p Main.pnl» — , . (always). ui.












All Articles