V 10
1
LANG:1 8 (NoName)
PANEL,407 193 1000 806 N "_3DFace" 0
"/* State Control Functions
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
/*===================================-======================================*/
/*                          SYSTEM STATE CONTROL                            */
/*-----------------------------------=--------------------------------------*/
/* AUTHORs:        S.G.Basiladze

   DESIGN ISSUEs:  This Script provides the Local and Global Control of the
                   System States functons and Transition functions

   MODIF_HISTORY:  01.03.2001 - first version
                   09.11.2002 -  2-nd version, DAQ Control is added
                   07.05.2003 -  3-rd version, DDC Control is added
                   04.07.2003 -  4-th version, for MoPS subsystem
/*--------------------------------------------------------------------------*/
/* SYSTEM CONTROL DATAPOINTS:
                   Host.Stat  - Desirable   (new) system state;
                   Syst.Stat  - Current (and old) system state;
                   Next.Stat  - Next step in the Syst->->->Host sequence;
                   Busy.Stat  - synchronisation, is using in 2 cases
                                a) for disabling of Transition function
                                   (for instance, if Syst_Off->->Host_Stb,
                                   then Next_ConfFunction will be skipped);                                   
                                b) for waiting when Transition will be made.*/
/* The *.Stat DataPoints bits assignment:

        DCS Mode : 0x1* - Global Control (\"on write\" - from DAQ),
                   0x2* - Local  Control (\"on event\" - control button click).

        DCS State: 0x20 – Off,          MPS State: 0x10 – Off,
                   0x24 – Configured,              0x14 - reserve (Config),
                   0x28 – reserve (Stb),           0x18 – Standby,
                   0x*C – Monitoring.              0x1C – On.

      Status bits:   00 - Normal        Colours  : Green[Local] or Cyan[Glob]
                     10 - Warning                  Yellow
                     01 - Alarm                    Red
                     11 - reserved (Disabled)      Gray
  ===================================-======================================*/

main()
{ delay(2);
  dpConnect(\"StateFunction\"     ,\"SCTmops1:Host.Stat:_original.._value\");
  dpConnect(\"ConfOffTransition\" ,\"SCTmops1:Next.Stat:_original.._value\");
  dpConnect(\"OffConfTransition\" ,\"SCTmops1:Next.Stat:_original.._value\");
  dpConnect(\"ConfStbTransition\" ,\"SCTmops1:Next.Stat:_original.._value\");
  dpConnect(\"StbOnTransition\"   ,\"SCTmops1:Next.Stat:_original.._value\");
  dpConnect(\"OnStbTransition\"   ,\"SCTmops1:Next.Stat:_original.._value\");
}

 StateFunction(string Dapo, int Stat) 
 { int    stat, mode;
   string estr, mstr;                /* Error and Monitor STRings           */
   
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
   mode = stat & 0x30;
/*
   sprintf(mstr,\" MakeState: Mode=%Xh, Stat=%Xh \", mode, stat & 0xC);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2); /* Debug */
     if((mode!=0x10) && (mode!=0x20))/* Global (write) or Local (event) mode*/
   { sprintf(estr,\" incorrect Control Mode code = %Xh \", mode);
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
   } else
   {   switch(stat & 0xC)
     { case   0x0: OffFunction();       break;
       case   0x4: ConfigFunction();    break;
       case   0x8: StandbyFunction();   break;
       case   0xC: OnFunction();        break;
       default   :
               sprintf(estr,\" incorrect Control State code = %X\", stat & 0xC);
               dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
               dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     } delay(2);
     dpSet(\"SCTmops1:Busy.Numb:_original.._value\", 1);
   }
/*
   sprintf(mstr,\" StateMade: Mode=%Xh, Stat=%Xh \", mode, stat & 0xC);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2); /* Debug */
 }

 ConfOffTransition(string Dapo, int Stat)
 { int    syss, next, stat, busy;
   string mstr;

/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" ConfOff: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                           stat, next, syss, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);            /* Debug */
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     if(((syss & 0xC) == 0x4) && ((next & 0xC) == 0x0) && (!busy))
   { dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x8);
   
//   ...                             /* Make your Config->Off job here      */
     MakeConfigs(0x4, 0x0);          /* Load DaPo_Off                       */
//   ...                             /* Make your Config->Off job here      */
/*
     delay(200);                                                   /* Debug */
     dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
   }
 }

 OffFunction()
 { int    syss, stat, stus, busy;    /* SYStem STATe, STatUS, BUSY Stat     */
   int    tout, eror, errn;          /* TimeOUT (sec), system ERrOR & Number*/
   int    int1, int2;
   string snam, estr, mstr, stri;    /* Syst NAMe, Error and Monitor STRings*/
 
   tout = 180;
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", stat);
/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", int1);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", stus);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" MakeOff: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                           int1, stus, stat, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2); /* Debug */
   syss = stat & 0xC;                   stus = stat & 0x33;  stat = 0x0;
     switch(syss)
   { case 0xC:                       /* Current State is 'On'               */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x8 | stus);
              delay(1);
              busy=1; while((busy > 0) && (tout > 0))
              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
                delay(1); tout--;
              } if(tout <= 0)
              { sprintf(estr,\" TimeOut Waiting for Standby State\"); 
                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
              }
              syss = 0x8 | stus;     /* Intermediate State is 'Standby'     */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
              delay(1);
     case 0x8:                       /* Current State is 'Standby'          */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x4 | stus);
              delay(1);
              busy=1; while((busy > 0) && (tout > 0))
              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
                delay(1); tout--;
              } if(tout <= 0)
              { sprintf(estr,\" TimeOut Waiting for Config State\"); 
                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
              }
              syss = 0x4 | stus;     /* Intermediate State is 'Config'      */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
              delay(1);
     case 0x4:                       /* Current State is 'Config'           */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x0 | stus);
              delay(1);
              busy=1; while((busy > 0) && (tout > 0))
              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
                delay(1); tout--;
              } if(tout <= 0)
              { sprintf(estr,\" TimeOut Waiting for Off State\"); 
                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
              }
              syss = 0x0 | stus;
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", stus);
     case 0x0: ;                     /* Current State is 'Off'              */
     default : ;
   }
   dpGet(\"SCTmops1:Eror.Stat:_original.._value\", eror);
     if((eror & 0x1) > 0)
   { dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2); /* Yellow Colour   */
     sprintf(mstr,\" CHECK ERROR AND PUSH EXIT [X] BUTTON\");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   } else
   {
/*
     dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
     dpGet(\"SCTmops1:Next.Stat:_original.._value\", stus);
     dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
     dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     sprintf(mstr,\" OffMade: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                             stat, stus, syss, busy);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(2);/* Debug */
     dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
     dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
     dpGet(\"SCTmops1:Busy.Numb:_original.._value\", int1);
       if(((stat & 0xC) == 0) && ((syss & 0xC) == 0) && (int1 > 0))
     {
//   ...                             /* Make your stop Off job here         */
       Send_Loaded();
//   ...                             /* Make your stop Off job here         */
       dpSet(\"SCTmops1:Moni.Stat:_original.._value\",0x2);/* Yellow colour   */
       sprintf(mstr,\" BY...!\");
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2);
       PanelOff();
     } else
     { dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x4);
       MakeConfigs(0x4, 0x4);        /* Load DaPo_Off & create OPC confFile */
       sprintf(mstr,\" DPs ARE 'OFF'_LOADED, OPC configFILE CREATED... \");
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2);
//   ...                             /* Make your start Off job here        */
       Send_Loaded();
//   ...                             /* Make your start Off job here        */
       int1=0; while(int1 < 9)
       { stri = getSystemName(int1);
         int2 = strlen(stri); if(int2 > 0)
         { sprintf(snam,\"%s\", stri);
           strreplace(snam,\":\",\"\");  break;
         } int1++;
       }
       sprintf(mstr,\" %s IS WAITING...\", snam);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(1);
       dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
     }
   }
 }
 
 OffConfTransition(string Dapo, int Stat)
 { int    syss, next, stat, busy;
   string mstr;

/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" OffConf: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                           stat, next, syss, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);            /* Debug */
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     if(((syss & 0xC) == 0x0) && ((next & 0xC) == 0x4) && (!busy))
   { dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x8);

//   ...                             /* Make your Off->Config job here      */
     MakeConfigs(0x8, 0x8);          /* Create OPC-configs                  */
//   ...                             /* Make your Off->Config job here      */
/*
     delay(70);                                                    /* Debug */
     dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
   }
 }

 ConfigFunction()
 { int    syss, stat, stus, busy;    /* SYStem STATe, STatUS, BUSY Stat     */
   int    tout, eror, errn;          /* TimeOUT (sec), system ERrOR & Number*/
   int    int1, int2;
   string snam, estr, mstr, stri;    /* Syst NAMe, Error and Monitor STRings*/

   tout = 300;  
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", stat);
/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", int1);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", stus);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" MakeConf: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                            int1, stus, stat, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2); /* Debug */
   syss = stat & 0xC;                   stus = stat & 0x33;  stat = 0x0;
     switch(syss)
   { case 0x0:                       /* Current State is 'Off'              */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x4 | stus);
              delay(1); 
              busy=1; while((busy > 0) && (tout > 0))
              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
                delay(1); tout--;
              } if(tout <= 0)
              { sprintf(estr,\" TimeOut Waiting for Config State\"); 
                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
              }
              syss = 0x4 | stus;     /* New State is 'Config'               */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
              break;
     case 0xC:                       /* Current State is 'Config'           */
                                     /* Disable condition for TransiFunction*/
              dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x4);
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x8 | stus);
              delay(1);
//              busy=1; while((busy > 0) && (tout > 0))
//              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
//                delay(1); tout--;
//              } if(tout <= 0)
//              { sprintf(estr,\" TimeOut Waiting for Standby State\"); 
//                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
//                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//              }
              syss = 0x8 | stus;     /* New State is 'Standby'              */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
              delay(1);
      case 0x8:                      /* Current State is 'Standby'          */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x4 | stus);
              delay(1);
//              busy=1; while((busy > 0) && (tout > 0))
//              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
//                delay(1); tout--;
//              } if(tout <= 0)
//              { sprintf(estr,\" TimeOut Waiting for Config State\"); 
//                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
//                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//              }
              syss = 0x4 | stus;     /* Intermediate State is 'Config'      */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
                                     /* Enable condition for TransiFunction */
              dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
              delay(1);
     case 0x4: ;                     /* ConfigState from maybe from Off only*/
//              break;
     default : sprintf(estr,\" State for 'Config' is NOT from 'Off'\"); 
               dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
               dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x2);
   }
   dpGet(\"SCTmops1:Eror.Stat:_original.._value\", eror);
     if((eror & 0x1) > 0)
   { dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2); /* Yellow Colour   */
     sprintf(mstr,\" CHECK ERROR AND PUSH EXIT [X] BUTTON\");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   } else
   { ;
//   ...                             /* Make your 'Config' job here         */
     sprintf(mstr,\" DPs ARE CONFIGURED FOR OPC SERVER... \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2);
     int1=0; while(int1 < 9)
     { stri = getSystemName(int1);
       int2 = strlen(stri); if(int2 > 0)
       { sprintf(snam,\"%s\", stri);
         strreplace(snam,\":\",\"\");  break;
       } int1++;
     }
     sprintf(mstr,\" %s IS WAITING...\", snam);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(1);
/*
     dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
     dpGet(\"SCTmops1:Next.Stat:_original.._value\", stus);
     dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
     dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     sprintf(mstr,\" ConfMade: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                              stat, stus, syss, busy);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(2);/* Debug */
   }
 }
 
 ConfStbTransition(string Dapo, int Stat)
 { int    syss, next, stat, busy;
   string mstr;

/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" ConfStb: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                           stat, next, syss, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);            /* Debug */
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     if(((syss & 0xC) == 0x4) && ((next & 0xC) == 0x8) && (!busy))
   { dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x8);
   
//   ...                             /* Make your Off->Config job here      */
     MakeConfigs(0x8, 0xC);          /* Load DaPo_Stb from 'Para' confFile  */
//   ...                             /* Make your Off->Config job here      */
/*
     delay(70);                                                    /* Debug */
     dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
   }
 }

 StandbyFunction()
 { int    syss, stat, stus, busy;    /* SYStem STATe, STatUS, BUSY Stat     */
   int    tout, eror, errn;          /* TimeOUT (sec), system ERrOR & Number*/
   int    int1, int2;
   string snam, estr, mstr, stri;    /* Syst NAMe, Error and Monitor STRings*/

   tout = 180;
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", stat);
/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", int1);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", stus);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" MakeStb: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                           int1, stus, stat, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2); /* Debug */
   syss = stat & 0xC;                   stus = stat & 0x33;  stat = 0x0;
     switch(syss)
   { case 0x0:                       /* Current State is 'Off'              */
                                     /* Disable condition for TransiFunction*/
              dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x4);
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x4 | stus);
              delay(1);
//              busy=1; while((busy > 0) && (tout > 0))
//              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
//                delay(1); tout--;
//              } if(tout <= 0)
//              { sprintf(estr,\" TimeOut Waiting for Config State\"); 
//                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
//                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//              }
              syss = 0x4 | stus;     /* Intermediate State is 'Config'      */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
                                     /* Enable condition for TransiFunction */
              dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x8 | stus);
              delay(1);
              busy=1; while((busy > 0) && (tout > 0))
              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
                delay(1); tout--;
              } if(tout <= 0)
              { sprintf(estr,\" TimeOut Waiting for Standby State\"); 
                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
              }
              syss = 0x8 | stus;     /* New State is 'Standby'              */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
              break;
     case 0x4:                       /* Current State is \"Local Config\"     */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x8 | stus);
              delay(1);
              busy=1; while((busy > 0) && (tout > 0))
              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
                delay(1); tout--;
              } if(tout <= 0)
              { sprintf(estr,\" TimeOut Waiting for Standby State\"); 
                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
              }
              syss = 0x8 | stus;     /* New State is 'Standby'              */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
              break;
     case 0x8: ;                     /* Current State is 'Standby'          */
              break;
     case 0xC:                       /* Current State is 'On'               */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x8 | stus);
              delay(1);
              busy=1; while((busy > 0) && (tout > 0))
              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
                delay(1); tout--;
              } if(tout <= 0)
              { sprintf(estr,\" TimeOut Waiting for Standby State\"); 
                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
              }
              syss = 0x8 | stus;     /* New State is 'Standby'              */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
              break;
     default : ;
   }
   dpGet(\"SCTmops1:Eror.Stat:_original.._value\", eror);
     if((eror & 0x1) > 0)
   { dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2); /* Yellow Colour   */
     sprintf(mstr,\" CHECK ERROR AND PUSH EXIT [X] BUTTON\");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   } else
   { sprintf(mstr,\" DPs ARE 'STB'_LOADED... \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2);
//   ...                             /* Make your 'Standby' job here        */
     Send_Loaded();
//   ...                             /* Make your 'Standby' job here        */
     int1=0; while(int1 < 9)
     { stri = getSystemName(int1);
       int2 = strlen(stri); if(int2 > 0)
       { sprintf(snam,\"%s\", stri);
         strreplace(snam,\":\",\"\");  break;
       } int1++;
     }
     sprintf(mstr,\" %s IS WAITING...\", snam);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(1);
     dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
/*
     dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
     dpGet(\"SCTmops1:Next.Stat:_original.._value\", stus);
     dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
     dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     sprintf(mstr,\" StbMade: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                             stat, stus, syss, busy);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(2);/* Debug */
   }
 }
 
 StbOnTransition(string Dapo, int Stat)
 { int    syss, next, stat, busy;
   string mstr;

/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" StbOn: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                         stat, next, syss, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);            /* Debug */
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     if(((syss & 0xC) == 0x8) && ((next & 0xC) == 0xC) && (!busy))
   { dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x8);
   
//   ...                             /* Make your Off->Config job here      */
     MakeConfigs(0xC, 0xC);          /* Load DaPo_On from 'Para' confFile   */
//   ...                             /* Make your Off->Config job here      */
/*
     delay(70);                                                    /* Debug */
     dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
   }
 }
 
 OnStbTransition(string Dapo, int Stat)
 { int    syss, next, stat, busy;
   string mstr;

/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" StbOn: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                         stat, next, syss, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);            /* Debug */
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", next);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     if(((syss & 0xC) == 0xC) && ((next & 0xC) == 0x8) && (!busy))
   { dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x8);
   
//   ...                             /* Make your Off->Config job here      */
     MakeConfigs(0x8, 0xC);          /* Load DaPo_Stb from 'Para' confFile  */
//   ...                             /* Make your Off->Config job here      */
/*
     delay(70);                                                    /* Debug */
     dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
   }
 }

 OnFunction()
 { int    syss, stat, stus, busy;    /* SYStem STATe, STatUS, BUSY Stat     */
   int    tout, eror, errn;          /* TimeOUT (sec), system ERrOR & Number*/
   int    int1, int2;
   int    pmon, scan, simu, wait, host;   /* Period of MONitoring           */
   string snam, estr, mstr, stri;    /* Syst NAMe, Error and Monitor STRings*/

   tout = 180;
   dpGet(\"SCTmops1:Syst.Stat:_original.._value\", stat);
/*
   dpGet(\"SCTmops1:Host.Stat:_original.._value\", int1);
   dpGet(\"SCTmops1:Next.Stat:_original.._value\", stus);
   dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
   sprintf(mstr,\" MakeOn: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                          int1, stus, stat, busy);
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2); /* Debug */
   syss = stat & 0xC;                   stus = stat & 0x33;  stat = 0x0;
     switch(syss)
   { case 0x0:                       /* Current State is 'Off'              */
                                     /* Disable condition for TransiFunction*/
              dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x4);
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x4 | stus);
              delay(1);
//              busy=1; while((busy > 0) && (tout > 0))
//              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
//                delay(1); tout--;
//              } if(tout <= 0)
//              { sprintf(estr,\" TimeOut Waiting for Config State\"); 
//                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
//                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//              }
              syss = 0x4 | stus;     /* Intermediate State is 'Config'      */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
              delay(1);
     case 0x4:                       /* Current State is 'Config'           */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0x8 | stus);
              delay(1);
//              busy=1; while((busy > 0) && (tout > 0))
//              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
//                delay(1); tout--;
//              } if(tout <= 0)
//              { sprintf(estr,\" TimeOut Waiting for Standby State\"); 
//                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
//                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//              }
              syss = 0x8 | stus;     /* Intermediate State is 'Standby'     */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
                                     /* Enable condition for TransiFunction */
              dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
              delay(1);
     case 0x8:                       /* Current State is 'Standby'          */
              dpSet(\"SCTmops1:Next.Stat:_original.._value\", 0xC | stus);
              delay(1);
              busy=1; while((busy > 0) && (tout > 0))
              { dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
                delay(1); tout--;
              } if(tout <= 0)
              { sprintf(estr,\" TimeOut Waiting for On State\"); 
                dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
                dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
              }
              syss = 0xC | stus;     /* New State is 'On'                   */
              dpSet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
     case 0xC: ;                     /* Current State is 'On'               */
     default : ;
   }
   dpGet(\"SCTmops1:Eror.Stat:_original.._value\", eror);
     if((eror & 0x1) > 0)
   { dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2); /* Yellow Colour   */
     sprintf(mstr,\" CHECK ERROR AND PUSH EXIT [X] BUTTON\");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   } else
   { sprintf(mstr,\" DPs ARE 'ON'_LOADED... \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2);
//   ...                             /* Make your start 'On' job here       */
     Send_Loaded();
//   ...                             /* Make your start 'On' job here       */
     int1=0; while(int1 < 9)
     { stri = getSystemName(int1);
       int2 = strlen(stri); if(int2 > 0)
       { sprintf(snam,\"%s\", stri);
         strreplace(snam,\":\",\"\");  break;
       } int1++;
     }
     sprintf(mstr,\" %s IS STARTING...\", snam);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(2);
     dpSet(\"SCTmops1:Busy.Stat:_original.._value\", 0x0);
/*
     dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
     dpGet(\"SCTmops1:Next.Stat:_original.._value\", stus);
     dpGet(\"SCTmops1:Syst.Stat:_original.._value\", syss);
     dpGet(\"SCTmops1:Busy.Stat:_original.._value\", busy);
     sprintf(mstr,\" OnMade: Host=%Xh, Next=%Xh, Syst=%Xh, Busy=%Xh\",
                            stat, stus, syss, busy);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(2);/* Debug */

     dpGet(\"SCTmops1:Host.Numb:_original.._value\", host);
     sprintf(stri,\"SCTmops1:Host0%d.Pmon:_original.._value\", host);
     dpGet(stri, pmon);
     sprintf(stri,\"SCTmops1:Host0%d.Simu:_original.._value\", host);
     dpGet(stri, simu);
     dpGet(\"SCTmops1:Scan.Numb:_original.._value\", scan);
       while(1)
     { scan++; dpSet(\"SCTmops1:Scan.Numb:_original.._value\", scan);
         if(simu)                    /* Data Simulation mode                */
       { sprintf(mstr,\" SIMULATION SCAN...\");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
           if((scan & 0x1) == 1)     /* Odd Scan number                     */
         { RandomData_32Chan(0,  0); /* Simulation From start Chan =  0     */
         } else                      /* Even Scan number                    */
         { RandomData_32Chan(0, 24); /* Simulation From start Chan = 24     */
         }
         wait = pmon - 8;
       } else
       { sprintf(mstr,\" MONITORING SCAN...\");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         wait = pmon;
       }
         while(wait > 0)
       { delay(1);                      wait--;
         sprintf(mstr,\" WAIT %2d sec...\", wait);
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
       }
       dpGet(\"SCTmops1:Host.Stat:_original.._value\", stat);
         if((stat & 0xC) != 0xC)
       { sprintf(mstr,\" STOP...\");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         break;
       }       
     }
   }
 }

/* ======================================================================== */
/*                    SEND LOADED CONFIGs TO POWER SUPPLIES                 */
/* ======================================================================== */
 
 Send_Loaded()
 { int channel, icard, set, lv;
   int    unit, umax, chan, cmax;    /* Unit (ELMB) & Chan(nel) MAX_numbers */
   int    stat, errn;                /* STATe and ERRor (serial) Number     */
   string stri, dstr, estr;          /* Current, Debugger and Error STRings */
   dyn_errClass eror;
/**/
  dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);   /* Yellow Background*/
  sprintf(dstr,\" Send_Loaded() started... \");
  dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);   delay(1); /* Debug */
  dpGet(\"SCTmops1:Umax.Numb:_original.._value\"  , umax);
  dpGet(\"SCTmops1:Cmax.Numb:_original.._value\"  , cmax);
  unit=0; while(unit < umax)         /* Scan all Crates (Units) on CAN-bus  */
  {   if(unit < 10)
    { sprintf(stri,\"SCTmops1:Crate0%d.Stat:_original.._value\", unit);
    } else
    { sprintf(stri,\"SCTmops1:Crate%d.Stat:_original.._value\" , unit);
    }
    dpGet(stri, stat);
      if((stat & 0xC) > 0)           /* If Crate is included in Run config  */
    { chan=0; while(chan < cmax)
      { channel = chan + 100;
          if(unit < 10)
        { sprintf(stri,
         \"SCTmops1:Crate0%d.Controller.CCch_Set.Send:_original.._value\",unit);
        } else
        { sprintf(stri,
         \"SCTmops1:Crate%d.Controller.CCch_Set.Send:_original.._value\" ,unit);
        }
        dpSetWait(stri, channel);
        delay(0,50);
        dpSetWait(stri, chan);
        chan++;
      }
    } unit++;
  }
    if(0)                            /* SYSTEM ERROR EXAMPLE                */
  { sprintf(estr,\" Send_Loaded()\\n      Check everything !!! \"); 
    dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
    dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
  }
/**/
  sprintf(dstr,\" Send_Loaded() finished \");
  dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);   delay(1); /* Debug */
  dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x0);    /* Green Background*/
  eror = getLastError();
    if(dynlen(eror) > 0)
  { errorDialog(eror);
  }
}

/* ======================================================================== */
/*                        MAKE_CONFIGS() SUBROUTINES                        */
/* ======================================================================== */

/* CREATE THE SETTINGS FOR OPC-SERVER                                       */
/*                                                                          */
 setOPCServer(string serverName, int aliveTimer, int reconnectTimer)
 { bool connectedState;
	
     //rename serverName just the internal name form
   serverName = \"_\" + serverName;
     //create severName datapoint if it does not exist already
     if (!dpExists(serverName))
   { //create serverName datapoint of type _OPCServer (PVSS internal type)
     dpCreate(serverName, \"_OPCServer\"); 
   }
     //set some of the serverName datapoint elements
   dpSet(serverName+\".StateTimer:_original.._value\", aliveTimer);
   dpSet(serverName+\".ReconnectTimer:_original.._value\", reconnectTimer);
     //check if the PVSS OPC client is connected
//   dpGet(serverName+\".Connected:_online.._value\", connectedState);
//   DebugN(\"====================== connectedState = \", connectedState);
 }

/* CREATE OPC-SERVER GROUP AND IT'S SETTINGS                                */
/*                                                                          */
 setOPCGroup(string groupName, int  nominalValue, string DataSoure,
                               bool active,       bool   enableCallBack)
 { bool DataSoureDevice;
	
     //rename groupName just the internal name form
   groupName = \"_\" + groupName;
     //create groupName datapoint if it does not already exist 
     if (!dpExists(groupName))
   { //create groupName datapoint of type _OPCGroup (PVSS internal type)
     dpCreate(groupName, \"_OPCGroup\"); 
   }
     //set some of the groupName datapoint elements
   dpSet(groupName+\".UpdateRateReq:_original.._value\", nominalValue);
     if(DataSoure == \"Device\")
   { DataSoureDevice = TRUE;
   } else
   { DataSoureDevice =FALSE;
   }
   dpSet(groupName+\".DataSourceDevice:_original.._value\", DataSoureDevice);
   dpSet(groupName+\".Active:_original.._value\", active);
   dpSet(groupName+\".EnableCallback:_original.._value\", enableCallBack);
 }

/* CREATE (IF ABSENT) AND FILL FatL, WarL, WarH, FatH CONFIGs OF DATA_POINT */
/*                                                                          */
 setAlerts(string dpConfigName, float Fatal_low, float Warn_low,
                                float Warn_high, float Fatal_high)
 { int      alert_exist, status;
   unsigned num_ranges = 0;
   float    normal_simu;
   string   dpName, estr;
/**/
   normal_simu = (Warn_low + Warn_high) / 2.0;
   dpSet(dpConfigName, normal_simu);                               /* Debug */
   sprintf(dpName, dpConfigName);
   strreplace(dpName,\":_original.._value\",\"\");
               // test if the alert exist already
   status = dpGet(dpName + \":_alert_hdl.._type\", alert_exist);
     if(!status && !alert_exist)
   {           // set analog alert (13 means analog alerts, 12 - binary alerts)
     dpSet(dpName + \":_alert_hdl.._type\", 13,
               // set 5 ranges
     dpName + \":_alert_hdl.1._type\", 4,  // fatal   low  range
     dpName + \":_alert_hdl.2._type\", 4,  // warning low  range
     dpName + \":_alert_hdl.3._type\", 4,  // normal       range
     dpName + \":_alert_hdl.4._type\", 4,  // warning high range
     dpName + \":_alert_hdl.5._type\", 4,  // fatal   high range
               //  set each range: each range consists of two values (borders)
     dpName + \":_alert_hdl.1._u_limit\", Fatal_low, 
     dpName + \":_alert_hdl.2._l_limit\", Fatal_low, 
     dpName + \":_alert_hdl.2._u_limit\", Warn_low, 
     dpName + \":_alert_hdl.3._l_limit\", Warn_low,
     dpName + \":_alert_hdl.3._u_limit\", Warn_high,
     dpName + \":_alert_hdl.4._l_limit\", Warn_high,
     dpName + \":_alert_hdl.4._u_limit\", Fatal_high,
     dpName + \":_alert_hdl.5._l_limit\", Fatal_high,
               // set the limit of each range, look for consistency!    
     dpName + \":_alert_hdl.1._u_incl\", TRUE,  
     dpName + \":_alert_hdl.2._l_incl\", FALSE, 
     dpName + \":_alert_hdl.2._u_incl\", TRUE, 
     dpName + \":_alert_hdl.3._l_incl\", FALSE, 
     dpName + \":_alert_hdl.3._u_incl\", FALSE, 
     dpName + \":_alert_hdl.4._l_incl\", TRUE, 
     dpName + \":_alert_hdl.4._u_incl\", FALSE, 
     dpName + \":_alert_hdl.5._l_incl\", TRUE, 
               // set alert texts
     dpName + \":_alert_hdl.1._text\", \" Data is fatal Low\",  
     dpName + \":_alert_hdl.2._text\", \" Data is warn. Low\", 
     dpName + \":_alert_hdl.3._text\", \" Data is Normal\",
     dpName + \":_alert_hdl.4._text\", \" Data is warn. High\",
     dpName + \":_alert_hdl.5._text\", \" Data is fatal High\",
               // set alert class
     dpName + \":_alert_hdl.1._class\", \"alert.\", 
     dpName + \":_alert_hdl.2._class\", \"warning.\",
     dpName + \":_alert_hdl.4._class\", \"warning.\",
     dpName + \":_alert_hdl.5._class\", \"alert.\",
               // working with the original value
     dpName + \":_alert_hdl.._orig_hdl\", TRUE, 
               // activates the alert handling
     dpName + \":_alert_hdl.._active\", TRUE); 
   } else
   {           // get the number of  alert ranges
     dpGet(dpName + \":_alert_hdl.._num_ranges\", num_ranges);
               // make sure there are 5 ranges (the case of script)
       if(num_ranges == 5)
     {         // acknoledge the alert if any, otherwise the parameters
               // cann't be changed
       dpSet(dpName + \":_alert_hdl.._ack\", 1);
               // desactivates the alert handling
       dpSet(dpName + \":_alert_hdl.._active\", FALSE, 
               // set each range: each range consists of two values (borders)
       dpName + \":_alert_hdl.1._u_limit\", Fatal_low, 
       dpName + \":_alert_hdl.2._l_limit\", Fatal_low, 
       dpName + \":_alert_hdl.2._u_limit\", Warn_low, 
       dpName + \":_alert_hdl.3._l_limit\", Warn_low,
       dpName + \":_alert_hdl.3._u_limit\", Warn_high,
       dpName + \":_alert_hdl.4._l_limit\", Warn_high,
       dpName + \":_alert_hdl.4._u_limit\", Fatal_high,
       dpName + \":_alert_hdl.5._l_limit\", Fatal_high);
               // re-activates the alert handling
       dpSet(dpName + \":_alert_hdl.._active\", TRUE);
     } else
     { sprintf(estr,
       \" there are not 5 ranges as assumed\\n           in the alert Script \");
       dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
       dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//       Debug(\" ERROR in alert script: there are not 5 ranges as assumed \");
     }
   }           //end of else
 }
 
/* CHECK WHETHER OPC SDERVER IS INCLUDING AND OPC_NAME & OPC_GROUP EXIST    */
/*                                                                          */
 CheckOPCserver(string opcServerName, string OPCGroup) 
 { int    serv;
   string opc, group, estr;

               //check if OPC server exists 
   opc = getSystemName() + \"_\" + opcServerName;
     if(!dpExists(opc))
   { sprintf(estr,
     \"  CheckOPCserver(): OPC Server: \"+opcServerName+\" does not exist\");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//     Debug(
//     \" CheckOPCserver(): OPC Server: \"+opcServerName+\" does not exist\"); 
     return;
   }	       //check if OPC group exists
   group = getSystemName() + \"_\" + OPCGroup; 
     if (!dpExists(group))
   { sprintf(estr,
     \" CheckOPCserver(): OPC group \"+OPCGroup+\" does not exist\");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//    Debug(\" CheckOPCserver(): OPC group \"+OPCGroup+\" does not exist\");
     return;
   }
 }

/* CREATE (IF ABSENT) AND CHANGE THE CONNECTION OF OPC_ITEM TO PVSS DPe     */
/* NOTE! OPCItemName should include: PortName.UnitName.ItemName             */
/*                                                                          */
 setOPCAddress(string dpeName  , string OPCItemName  , string dpeType,
               string direction, string opcServerName, int    driverNum,
               string OPCGroup) 
 { int intDirection, intDpeType;
   string       estr, reference; 
   dyn_errClass eror; 

   strreplace(dpeName,\":_original.._value\",\"\");
/*   
   DebugN(\"=====================dpeName = \", dpeName );
   DebugN(\"=====================OPCItemName = \", OPCItemName);
   DebugN(\"=====================dpeType = \", dpeType);
   DebugN(\"=====================direction = \", direction);
   DebugN(\"=====================opcServerName = \", opcServerName);
   DebugN(\"=====================OPCGroup = \", OPCGroup);
   while(1){delay(1);}                                             /* Debug */	
               //the full OPC item address  
   reference = opcServerName + \"$\" + OPCGroup + \"$\" + OPCItemName; 
               //the direction (read or write):
     if(direction == \"OUT\" || direction == \"out\" || direction == \"Out\")
   { intDirection = DPATTR_ADDR_MODE_OUTPUT_SINGLE;
   } else if(direction == \"IN\" || direction == \"in\" || direction == \"In\")
   { intDirection = DPATTR_ADDR_MODE_INPUT_SPONT;
   }
     switch(intDirection) 
   { case DPATTR_ADDR_MODE_OUTPUT_SINGLE:    ;
     case DPATTR_ADDR_MODE_INPUT_SPONT:      ;
     case DPATTR_ADDR_MODE_INPUT_SPONT + 64: ;
     case DPATTR_ADDR_MODE_OUTPUT_SINGLE + 64:
          dpSetWait(dpeName + \":_distrib.._type\", DPCONFIG_DISTRIBUTION_INFO,
                    dpeName + \":_distrib.._driver\", driverNum);
          eror = getLastError();
            if(dynlen(eror) > 0) 
          { throwError(eror);
            sprintf(estr,
            \" setOPCAddress()\\n           while creating the address config\");
            dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
            dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//            Debug(
//            \" ERROR in setOPCAddress() while creating the address config\");
          }    //find the PVSS OPC client data type:
            switch(dpeType)
          { case \"VT_UI1\":    intDpeType = 0;    break;  //uint8
            case \"VT_UI2\":    intDpeType = 488;  break;  //uint16
            case \"VT_UI4\":    intDpeType = 489;  break;  //uint32
            case \"VT_BOOL\":   intDpeType = 486;  break;  //Bool
            case \"VT_FLOAT8\": intDpeType = 485;  break;  //float64
            case \"VT_FLOAT4\": intDpeType = 484;  break;  //float32
            case \"VT_I1\":     intDpeType = 0;    break;  //int8
            case \"VT_I2\":     intDpeType = 481;	 break;  //int16
            case \"VT_I4\":     intDpeType = 482;	 break;  //int32
            case \"VT_STRING\": intDpeType = 487;  break;  //string
            case \"default\":   intDpeType = 0;    break;  //default
            default:          intDpeType = 480;  break;  //unknown
          }	   //set the address config parameters
          dpSetWait(dpeName + \":_address.._type\", DPCONFIG_PERIPH_ADDR_MAIN,
                    dpeName + \":_address.._reference\", reference,
                    dpeName + \":_address.._datatype\" , intDpeType,
                    dpeName + \":_address.._mode\"     , intDirection,
                    dpeName + \":_address.._drv_ident\", \"OPCCLIENT\");
          eror = getLastError();
            if(dynlen(eror) > 0) 
          {	throwError(eror);
            sprintf(estr,
\" setOPCAddress():           Error while configuring the peripheral address\");
            dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
            dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//            Debug(
//          \" setOPCAddress(): Error while configuring the peripheral address\");
          } break;
     default:  sprintf(estr,
\" setOPCAddress()\\n           The selected mode \"+ intDirection +\" is unknown\");
              dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
              dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//            Debug(
//\" ERROR in setOPCAddress(); the selected mode \"+ intDirection +\" is unknown\");
              return;
   }
 } 

/* CONVERTIONs: RAW->PHYSICAL->RAW BY USING _MSG_CONV AND _CMD_CONV CONFIGs */
/*                                                                          */
 setConversion(string dpeName, string Direction, float Alfa, float Beta)
 { dyn_errClass eror;

     switch(Direction)
   { case \"IN\":                            // Monitored value coversion
     dpSetWait(
          dpeName+\":_msg_conv.._type\", 33, //Coversion from raw to physical
          dpeName+\":_msg_conv.1._type\", 2, //Polynomial 4th degree conversion
          dpeName+\":_msg_conv.1._poly_grade\", 1,  //Take only: y = a + b*x
          dpeName+\":_msg_conv.1._poly_a\", Alfa,
          dpeName+\":_msg_conv.1._poly_b\", Beta); break;
     case \"OUT\":                           // Controled value conversion
     dpSetWait(
          dpeName+\":_cmd_conv.._type\", 36, //Coversion from raw to physical
          dpeName+\":_cmd_conv.1._type\", 2, //Polynomial 4th degree conversion
          dpeName+\":_cmd_conv.1._poly_grade\", 1,  //Take only: y = a + b*x
          dpeName+\":_cmd_conv.1._poly_a\", Alfa,
          dpeName+\":_cmd_conv.1._poly_b\", Beta); break;
     default: ;	
   }//end of switch(...)
   eror = getLastError(); if(dynlen(eror) > 0) 
   { throwError(eror);
   }	  		  
 }
/*                                                          07.07.2003      */
/*                             CONVERSION FORMULAS                          */
/*                                                                          */
//   switch(para)                    /* Conversion of Raw Value to \"Recv\"   */
// { case  1: recv = 1.0  * rawv;            break;      /* LVcaTemp        */
//   case  2: recv = rawv / 2.5;             break;      /* LVcaPowr        */
//   default: recv = 9999.9;
// }
//   switch(para)                    /* Conversion of \"Send\" to Raw Value   */
// { case  1: rawv = send * 2.5;             break;      /* LVcaTrip        */
//   default: rawv = 0.0;
// }
//   switch(para)                    /* Conversion of Raw Value to \"Recv\"   */
// { case  1: recv = (20.0 * rawv) / 1000.0; break;      /* LVch_Vcc        */
//   case  2: recv = (50.0 * rawv) / 1000.0; break;      /* LVps_Vcc        */
//   case  3: recv = (20.0 * rawv) / 1000.0; break;      /* LVretVcc        */
//   case  4: recv =  10.0 * rawv;           break;      /* LVch_Icc        */
//   case  5: recv = (20.0 * rawv) / 1000.0; break;      /* LVch_Vdd        */
//   case  6: recv = (50.0 * rawv) / 1000.0; break;      /* LVps_Vdd        */
//   case  7: recv = (20.0 * rawv) / 1000.0; break;      /* LVretVdd        */
//   case  8: recv =  10.0 * rawv;           break;      /* LVch_Idd        */
//   case  9: recv = (40.0 * rawv) / 1000.0; break;      /* LVchVCSV        */
//   case 10: recv =  rawv / 25.0;           break;      /* LVchVCSI        */
//   case 11: recv = (50.0 * rawv) / 1000.0; break;      /* LVchPINV        */
//   case 12: recv =  rawv / 100.0;          break;      /* LVchPINI        */
//   case 13: recv = ( 1.0 * rawv) / 1.0;    break;      /* MOch_Tm0        */
//   case 14: recv = ( 1.0 * rawv) / 1.0;    break;      /* MOch_Tm1        */
//   case 15: recv = 2.0 * rawv;             break;      /* LVchDTrp_send   */
//   case 16: recv = 2.0 * rawv;             break;      /* LVchCTrp_send   */
//   case 17: recv = rawv - 128.0;           break;      /* LVchTLim_send   */
//   case 18: recv = rawv - 128.0;           break;      /* LVchTTrp_send   */
//   case 23: recv = rawv / 8.0;             break;      /* HVchVolt        */
//   case 24: recv = rawv;                   break;      /* HVchCurr        */
//   case 27: recv = rawv;                   break;      /* HVchITrp_send   */
//   case 28: recv = rawv;                   break;      /* HVchRamp_send   */
//   default: recv = 9999.9;
// }
//   switch(para)                    /* Conversion of \"Send\" to Raw Value   */
// { case  1: rawv = (send * 1000.0) / 20.0; break;      /* LVch_Vcc        */
//   case  5: rawv = (send * 1000.0) / 20.0; break;      /* LVch_Vdd        */
//   case  9: rawv = (send * 1000.0) / 40.0; break;      /* LVchVCSV        */
//   case 11: rawv = (send * 1000.0) / 50.0; break;      /* LVchPINV        */
//   case 15: rawv = send / 2.0;             break;      /* LVchDTrp        */
//   case 16: rawv = send / 2.0;             break;      /* LVchCTrp        */
//   case 17: rawv = send + 128.0;           break;      /* LVchTLim        */
//   case 18: rawv = send + 128.0;           break;      /* LVchTTrp        */
//   case 26: rawv = send;                   break;      /* HVchVolt        */
//   case 27: rawv = send;                   break;      /* HVchITrp        */
//   case 28: rawv = send;                   break;      /* HVchRamp        */
//   default: rawv = 0.0;
// }

/* ======================================================================== */
/* CREATE PVSS CONFIGs AND LOAD THEM, MAKE OPC_CONFIG FILE & PVSS OPC ADDRs */
/*                                                                          */
/*                      Load -       ( if Serv == 0x0 or 0x4 or 0xC )       */
/*                             0x0 - Load NOTHING       from 'Para' confFile*/
/*                             0x4 - Load 'Off' to DaPo from 'Para' confFile*/
/*                             0x8 - Load 'Stb' to DaPo from 'Para' confFile*/
/*                             0xC - Load 'On'  to DaPo from 'Para' confFile*/
/*                      Serv - what will be created for OPC-server:         */
/*                             0x0 - Create NOTHING                         */
/*                             0x4 - Create OPC-configFile                  */
/*                             0x8 - Create OPC-addresses and PVSS          */
/*                                          comm/mesg conversion formulas   */
/*                             0xC - Create NOTHING                         */
/*                                                                          */
 MakeConfigs(int Load, int Serv)
 { int  host, node, port, unit, chan, cnod, cpor, busn;
   int  hmax, nmax, pmax, umax, cmax, mmax, lvmx, hvmx, lmax;
   int  mod1, mod2, para, len1, len2, leng;
   int  rack, crat, card, lvca, hvca, lvpa, lvix, hvpa, hvix, hivo;
   int  grup, maxp, lvca_max  , hvca_max  , crmx;
   int  iden, pmon, simu, unin, limi, int1, int2, int3;
   int  syss, stat, stus, imod;      /* SYStem STATe and STatuS (Error)     */
   int  busy, tout, usts, csts;      /* BUSY, TimeOUT (sec); Unit,Chan STuS */
   int  vadc, conv, eror, errn, arch;/* ADC range, CONVersion number, ERrOR */
   float acal,bcal, ccal, dcal, ecal, rcal;    /* A,B,C,D,E,R- CALibrations */
   float data,flo1, flo2;
   float      s00f, s01f, s02f, s03f,/* String '**' of Float(s)             */
              s04f, s05f, s06f, s07f, s08f, s09f, s10f, s11f,
              s12f, s13f, s14f, s15f, s16f, s17f, s18f, s19f,
              s20f, s21f, s22f, s23f, s24f, s25f, s26f, s27f;
   int        s00i, s01i, s02i, s03i,/* String '**' of Integer(s)           */
              s04i, s05i, s06i, s07i, s08i, s09i, s10i, s11i,
              s12i, s13i, s14i, s15i, s16i, s17i, s18i, s19i,
              s20i, s21i, s22i, s23i, s24i, s25i, s26i, s27i;
   string     s00w, s01w, s02w, s03w,/* String '**' of Word(s)              */
              s04w, s05w, s06w, s07w, s08w, s09w, s10w, s11w,
              s12w, s13w, s14w, s15w, s16w, s17w, s18w, s19w,
              s20w, s21w, s22w, s23w, s24w, s25w, s26w, s27w, s28w;
   string     s00e, s01e, s02e, s03e,/* String '**' of idEn(s)              */
              s04e, s05e, s06e, s07e, s08e, s09e, s10e, s11e,
              s12e, s13e, s14e, s15e, s16e, s17e, s18e, s19e,
              s20e, s21e, s22e, s23e, s24e, s25e, s26e, s27e;
   string     stri, snam, bnam, fstr, estr, mstr, dstr;
   string     str0, str1, str2, str3, str4, str5,
              str6, str7, str8, str9;
   string     nadr, padr, uadr, cadr, para_adr;/* Node,Port,Unit,Chan ADdRes*/
   dyn_string list;
   file       finp, fopc, fsdi, fpdo, fpdi, fini, fidn;
   bool       connectedState;
/*-----------------------------------=--------------------------------------*/
   imod =   4;                       /* Identification mode for Chan Name   */
   tout =  30;                       /* TimeOut (in sec)                    */  
/*-----------------------------------=--------------------------------------*/
   int1=0; while(int1 < 9)           /* 9 - Max_number of PVSS systems      */
   { snam = getSystemName(int1);
     int2 = strlen(snam); if(int2 > 0)
     {
/*
       dpSet(\"SCTmops1:Moni.Name:_original.._value\",sman);delay(1);/* Debug */
       strreplace(snam,\":\",\"\");          sprintf(stri, snam);
       strreplace(stri,\"SCTmops\",\"\");    break;
     } int1++;
   }
   sprintf(stri, snam);                 strreplace(stri,\"mops\",\"\");
   len1 = strlen(snam);                 len2 = strlen(stri);
     if(len2 >= len1)
   { sprintf(estr,\" PVSS_DB is not for MoPS: %s \", snam);
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2); /* Yellow Colour   */
     sprintf(mstr,\" CHECK PROJ_DB AND PUSH EXIT [X] BUTTON\");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   }
     if((Serv & 0xC) == 0x4)
   { setOPCServer(\"CANopen\", 10, 10); 
     setOPCGroup(\"Comm\", 1000, \"Device\", TRUE, FALSE); 
     setOPCGroup(\"Moni\",  100, \"Cache\" , TRUE, TRUE);
     CheckOPCserver(\"CANopen\", \"Comm\");   /* Checking if OPC server exists  */
   }
     if((Serv & 0xC) > 0x4)
   { connectedState = 1;                  /* Should be commented for NO_OPC */
/**/
     dpGet(\"_CANopen.Connected:_online.._value\", connectedState);  /* Debug */
       if(!connectedState)
     { sprintf(estr,\" OPC Client is not connected\");
       dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
       dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x2);
//       dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);    /* YellowColor*/
//       sprintf(mstr,\" CHECK OPC-SERVER AND PUSH EXIT [X] BUTTON\");
//       dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
//       while(1) { delay(1); }
     }
   }
//   dpGet(\"SCTmops1:Cmax.Numb:_original.._value\", cmax);
   sprintf(str1,\"%s\",\" ERROR \");         sprintf(str2,\"%s\",\" ERROR \");
   sprintf(str3,\"%s\",\" ERROR \");         sprintf(str4,\"%s\",\" ERROR \");
   sprintf(str5,\"%s\",\" ERROR \");         sprintf(str6,\"%s\",\" ERROR \");
   sprintf(str7,\"%s\",\" ERROR \");         sprintf(str8,\"%s\",\" ERROR \");
/*SYST*/
   dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);   /* Yellow Colour   */
   sprintf(mstr,\" SYST CONFIGs LOADING...\");            delay(1);  /* Debug */
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
   finp = fopen(\"Cnf_Syst.txt\",\"r\"); /* System parameters reading from CF   */
   eror = ferror(finp);
     if(!eror)
   { fgets(fstr, 300, finp);         /* Skip the first line                 */
     fgets(fstr, 300, finp);
     sscanf(fstr,\"%d  %d %d %d %d %d  %d  %d %d %d %d %d\",
      s00i, s01i, s02i, s03i, s04i, s05i, s06i, s07i, s08i, s09i, s10i, s11i);
     fclose(finp);
     hmax= s01i; if(hmax > 9)
     { sprintf(estr,
       \" Reading 'Cnf_Host.txt',\\n           HostMax number is too much: %d\",
                     hmax); 
       dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
       dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
       dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
       sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
       while(1) { delay(1); }
     }
     dpSet(\"SCTmops1:Hmax.Numb:_original.._value\", s01i);
     dpSet(\"SCTmops1:Nmax.Numb:_original.._value\", s02i);
     dpSet(\"SCTmops1:Pmax.Numb:_original.._value\", s03i);
     dpSet(\"SCTmops1:Umax.Numb:_original.._value\", s04i);
     dpSet(\"SCTmops1:Cmax.Numb:_original.._value\", s05i);
     dpSet(\"SCTmops1:LVch_max.Numb:_original.._value\", s06i);
     dpSet(\"SCTmops1:HVch_max.Numb:_original.._value\", s07i);
     dpSet(\"SCTmops1:LVca_max.Numb:_original.._value\", s08i);
     dpSet(\"SCTmops1:HVca_max.Numb:_original.._value\", s09i);
     dpSet(\"SCTmops1:CRpa_max.Numb:_original.._value\", s10i);
     dpSet(\"SCTmops1:Lmax.Numb:_original.._value\", s11i);
     delay(1);
     dpGet(\"SCTmops1:Hmax.Numb:_original.._value\", hmax);     /* Host_Max   */
     dpGet(\"SCTmops1:Nmax.Numb:_original.._value\", nmax);     /* Node_Max   */
     dpGet(\"SCTmops1:Pmax.Numb:_original.._value\", pmax);     /* Port_Max   */
     dpGet(\"SCTmops1:Umax.Numb:_original.._value\", umax);     /* Unit_Max   */
     dpGet(\"SCTmops1:Cmax.Numb:_original.._value\", cmax);     /* Chan_Max   */
     dpGet(\"SCTmops1:LVch_max.Numb:_original.._value\", lvmx); /* LVparaMax  */
     dpGet(\"SCTmops1:HVch_max.Numb:_original.._value\", hvmx); /* HVparaMax  */
     dpGet(\"SCTmops1:LVca_max.Numb:_original.._value\", lvca_max);
     dpGet(\"SCTmops1:HVca_max.Numb:_original.._value\", hvca_max);
     dpGet(\"SCTmops1:CRpa_max.Numb:_original.._value\", crmx); /* CRparaMax  */
     dpGet(\"SCTmops1:Lmax.Numb:_original.._value\", lmax);     /* LimiTypeMax*/
     cnod= s12i; cpor= s13i;         /* Control (nonScan) NODe & PORt number*/
     mmax = nmax*pmax * umax*cmax;   /* Modl-s/Chan-s_MAX number in one Host*/
/**/
     dpSet(\"SCTmops1:Hmax.Stat:_original.._value\", 0x2); /* Yellow Colour   */
     sprintf(dstr,\" Hmax=%d, Nmax=%d, Pmax=%d, Umax=%d, Cmax=%d, Lmax=%d\",
                    hmax, nmax, pmax, umax, cmax, lmax);
     dpSet(\"SCTmops1:Hmax.Name:_original.._value\", dstr);           /* Debug*/
/**/
     dpSet(\"SCTmops1:Nmax.Stat:_original.._value\", 0x2); /* Yellow Colour   */
     sprintf(dstr,\" LVpMx=%d, HVpMx=%d, LVcpMx=%d, HVcpMax=%d, CRpMax=%d\",
                    lvmx, hvmx, lvca_max, hvca_max, crmx);
     dpSet(\"SCTmops1:Nmax.Name:_original.._value\", dstr); delay(1); /* Debug*/
   } else
   { sprintf(estr,\" 'Cnf_Syst.txt' File opening \");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
     sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   }
/*HOST*/
   sprintf(mstr,\" HOST CONFIGs LOADING...\");             delay(1);  /* Debug*/
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
   finp = fopen(\"Cnf_Host.txt\",\"r\"); /* Host(s) parameters reading from DB  */
   eror = ferror(finp);
     if(!eror)
   { fgets(fstr, 300, finp);         /* Skip the first line                 */
     fgets(fstr, 300, finp);
     sscanf(fstr,\"%d %d %s %s %s %d %d %d %d %d %d %d %d\",
                 s00i, s01i, s02w, s03w, s04w, s05i, s06i, s07i, s08i,
                                               s09i, s10i, s11i, s12i);
//     sprintf(dstr,\" %d %s %s %s %d %d %d\",
//                  s00i, s01w, s02w, s03w, s04i, s05i, s06i);
     dpGet(\"SCTmops1:Host.Numb:_original.._value\", host);
     sprintf(str1,\"%s\"\"%d\"\"%s\",
                  \"SCTmops1:Host0\",host,\".Name:_original.._value\");
     strreplace(s02w,\"\\\"\",\"\");          dpSet(str1, s02w);
     sprintf(str2,\"%s\"\"%d\"\"%s\",
                  \"SCTmops1:Host0\",host,\".Iden:_original.._value\");
     strreplace(s03w,\"\\\"\",\"\");          dpSet(str2, s04w);
     sprintf(str3,\"%s\"\"%d\"\"%s\",
                  \"SCTmops1:Host0\",host,\".Stat:_original.._value\");
                                        dpSet(str3, 0x8);
     sprintf(str4,\"%s\"\"%d\"\"%s\",
                  \"SCTmops1:Host0\",host,\".Pmon:_original.._value\");
                                        dpSet(str4, s10i);
     sprintf(str5,\"%s\"\"%d\"\"%s\",
                  \"SCTmops1:Host0\",host,\".Scan:_original.._value\");
                                        dpSet(str5, s11i);
     sprintf(str6,\"%s\"\"%d\"\"%s\",
                  \"SCTmops1:Host0\",host,\".Simu:_original.._value\");
                                        dpSet(str6, s12i);
/*
     sscanf(fstr,\"%d %d %s %s %s %d %d %d %d %d %d %d %d\",
                 s00i, s01i, s02w, s03w, s04w, s05i, s06i, s07i, s08i,
                                               s09i, s10i, s11i, s12i);
//     sprintf(dstr,\" %d %s %s %s %d %d %d\",
//                  s00i, s01w, s02w, s03w, s04i, s05i, s06i);
//     dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr); delay(2);
     dpGet(str1, str0);  dpGet(str2, str9);  dpGet(str3, stat);
     sprintf(dstr,\" Host0%d Name: %s, Iden: %s, Stat = %xh\",
                    host, str0, str9, stat);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr); delay(2);
     dpGet(str4, int1);  dpGet(str5, int2);  dpGet(str6, int3);
     sprintf(dstr,\" Host0%d Pmon = %d, Scan = %d, Simu = %d\",
                    host, int1, int2, int3);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr); delay(2);/* Debug */
     fclose(finp);
   } else
   { sprintf(estr,\" 'Cnf_Host.txt' File opening \");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
     sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   }
/*NODE*/
   sprintf(mstr,\" NODE CONFIGs LOADING...\");
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(1); /* Debug */
/*OPC>*/
     if((Serv == 0x4) || (Serv == 0x8))
   { fopc = fopen(\"OPCCanServer.cfg\",\"w\");/* ConfigFile for OPC-server      */
     fini = fopen(\"OPCini.bak\",\"w\"); /* ConfigFile for OPC INItial param-s  */
     fprintf(fini,\"\\n[INIT]\\n\");
   }
/*<OPC*/
   finp = fopen(\"Cnf_Node.txt\",\"r\"); /* Node(s) parameters reading from DB  */
   eror = ferror(finp);
     if(!eror)
   { fgets(fstr, 300, finp);         /* Skip the first line                 */
     node=0; while(node < nmax)      /* OVER nodes must be after SCAN ones  */
     { fgets(fstr, 300, finp);
       sscanf(fstr,\"%d %d %d %s %s %s %s %s %s %d %s %s %d %s %s %d %s %s %d\",
              s00i, s01i, s02i, s03w, s04w, s05w, s06w, s07w, s08w, s09i,
                    s10w, s11w, s12i, s13w, s14w, s15i, s16w, s17w, s18i);
       node = s02i; if(node > 9)
       { sprintf(estr,
     \" Reading 'Cnf_Node.txt',\\n           Node number is too much, Node: %d\",
                      node); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       } if(node == 9)
       { break;
       }
       sprintf(str1,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                    \".Node0\",node,\".Name:_original.._value\");
       strreplace(s04w,\"\\\"\",\"\");       dpSet(str1, s04w);
       sprintf(str2,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                    \".Node0\",node,\".Iden:_original.._value\");
       strreplace(s05w,\"\\\"\",\"\");       dpSet(str2, s05w);
       sprintf(str3,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                    \".Node0\",node,\".Stat:_original.._value\");
       strreplace(s06w,\"\\\"\",\"\");       sscanf(s06w,\"%x\",stat);
                                       dpSet(str3, stat);
         if(pmax > 3)
       { busn = (node * pmax) + 3;
            if(busn < 10)
         { sprintf(bnam,\"Bus0%d\", busn);
         } else
         { sprintf(bnam,\"Bus%d\" , busn);
         }
         sprintf(str4,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                      \".Node0\",node,\".Port03.Iden:_original.._value\");
         strreplace(s16w,\"\\\"\",\"\");     dpSet(str4, s16w);
         sprintf(str5,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                      \".Node0\",node,\".Port03.Stat:_original.._value\");
         strreplace(s17w,\"\\\"\",\"\");     sscanf(s17w,\"%x\",stat);
                                       dpSet(str5, stat);
         sprintf(str6,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                      \".Node0\",node,\".Port03.Baud:_original.._value\");
                                       dpSet(str6, s18i);
       }
/*OPC>*/
         if((Serv == 0x4) || (Serv == 0x8))
       { fprintf(fopc,\"[CANBUS]\\n\");
           if((stat == 0x54) && (pmax > 3))
         { fprintf(fopc,\"%s = %s %s %d\\n\" , bnam, s05w, s16w, s18i);
           sprintf(stri,\"SCTmops1:Host0%d.Pmon:_original.._value\", host);
           dpGet(stri, pmon);
           fprintf(fini,\"%s.NMT               = 128\\n\", bnam);
           fprintf(fini,\"%s.SyncInterval      = %d\\n\" , bnam, pmon * 1000);
           fprintf(fini,\"%s.NodeGuardInterval = %d\\n\" , bnam, pmon * 10000);
           fprintf(fini,\"%s.NMT               = 1\\n\"  , bnam);
         }
       }
/*<OPC*/
         if(pmax > 2)
       { busn = (node * pmax) + 2;
            if(busn < 10)
         { sprintf(bnam,\"Bus0%d\", busn);
         } else
         { sprintf(bnam,\"Bus%d\" , busn);
         }
         sprintf(str4,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                      \".Node0\",node,\".Port02.Iden:_original.._value\");
         strreplace(s13w,\"\\\"\",\"\");     dpSet(str4, s13w);
         sprintf(str5,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                      \".Node0\",node,\".Port02.Stat:_original.._value\");
         strreplace(s14w,\"\\\"\",\"\");     sscanf(s14w,\"%x\",stat);
                                       dpSet(str5, stat);
         sprintf(str6,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                      \".Node0\",node,\".Port02.Baud:_original.._value\");
                                       dpSet(str6, s15i);
       }
/*OPC>*/
         if((Serv == 0x4) || (Serv == 0x8))
       {   if((stat == 0x54) && (pmax > 2))
         { fprintf(fopc,\"%s = %s %s %d\\n\" , bnam, s05w, s13w, s15i);
           sprintf(stri,\"SCTmops1:Host0%d.Pmon:_original.._value\", host);
           dpGet(stri, pmon);
           fprintf(fini,\"%s.NMT               = 128\\n\", bnam);
           fprintf(fini,\"%s.SyncInterval      = %d\\n\" , bnam, pmon * 1000);
           fprintf(fini,\"%s.NodeGuardInterval = %d\\n\" , bnam, pmon * 10000);
           fprintf(fini,\"%s.NMT               = 1\\n\"  , bnam);
         }
       }
/*<OPC*/
         if(pmax > 1)
       { busn = (node * pmax) + 1;
            if(busn < 10)
         { sprintf(bnam,\"Bus0%d\", busn);
         } else
         { sprintf(bnam,\"Bus%d\" , busn);
         }
         sprintf(str4,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                      \".Node0\",node,\".Port01.Iden:_original.._value\");
         strreplace(s10w,\"\\\"\",\"\");     dpSet(str4, s10w);
         sprintf(str5,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                    \".Node0\",node,\".Port01.Stat:_original.._value\");
         strreplace(s11w,\"\\\"\",\"\");     sscanf(s11w,\"%x\",stat);
                                       dpSet(str5, stat);
         sprintf(str6,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                      \".Node0\",node,\".Port01.Baud:_original.._value\");
                                       dpSet(str6, s12i);
       }
/*OPC>*/
         if((Serv == 0x4) || (Serv == 0x8))
       {   if((stat == 0x54) && (pmax > 1))
         { fprintf(fopc,\"%s = %s %s %d\\n\" , bnam, s05w, s10w, s12i);
           sprintf(stri,\"SCTmops1:Host0%d.Pmon:_original.._value\", host);
           dpGet(stri, pmon);
           fprintf(fini,\"%s.NMT               = 128\\n\", bnam);
           fprintf(fini,\"%s.SyncInterval      = %d\\n\" , bnam, pmon * 1000);
           fprintf(fini,\"%s.NodeGuardInterval = %d\\n\" , bnam, pmon * 10000);
           fprintf(fini,\"%s.NMT               = 1\\n\"  , bnam);
         }
       }
/*<OPC*/
       sprintf(str4,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                    \".Node0\",node,\".Port00.Iden:_original.._value\");
       strreplace(s07w,\"\\\"\",\"\");       dpSet(str4, s07w);
       sprintf(str5,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                    \".Node0\",node,\".Port00.Stat:_original.._value\");
       strreplace(s08w,\"\\\"\",\"\");       sscanf(s08w,\"%x\",stat);
                                       dpSet(str5, stat);
       sprintf(str6,\"%s\"\"%d\"\"%s\"\"%d\"\"%s\",\"SCTmops1:Host0\",host,
                    \".Node0\",node,\".Port00.Baud:_original.._value\");
                                       dpSet(str6, s09i);
/*OPC>*/
         if((Serv == 0x4) || (Serv == 0x8))
       {   if(stat == 0x54)
         { busn = (node * pmax) + 0;
             if(busn < 10)
           { sprintf(bnam,\"Bus0%d\", busn);
           } else
           { sprintf(bnam,\"Bus%d\" , busn);
           }
           fprintf(fopc,\"%s = %s %s %d\\n\" , bnam, s05w, s07w, s09i);
           sprintf(stri,\"SCTmops1:Host0%d.Pmon:_original.._value\", host);
           dpGet(stri, pmon);
           fprintf(fini,\"%s.NMT               = 128\\n\", bnam);
           fprintf(fini,\"%s.SyncInterval      = %d\\n\" , bnam, pmon * 1000);
           fprintf(fini,\"%s.NodeGuardInterval = %d\\n\" , bnam, pmon * 10000);
           fprintf(fini,\"%s.NMT               = 1\\n\"  , bnam);
         }
       }
/*<OPC*/
/*
       sprintf(dstr,\"%d %d %s %s %s %s %s %s \\n%d %s %s %d %s %s %d %s %s %d\",
               s01i, s02i, s03w, s04w, s05w, s06w, s07w, s08w, s09i,
               s10w, s11w, s12i, s13w, s14w, s15i, s16w, s17w, s18i);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(2);
       dpGet(str1, str0);  sprintf(dstr,\" Node0%d Name : %s\", node, str0);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(2);
       dpGet(str2, str0);  sprintf(dstr,\" Node0%d Iden : %s\", node, str0);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(2);
       dpGet(str3, stat);  sprintf(dstr,\" Node0%d Stat = %xh\",node, stat);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(1);
       dpGet(str4, str0);  sprintf(dstr,\" n_%d.Port0%d Iden = %s\",
                                                        node, port, str0);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(1);
       dpGet(str5, stat);  sprintf(dstr,\" n_%d.Port0%d Stat = %xh\",
                                                        node, port, stat);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(1);
       dpGet(str6, int1);  sprintf(dstr,\" n_%d.Port0%d Baud = %d\",
                                                        node, port, int1);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\",dstr);delay(1);/* Debug */
       node++;
     } fclose(finp);
   } else
   { fclose(fopc);  fclose(fini);
     sprintf(estr,\" 'Cnf_Node.txt' File opening \");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
     sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   }
/*UNIT*/
     if((Serv == 0x0) || (Serv == 0x4) || (Serv == 0xC))
   { sprintf(mstr,\" UNIT CONFIGs LOADING...\");
   } else
   { sprintf(mstr,\" UNIT OPC CONFIGs CREATING...\");
   }
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(1);
   finp = fopen(\"Cnf_Unit.txt\",\"r\"); /* Unit(s) parameters reading from DB  */
   eror = ferror(finp);
     if(!eror)
   {
/*OPC>*/
       if((Serv == 0x4) || (Serv == 0x8))
     { fprintf(fopc,\"\\n[DEVICE]\\n\");
       fsdi= fopen(\"OPCsdi.bak\",\"w\");/* ConfigFile for OPC SDoItem param-s  */
       fprintf(fsdi,\"\\n[SDOItem]\\n\");
       fpdo= fopen(\"OPCpdo.bak\",\"w\");/* ConfigFile for OPC PDO  parameters  */
       fprintf(fpdo,\"\\n[PDO]\\n\");
       fpdi= fopen(\"OPCpdi.bak\",\"w\");/* ConfigFile for OPC PDoItem param-s  */
       fprintf(fpdi,\"\\n[PDOItem]\\n\");
     }
/*<OPC*/
     fgets(fstr, 300, finp);         /* Skip the first line                 */
     unit=0; while(unit < umax)      /* OVER units must be after SCAN ones  */
     { fgets(fstr, 300, finp);
       sscanf(fstr,\"%d %d %d %d %d %s %s %s %s %d %d %d %s\",
              s00i, s01i, s02i, s03i, s04i, s05w, s06w, s07w, s08w, s09i,
              s10i, s11i, s12w);
       host = s01i; if(host == 99)   /* End of Unit ConfigFile              */
      { break;
       } else
       {   if(host > 9)
         { sprintf(estr,
     \" Reading 'Cnf_Unit.txt',\\n           Host number is too much, Unit: %d\",
                        unit); 
           dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
           dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
           dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
           sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
           dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
           while(1) { delay(1); }
         }
       }
       node = s02i; if((node >= (nmax + cnod)) || (node > 9))
       { sprintf(estr,
     \" Reading 'Cnf_Unit.txt',\\n           Node number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       }
       port = s03i; if((port >= (pmax + cpor)) || (port > 9))
       { sprintf(estr,
     \" Reading 'Cnf_Unit.txt',\\n           Port number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       }
       unit = s04i; if((unit >= (umax + (cnod * cpor))) || (unit > 64))
       { sprintf(estr,
     \" Reading 'Cnf_Unit.txt',\\n           Unit number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       }                             /* Only Scan Units are including       */
         if((node < nmax) && (port < pmax) &&
            (unit < umax) && (unit !=  99))
       { crat = (node * pmax) + (port * umax) + unit;
           if(crat < 10)
         { sprintf(str3,\"SCTmops1:Crate0%d%s\",crat,\".Stat:_original.._value\");
         } else
         { sprintf(str3,\"SCTmops1:Crate%d%s\" ,crat,\".Stat:_original.._value\");
         }
         strreplace(s07w,\"\\\"\",\"\");     sscanf(s07w,\"%x\",iden);
         strreplace(s08w,\"\\\"\",\"\");     sscanf(s08w,\"%x\",stat);
                                       dpSet(str3, stat);
/*
         sprintf(mstr,\"%d %d %d %d %d %s %s %s %s %d %d %d %s\",
                 s00i, s01i, s02i, s03i, s04i, s05w, s06w, s07w, s08w, s09i,
                 s10i, s11i, s12w);
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(2);
         dpGet(str1, str0);  sprintf(mstr,\" Unit0%d Name : %s\"   ,unit, str0);
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(1);
         dpGet(str2, str0);  sprintf(mstr,\" Unit0%d Iden : %s\"   ,unit, str0);
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(1);
         dpGet(str3, stat);  sprintf(mstr,\" Unit0%d Stat = %xh\"  ,unit, stat);
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(2);
         dpGet(str4, vadc);  sprintf(mstr,\" Unit0%d Vadc = %d\",unit, vadc);
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr); delay(1);
                                                                   /* Debug */
/*OPC>*/
           if((Serv == 0x4) || (Serv == 0x8))
         {   if(stat == 0x54)        /* Loading the CAN_parameters of ELMBs */
           { busn = (node * pmax) + port;
               if(busn < 10)
             { sprintf(bnam,\"Bus0%d\", busn);
             } else
             { sprintf(bnam,\"Bus%d\" , busn);
             }
               if(crat < 10)
             { fprintf(fopc,\"Crate0%d = %s %x NG\\n\", crat, bnam, iden);
             } else
             { fprintf(fopc,\"Crate%d = %s %x NG\\n\" , crat, bnam, iden);
             }
             fprintf(fpdo,\"%x = %s 404 IN 0 18\\n\", 0x180+iden, bnam);
             fprintf(fpdo,\"%x = %s 404 IN 0 48\\n\", 0x280+iden, bnam);
             fprintf(fpdo,\"%x = %s 404 IN 0 48\\n\", 0x380+iden, bnam);
             fprintf(fpdo,\"%x = %s 404 IN 0 48\\n\", 0x480+iden, bnam);
             fprintf(fpdo,\"%x = %s 404 IN 0 48\\n\", 0x200+iden, bnam);
             fprintf(fpdo,\"%x = %s 404 IN 0 48\\n\", 0x300+iden, bnam);
             fprintf(fpdo,\"%x = %s 401 OUT\\n\"    , 0x400+iden, bnam);
             fprintf(fpdo,\"%x = %s 401 OUT\\n\"    , 0x500+iden, bnam);
           }
         }
/*<OPC*/
       } unit++;
     } fclose(finp);
   } else
   { fclose(fopc);  fclose(fini);  fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
     sprintf(estr,\" 'Cnf_Unit.txt' File opening \");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
     sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   }
/*CHAN*/
     if((Serv == 0x0) || (Serv == 0x4) || (Serv == 0xC))
   { sprintf(mstr,\" PARA CONFIGs LOADING (~50 sec)...\");
   } else
   { sprintf(mstr,\" PARA OPC CONFIGs CREATING (~100 sec)...\");
   }
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(1);
   finp = fopen(\"Cnf_Para.txt\",\"r\"); /* ConfigFile reading from DB          */
   eror = ferror(finp);
     if(!eror)
   { fgets(fstr, 300, finp);         /* Skip the first line                 */
     mod1=0; while(mod1 < mmax)
     {   if(para < (lvmx + hvmx))
       { fgets(fstr, 300, finp);
       }
       sscanf(fstr,\"%d%d%s%s %s%s%s%s%s%s %s%s%s%s%s%s %s%s%s%s%s\",
       s00i, s01i, s02w, s03w,  s04w, s05w, s06w, s07w, s08w, s09w,
       s10w, s11w, s12w, s13w, s14w, s15w,  s16w, s17w, s18w, s19w, s20w);
/*
                                     strreplace(s02w,\"\\\"\",\"\");
       strreplace(s03w,\"\\\"\",\"\");     strreplace(s04w,\"\\\"\",\"\");
       strreplace(s05w,\"\\\"\",\"\");     strreplace(s06w,\"\\\"\",\"\");
       strreplace(s07w,\"\\\"\",\"\");     strreplace(s08w,\"\\\"\",\"\");
       strreplace(s09w,\"\\\"\",\"\");     strreplace(s10w,\"\\\"\",\"\");
       strreplace(s11w,\"\\\"\",\"\");     strreplace(s12w,\"\\\"\",\"\");
       strreplace(s13w,\"\\\"\",\"\");     strreplace(s14w,\"\\\"\",\"\");
       strreplace(s15w,\"\\\"\",\"\");     strreplace(s16w,\"\\\"\",\"\");
       strreplace(s17w,\"\\\"\",\"\");     strreplace(s18w,\"\\\"\",\"\");
       strreplace(s19w,\"\\\"\",\"\");     strreplace(s20w,\"\\\"\",\"\");
       sprintf(dstr,
       \" Pa: %d %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\",
       s00i, s01i, s02w, s03w,  s04w, s05w, s06w, s07w, s08w, s09w,
       s10w, s11w, s12w, s13w, s14w, s15w,  s16w, s17w, s18w, s19w, s20w);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\",dstr);delay(2);/* Debug */
         if(s01i >= 99999)           /* ModuleNumb - end of Para ConfigFile */
       { break;
       } else                        /* Looking for parameter Iden (address)*/
       { fidn = fopen(\"Cnf_Iden.txt\",\"r\");    /* ConfigFile reading from DB */
         eror = ferror(fidn);
           if(!eror)
         { fgets(fstr, 300, fidn);   /* Skip the first line                 */
           mod2=1; while(mod2 <= mmax)
           { fgets(fstr, 300, fidn);
             sscanf(fstr,
              \"%d%d %s%s%s%s %s%s%s%s%s %s%s%s %s%s%s%s%s  %d%d%d%d%d%s%s\",
                   s10i,s11i, s02e,s03e,s04e,s05e, s06e,s07e,s08e,s09e,s10e,
                              s11e,s12e,s13e,      s14e,s15e,s16e,s17e,s18e,
                              s19i,s20i,s21i,s22i,s23i,s24e,s25e);
/*
                                        strreplace(s02e,\"\\\"\",\"\");
             strreplace(s03e,\"\\\"\",\"\");  strreplace(s04e,\"\\\"\",\"\");
             strreplace(s05e,\"\\\"\",\"\");  strreplace(s06e,\"\\\"\",\"\");
             strreplace(s07e,\"\\\"\",\"\");  strreplace(s08e,\"\\\"\",\"\");
             strreplace(s09e,\"\\\"\",\"\");  strreplace(s10e,\"\\\"\",\"\");
             strreplace(s11e,\"\\\"\",\"\");  strreplace(s12e,\"\\\"\",\"\");
             strreplace(s13e,\"\\\"\",\"\");  strreplace(s14e,\"\\\"\",\"\");
             strreplace(s15e,\"\\\"\",\"\");  strreplace(s16e,\"\\\"\",\"\");
             strreplace(s17e,\"\\\"\",\"\");  strreplace(s18e,\"\\\"\",\"\");
                                        strreplace(s24e,\"\\\"\",\"\");
             strreplace(s25e,\"\\\"\",\"\");
             sprintf(dstr,
\"Id: %d %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %d %d %d %d %d %s %s\",
                   s10i,s11i, s02e,s03e,s04e,s05e, s06e,s07e,s08e,s09e,s10e,
                              s11e,s12e,s13e,      s14e,s15e,s16e,s17e,s18e,
                              s19i,s20i,s21i,s22i,s23i,s24e,s25e);
             dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(2);
                                                                   /* Debug */
               if(s11i >= 99999)     /* ModuleNumb - end of Iden ConfigFile */
             { fclose(fopc);  fclose(fini);
               fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
               sprintf(estr,
     \" Reading 'Cnf_Iden.txt',\\n           Can not find Si-Module: %d\", modl); 
               dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
               dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
               dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
               sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
               dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
               while(1) { delay(1); }
             } if(s01i == s11i)
             {                              strreplace(s02e,\"\\\"\",\"\");
               strreplace(s03e,\"\\\"\",\"\");    strreplace(s04e,\"\\\"\",\"\");
               strreplace(s05e,\"\\\"\",\"\");    strreplace(s06e,\"\\\"\",\"\");
               strreplace(s07e,\"\\\"\",\"\");    strreplace(s08e,\"\\\"\",\"\");
               strreplace(s09e,\"\\\"\",\"\");    strreplace(s10e,\"\\\"\",\"\");
               strreplace(s11e,\"\\\"\",\"\");    strreplace(s12e,\"\\\"\",\"\");
               strreplace(s13e,\"\\\"\",\"\");    strreplace(s14e,\"\\\"\",\"\");
               strreplace(s15e,\"\\\"\",\"\");    strreplace(s16e,\"\\\"\",\"\");
               strreplace(s17e,\"\\\"\",\"\");    strreplace(s18e,\"\\\"\",\"\");
                                            strreplace(s24e,\"\\\"\",\"\");
               strreplace(s25e,\"\\\"\",\"\");
               host = s19i; node = s20i; port = s21i; unit= s22i; chan= s23i;
               strreplace(s14e,\"Rack\" ,\"\"); sscanf(s14e,\"%d\", int3);
               strreplace(s15e,\"Crate\",\"\"); sscanf(s15e,\"%d\", int2);
//               strreplace(s16e,\"Card\" ,\"\"); sscanf(s16e,\"%d\", int1);
               rack = int3 - 1;  crat = int2 - 1;
/*
               card = int1 - 1;
                 switch(card )
               { case  0: lvca =  1;  lvix =  0;  hvca =  2;  hivo = 0; break;
                 case  1: lvca =  1;  hvix =  0;  hvca =  2;  hivo = 1; break;
                 case  2: lvca =  3;  lvix =  1;  hvca =  2;  hivo = 0; break;
                 case  3: lvca =  4;  lvix =  2;  hvca =  5;  hivo = 0; break;
                 case  4: lvca =  4;  hvix =  1;  hvca =  5;  hivo = 1; break;
                 case  5: lvca =  6;  lvix =  3;  hvca =  5;  hivo = 0; break;
                 case  6: lvca =  7;  lvix =  4;  hvca =  8;  hivo = 0; break;
                 case  7: lvca =  7;  hvix =  2;  hvca =  8;  hivo = 1; break;
                 case  8: lvca =  9;  lvix =  5;  hvca =  8;  hivo = 0; break;
                 case  9: lvca = 10;  lvix =  6;  hvca = 11;  hivo = 0; break;
                 case 10: lvca = 10;  hvix =  3;  hvca = 11;  hivo = 1; break;
                 case 11: lvca = 12;  lvix =  7;  hvca = 11;  hivo = 0; break;
                 case 12: lvca = 13;  lvix =  8;  hvca = 14;  hivo = 0; break;
                 case 13: lvca = 13;  hvix =  4;  hvca = 14;  hivo = 1; break;
                 case 14: lvca = 15;  lvix =  9;  hvca = 14;  hivo = 0; break;
                 case 15: lvca = 16;  lvix = 10;  hvca = 17;  hivo = 0; break;
                 case 16: lvca = 16;  hvix =  5;  hvca = 17;  hivo = 1; break;
                 case 17: lvca = 18;  lvix = 11;  hvca = 17;  hivo = 0; break;
                 default: lvca =  0;  lvix = -1;  hvca =  0;  hivo = 2;
               }
*/
/*
               sprintf(dstr,
      \"Host=%d Node=%d Port=%d; Rack=%d Crate=%d Chan=%d, LVst=%sh HVst=%sh\",
                             host, node, port, rack, unit, chan, s24e, s25e);
               dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr); delay(2);
                                                                   /* Debug */
               crat = (4 * rack) + unit;
                 if(crat < 10)
               {   if(chan < 10)
                 { sprintf(stri,
                   \"SCTmops1:Crate0%d.Channel0%d.LV_Stat:_original.._value\",
                                 crat, chan);
                 } else
                 { sprintf(stri,
                   \"SCTmops1:Crate0%d.Channel%d.LV_Stat:_original.._value\",
                                 crat, chan);
                 }
               } else
               {   if(chan < 10)
                 { sprintf(stri,
                   \"SCTmops1:Crate%d.Channel0%d.LV_Stat:_original.._value\",
                                 crat, chan);
                 } else
                 { sprintf(stri,
                   \"SCTmops1:Crate%d.Channel%d.LV_Stat:_original.._value\",
                                 crat, chan);
                 }
               }
               sscanf(s24e,\"%x\", int1); dpSet(stri, int1);
               strreplace(stri, \"LV_Stat\",\"HV_Stat\");
               sscanf(s25e,\"%x\", int1); dpSet(stri, int1);             
               break;
             } mod2++;
           } fclose(fidn);           /* Bus Name (Port ADdRess)             */
           busn = (node * pmax) + port;
             if(busn < 10)
           { sprintf(padr,\"Bus0%d\", busn);
           } else
           { sprintf(padr,\"Bus%d\" , busn);
           }
           crat = (node * pmax) + (port * umax) + unit;
             if(unit < 10)           /* Crate Name (Unit ADdRess)           */
           { sprintf(uadr,\"Crate0%d\", crat); 
           } else
           { sprintf(uadr,\"Crate%d\" , crat); 
           }
           lvpa=0; hvpa=0; para=0; while(para < (lvmx + hvmx))
           {   if(para == 0)
             { sprintf(str1,\"SCTmops1:%s%s\",uadr,\".Stat:_original.._value\"); 
               dpGet(str1, usts);
/*
               sprintf(dstr,\"Uname=%s St=%xh\", str1, usts);
               strreplace(dstr,\"_value\",\"\");
               dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr); delay(2);
                                                                   /* Debug */
                 switch(imod)        /* Identification mode for Chan Name   */
               { case  1: sprintf(str2,\"%s.%s.%s\",s02e,s03e,s04e);
                          break;
                 case  2: sprintf(str2,\"%s.%s.%s.%s\",s06e,s07e,s08e,s09e);
                          break;
                 case  3: sprintf(str2,\"%s.%s\",s11e,s12e);
                          break;
                 case  4: sprintf(str2,\"%s.%s.%s.%s\",s14e,s15e,s16e,s17e);
                          break;
                 default: sprintf(str2,\"\");
               }
             }                             strreplace(s02w,\"\\\"\",\"\");
             strreplace(s03w,\"\\\"\",\"\");     strreplace(s04w,\"\\\"\",\"\");
             strreplace(s05w,\"\\\"\",\"\");     strreplace(s06w,\"\\\"\",\"\");
             strreplace(s07w,\"\\\"\",\"\");     strreplace(s08w,\"\\\"\",\"\");
             strreplace(s19w,\"\\\"\",\"\");     strreplace(s10w,\"\\\"\",\"\");
             strreplace(s11w,\"\\\"\",\"\");     strreplace(s12w,\"\\\"\",\"\");
             strreplace(s13w,\"\\\"\",\"\");     strreplace(s14w,\"\\\"\",\"\");
             strreplace(s15w,\"\\\"\",\"\");     strreplace(s16w,\"\\\"\",\"\");
             strreplace(s17w,\"\\\"\",\"\");     strreplace(s18w,\"\\\"\",\"\");
             strreplace(s19w,\"\\\"\",\"\");     strreplace(s20w,\"\\\"\",\"\");
             sprintf(str0,\"%s\",s02w);      int1 = strlen(str0);
             strreplace(str0,\"HV\",\"\");     int2 = strlen(str0);
               if(int2 < int1)       /* HV set of parameters                */
             { sscanf(s25e,\"%x\",csts);
                 if(chan < 10)
               { sprintf(cadr,\"Channel0%d\",chan);        /* Chan ADdRess    */
               } else
               { sprintf(cadr,\"Channel%d\",chan);         /* Chan ADdRess    */
               }
                 if(hvpa == 0)       /* Module State == HV_chan State       */
               { sprintf(str3,\"SCTmops1:%s.%s.%s\", uadr, cadr,
                                             \"HV_Stat:_original.._value\");
/*
                 sprintf(dstr,\" HV: %s; Cs=%xh\", str3, csts);
                 dpSet(\"SCTmops1:Moni.Name:_original.._value\",dstr); delay(2);
                                                                   /* Debug */
                 dpSet(str3, csts);  /* Stat of siModule (Chan) to Chan_DP  */
               }
               sprintf(para_adr, s02w);             /* Loading DataPoints : */
                 if((Serv == 0x0) || (Serv == 0x4) || (Serv == 0xC))
               { sprintf(str4,\"SCTmops1:%s.%s.%s.%s\",
                               uadr,cadr,para_adr,\"Name:_original.._value\"); 
//               dpSet(str4, s02w);  /* Name of siModule (Chan) to Chan_DP  */
                   if(Load == 0x4)   /* Load Config State - Off             */
                 {   if((hvpa == 1) || (hvpa > 2))
                   { sscanf(s06w,\"%f\",s06f);
                     strreplace(str4,\"Name\",\"Send\");
                     dpSet(str4, s06f);
                       if(hvpa == 1)
                     { strreplace(str4,\"Send\",\"Recv\");
                       sscanf(s04w,\"%f\",s04f);
                       sscanf(s05w,\"%f\",s05f);
                       sscanf(s07w,\"%f\",s07f);
                       sscanf(s08w,\"%f\",s08f);
                       dpSet(str4, s06f);
                       setAlerts(str4, s04f, s05f, s07f, s08f);
                     }
                   } else
                   {   if(hvpa == 0)
                     { sscanf(s06w,\"%x\",s06i);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s06i);
                     } else
                     { sscanf(s04w,\"%f\",s04f);
                       sscanf(s05w,\"%f\",s05f);
                       sscanf(s06w,\"%f\",s06f);
                       sscanf(s07w,\"%f\",s07f);
                       sscanf(s08w,\"%f\",s08f);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s06f);
                       setAlerts(str4, s04f, s05f, s07f, s08f);
                     }
                   }
/*
                   sprintf(dstr,\"OF: %s; N=%3.1f, W=%3.1f, F=%3.1f \",
                                     str4, s06f, s07f, s08f);
                   strreplace(dstr,\":_original.._value\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                         delay(1); /* Debug */
                 }
                   if(Load == 0x8)   /* Load Config State - Standby         */
                 {   if((hvpa == 1) || (hvpa > 2))
                   { sscanf(s12w,\"%f\",s12f);
                     strreplace(str4,\"Name\",\"Send\");
                     dpSet(str4, s12f);
                       if(hvpa == 1)
                     { strreplace(str4,\"Send\",\"Recv\");
                       sscanf(s10w,\"%f\",s10f);
                       sscanf(s11w,\"%f\",s11f);
                       sscanf(s13w,\"%f\",s13f);
                       sscanf(s14w,\"%f\",s14f);
                       dpSet(str4, s12f);
                       setAlerts(str4, s10f, s11f, s13f, s14f);
                     }
                   } else
                   {   if(hvpa == 0)
                     { sscanf(s12w,\"%x\",s12i);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s12i);
                     } else
                     { sscanf(s10w,\"%f\",s10f);
                       sscanf(s11w,\"%f\",s11f);
                       sscanf(s12w,\"%f\",s12f);
                       sscanf(s13w,\"%f\",s13f);
                       sscanf(s14w,\"%f\",s14f);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s12f);
                       setAlerts(str4, s10f, s11f, s13f, s14f);
                     }
                   }
/*
                   sprintf(dstr,\"SB: %s; N=%3.1f, W=%3.1f, F=%3.1f \",
                                     str4, s12f, s13f, s14f);
                   strreplace(dstr,\":_original.._value\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                         delay(1); /* Debug */
                 }
                   if(Load == 0xC)   /* Load Config State - On              */
                 {   if((hvpa == 1) || (hvpa > 2))
                   { sscanf(s18w,\"%f\",s18f);
                     strreplace(str4,\"Name\",\"Send\");
                     dpSet(str4, s18f);
                       if(hvpa == 1)
                     { strreplace(str4,\"Send\",\"Recv\");
                       sscanf(s16w,\"%f\",s16f);
                       sscanf(s17w,\"%f\",s17f);
                       sscanf(s19w,\"%f\",s19f);
                       sscanf(s20w,\"%f\",s20f);
                       dpSet(str4, s18f);
                       setAlerts(str4, s16f, s17f, s19f, s20f);
                     }
                   } else
                   {   if(hvpa == 0)
                     { sscanf(s18w,\"%x\",s18i);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s18i);
                     } else
                     { sscanf(s16w,\"%f\",s16f);
                       sscanf(s17w,\"%f\",s17f);
                       sscanf(s18w,\"%f\",s18f);
                       sscanf(s19w,\"%f\",s19f);
                       sscanf(s20w,\"%f\",s20f);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s18f);
                       setAlerts(str4, s16f, s17f, s19f, s20f);
                     }
                   }
/*
                   sprintf(dstr,\"ON: %s; N=%3.1f, W=%3.1f, F=%3.1f \",
                                     str4, s18f, s19f, s20f);
                   strreplace(dstr,\":_original.._value\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                         delay(1); /* Debug */
                 }
                   if((Serv == 0x8) || (Serv == 0xC))
                 { ;
//                   delay(0,05);      /* For ELMB - if OPC-server is running */
                 }
               }
/*OPC>*/
               sprintf(str4,\"SCTmops1:%s.%s.%s.%s\",uadr,cadr,para_adr,\"Send\"); 
                                     /* Str5/6 - OPC Item Name for Send/Recv*/
               sprintf(cadr,\"Chan%d\", chan);   /* Channel OPC ADdRess       */
               sprintf(str5,\"%s_%s_Send%s\", uadr, para_adr, cadr);
               sprintf(str6,\"%s_%s_Recv%s\", uadr, para_adr, cadr);
                                     /* Str7/8 - Full Item Name for Connect.*/
               sprintf(str7,\"%s.%s.%s_%s_Send%s\",padr,uadr,uadr,para_adr,cadr);
               sprintf(str8,\"%s.%s.%s_%s_Recv%s\",padr,uadr,uadr,para_adr,cadr);
/*
               dpSet(\"SCTmops1:Moni.Name:_original.._value\", str8);
                                                         delay(2); /* Debug */
                                     /* If Unit and Chan are included       */
                 if(((usts & 0x4) > 0) && ((csts & 0x4) > 0) &&
                        ((Serv == 0x4) || (Serv == 0x8)))
               {   switch(hvpa)
                 { case  0:          /* HVchStat                            */
//                            fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
//                                    str5, uadr, 0x2600 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 1\\n\",
                                      str6, uadr, 0x300+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                            }
                            break;
                   case  1:          /* HVchVolt                            */
                            fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI2\\n\",
                                    str5, uadr, 0x2700 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI2\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1.0); // ? /8 ?
//                              dpConnect(\"OneToOne_toSend\", str4);
                            }
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI2 ALL 2\\n\",
                                      str6, uadr, 0x300+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
//                            { strreplace(str4,\"Comm\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI2\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 1.0 / 8.0);
//                              dpConnect(\"HVchVolt_toData\", str4);
                            }
                            break;
                   case  2:          /* HVchCurr                            */
//                            fprintf(fsdi,\"%s  = %s %x 3 IO VT_UI2\\n\",
//                                    str5, uadr, 0x2600 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI2 ALL 4\\n\" ,
                                      str6, uadr, 0x300+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI2\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 1.0);
//                              dpConnect(\"OneToOne_toData\", str4);
                            }
                            break;
                   case  3:          /* HVchITrp                            */
                            fprintf(fsdi,\"%s  = %s %x 2 IO VT_UI2\\n\",
                                    str5, uadr, 0x2700 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI2\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1.0);
//                              dpConnect(\"OneToOne_toSend\", str4);
                            }
//                            fprintf(fpdi,\"s  = %s %x VT_UI2 %d   2\\n\",
//                                    str6, uadr, 0x280+iden, chan);
                            break;
                   case  4:          /* HVchRamp                            */
                            fprintf(fsdi,\"%s  = %s %x 3 IO VT_UI1\\n\",
                                    str5, uadr, 0x2700 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1.0);
//                              dpConnect(\"OneToOne_toSend\", str4);
                            }
//                            fprintf(fpdi,\"%s  = %s %x VT_UI1 %d   3\\n\",
//                                    str6, uadr, 0x280+iden, chan);
                            break;
                   default: ;
                 }
/*
                 sprintf(dstr,
                         \" Rk=%d Cr=%d Ca=%d Ix=%d %s_%s_%s:%s Us=%xh Cs=%xh\",
                 rack, crat, card, hvix, uadr,cadr,para_adr,s02w, usts, csts);
                 dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                         delay(1); /* Debug */
               }
/*<OPC*/
                 if(hvpa < hvmx)
               { hvpa++;
               } else
               { fclose(fopc);  fclose(fini);
                 fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
                 sprintf(estr,
 \" HV_para - %s number in 'Cnf_Para' list:%d\\n           is more than Max=%d\",
                               s02w, para+1, hvmx);
                 dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
                 dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
                 dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
                 sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
                 dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
                 while(1) { delay(1); }
               }

             } else                  /* LV set of parameters                */
             { sscanf(s24e,\"%x\",csts);    /* LV_chan STate & STatuS         */
                 if(chan < 10)
               { sprintf(cadr,\"Channel0%d\",chan);        /* Chan ADdRess    */
               } else
               { sprintf(cadr,\"Channel%d\",chan);         /* Chan ADdRess    */
               }                     /* Module Stat is HV-chan Stat         */
                 if(lvpa == 0)       /* Module State == HV_chan State       */
               { sprintf(str3,\"SCTmops1:%s.%s.%s\", uadr, cadr,
                                             \"LV_Stat:_original.._value\");
//                 dpSet(str3, csts);/* Stat of siModule (Chan) to Chan_DP  */
               }
               sprintf(para_adr, s02w);             /* Loading DataPoints : */
                 if((Serv == 0x0) || (Serv == 0x4) || (Serv == 0xC))
               { sprintf(str4,\"SCTmops1:%s.%s.%s.%s\",
                               uadr,cadr,para_adr,\"Name:_original.._value\"); 
//               dpSet(str4, s02w);  /* Name of siModule (Chan) to Chan_DP  */
                   if(Load == 0x4)   /* Load Config State - Off             */
                 {   if((lvpa == 1) || (lvpa ==  5) || (lvpa == 9) ||
                                       (lvpa == 11) || (lvpa > 14))
                   {   if(lvpa < 19)
                     { sscanf(s06w,\"%f\",s06f);
                       strreplace(str4,\"Name\",\"Send\");
                       dpSet(str4, s06f);
                     } else
                     { sscanf(s06w,\"%x\",s06i);
                       strreplace(str4,\"Name\",\"Send\");
                       dpSet(str4, s06i);
                     }
                       if((lvpa == 1) || (lvpa ==  5) || (lvpa == 9) ||
                                         (lvpa == 11))
                     { sscanf(s04w,\"%f\",s04f);
                       sscanf(s05w,\"%f\",s05f);
                       sscanf(s07w,\"%f\",s07f);
                       sscanf(s08w,\"%f\",s08f);
                       strreplace(str4,\"Send\",\"Recv\");
                       dpSet(str4, s06f);
                       setAlerts(str4, s04f, s05f, s07f, s08f);
                     }
                   } else
                   {   if(lvpa == 0)
                     { sscanf(s06w,\"%x\",s06i);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s06i);
                     } else
                     { sscanf(s04w,\"%f\",s04f);
                       sscanf(s05w,\"%f\",s05f);
                       sscanf(s06w,\"%f\",s06f);
                       sscanf(s07w,\"%f\",s07f);
                       sscanf(s08w,\"%f\",s08f);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s06f);
                       setAlerts(str4, s04f, s05f, s07f, s08f);
                     }
                   }
                 }
                   if(Load == 0x8)   /* Load Config State - Standby         */
                 {   if((lvpa == 1) || (lvpa ==  5) || (lvpa == 9) ||
                                       (lvpa == 11) || (lvpa > 14))
                   {   if(lvpa < 19)
                     { sscanf(s12w,\"%f\",s12f);
                       strreplace(str4,\"Name\",\"Send\");
                       dpSet(str4, s12f);
                     } else
                     { sscanf(s12w,\"%x\",s12i);
                       strreplace(str4,\"Name\",\"Send\");
                       dpSet(str4, s12i);
                     }
                       if((lvpa == 1) || (lvpa ==  5) || (lvpa == 9) ||
                                         (lvpa == 11))
                     { sscanf(s10w,\"%f\",s10f);
                       sscanf(s11w,\"%f\",s11f);
                       sscanf(s13w,\"%f\",s13f);
                       sscanf(s14w,\"%f\",s14f);
                       strreplace(str4,\"Send\",\"Recv\");
                       dpSet(str4, s12f);
                       setAlerts(str4, s10f, s11f, s13f, s14f);
                     }
                   } else
                   {   if(lvpa == 0)
                     { sscanf(s12w,\"%x\",s12i);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s12i);
                     } else
                     { sscanf(s10w,\"%f\",s10f);
                       sscanf(s11w,\"%f\",s11f);
                       sscanf(s12w,\"%f\",s12f);
                       sscanf(s13w,\"%f\",s13f);
                       sscanf(s14w,\"%f\",s14f);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s12f);
                       setAlerts(str4, s10f, s11f, s13f, s14f);
                     }
                   }
                 }
                   if(Load == 0xC)   /* Load Config State - On              */
                 {   if((lvpa == 1) || (lvpa ==  5) || (lvpa == 9) ||
                                       (lvpa == 11) || (lvpa > 14))
                   {   if(lvpa < 19)
                     { sscanf(s18w,\"%f\",s18f);
                       strreplace(str4,\"Name\",\"Send\");
                       dpSet(str4, s18f);
                     } else
                     { sscanf(s18w,\"%x\",s18i);
                       strreplace(str4,\"Name\",\"Send\");
                       dpSet(str4, s18i);
                     }
                       if((lvpa == 1) || (lvpa ==  5) || (lvpa == 9) ||
                                         (lvpa == 11))
                     { sscanf(s16w,\"%f\",s16f);
                       sscanf(s17w,\"%f\",s17f);
                       sscanf(s19w,\"%f\",s19f);
                       sscanf(s20w,\"%f\",s20f);
                       strreplace(str4,\"Send\",\"Recv\");
                       dpSet(str4, s18f);
                       setAlerts(str4, s16f, s17f, s19f, s20f);
                     }
                   } else
                   {   if(lvpa == 0)
                     { sscanf(s18w,\"%x\",s18i);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s18i);
                     } else
                     { sscanf(s16w,\"%f\",s16f);
                       sscanf(s17w,\"%f\",s17f);
                       sscanf(s18w,\"%f\",s18f);
                       sscanf(s19w,\"%f\",s19f);
                       sscanf(s20w,\"%f\",s20f);
                       strreplace(str4,\"Name\",\"Recv\");
                       dpSet(str4, s18f);
                       setAlerts(str4, s16f, s17f, s19f, s20f);
                     }
                   }
                 }
                   if((Serv == 0x8) || (Serv == 0xC))
                 { ;
//                   delay(0,05);      /* For ELMB - if OPC-server is running */
                 }
               }
/*OPC>*/
               sprintf(str4,\"SCTmops1:%s.%s.%s.%s\",uadr,cadr,para_adr,\"Send\"); 
                                     /* Str5/6 - OPC Item Name for Send/Recv*/
               sprintf(cadr,\"Chan%d\", chan);   /* Channel OPC ADdRess       */
               sprintf(str5,\"%s_%s_Send%s\", uadr, para_adr, cadr);
               sprintf(str6,\"%s_%s_Recv%s\", uadr, para_adr, cadr);
                                     /* Str7/8 - Full Item Name for Connect.*/
               sprintf(str7,\"%s.%s.%s_%s_Send%s\",padr,uadr,uadr,para_adr,cadr);
               sprintf(str8,\"%s.%s.%s_%s_Recv%s\",padr,uadr,uadr,para_adr,cadr);
/*
               dpSet(\"SCTmops1:Moni.Name:_original.._value\", str4);
                                                         delay(2); /* Debug */
                                     /* If Unit and Chan are included       */
                 if(((usts & 0x4) > 0) && ((csts & 0x4) > 0) &&
                        ((Serv == 0x4) || (Serv == 0x8)))
               {   switch(lvpa)
                 { case  0:          /* LVchStat                            */
//                            fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
//                                    str5, uadr, 0x2400 + chan);
//                              if(Serv == 0x8)
//                            { setOPCAddress(str4, str7,
//                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                            }
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 1\\n\",
                                      str6, uadr, 0x280+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                            }
                            break;
                   case  1:          /* LVch_Vcc                            */
                            fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1000.0 / 20.0);
//                              dpConnect(\"LVch_Vcc_toSend\", str4);
                            }
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 2\\n\",
                                      str6, uadr, 0x280+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
//                              strreplace(str4,\"Comm\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 20.0 / 1000.0);
//                              dpConnect(\"LVch_Vcc_toData\", str4);
                            }
                            break;
                   case  2:            /* LVps_Vcc                          */
//                            fprintf(fsdi,\"%s  = %s %x 3 IO VT_UI1\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 3\\n\",
                                      str6, uadr, 0x280+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 50.0 / 1000.0);
//                              dpConnect(\"LVps_Vcc_toData\", str4);
                            }
                            break;
                   case  3:            /* LVretVcc                          */
//                            fprintf(fsdi,\"%s  = %s %x 4 IO VT_UI1\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 4\\n\",
                                      str6, uadr, 0x280+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 20.0 / 1000.0);
//                              dpConnect(\"LVretVcc_toData\", str4);
                            }
                            break;
                   case  4:            /* LVch_Icc                          */
//                            fprintf(fsdi,\"%s  = %s %x 5 IO VT_UI1\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 5\\n\",
                                      str6, uadr, 0x280+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 10.0);
//                              dpConnect(\"LVch_Icc_toData\", str4);
                            }
                            break;
                   case  5:            /* LVch_Vdd                          */
                            fprintf(fsdi,\"%s  = %s %x 2 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1000.0 / 20.0);
//                              dpConnect(\"LVch_Vdd_toSend\", str4);
                            }
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 6\\n\",
                                      str6, uadr, 0x280+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
//                            { strreplace(str4,\"Comm\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 20.0 / 1000.0);
//                              dpConnect(\"LVch_Vdd_toData\", str4);
                            }
                            break;
                   case  6:            /* LVps_Vdd                          */
//                            fprintf(fsdi,\"%s  = %s %x 7 IO VT_UI1\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 7\\n\",
                                      str6, uadr, 0x280+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 50.0 / 1000.0);
//                              dpConnect(\"LVps_Vdd_toData\", str4);
                            }
                            break;
                   case  7:            /* LVretVdd                          */
//                            fprintf(fsdi,\"%s  = %s %x 8 IO VT_UI1\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 1\\n\",
                                      str6, uadr, 0x380+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 20.0 / 1000.0);
//                              dpConnect(\"LVretVdd_toData\", str4);
                            }
                            break;
                   case  8:            /* LVch_Idd                          */
//                            fprintf(fsdi,\"%s  = %s %x 9 IO VT_UI1\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 2\\n\",
                                      str6, uadr, 0x380+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 10.0);
//                              dpConnect(\"LVch_Idd_toData\", str4);
                            }
                            break;
                   case  9:            /* LVchVCSV                          */
                            fprintf(fsdi,\"%s  = %s %x 3 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1000.0 / 40.0);
//                              dpConnect(\"LVchVCSV_toSend\", str4);
                            }
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 3\\n\",
                                      str6, uadr, 0x380+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
//                            { strreplace(str4,\"Comm\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 40.0 / 1000.0);
//                              dpConnect(\"LVchVCSV_toData\", str4);
                            }
                            break;
                   case 10:            /* LVchVCSI                          */
//                            fprintf(fsdi,\"%s  = %s %x a IO VT_UI1\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 4\\n\",
                                      str6, uadr, 0x380+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 1.0 / 25.0);
//                              dpConnect(\"LVchVCSI_toData\", str4);
                            }
                            break;
                   case 11:            /* LVchPINV                          */
                            fprintf(fsdi,\"%s  = %s %x 4 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1000.0 / 50.0);
//                              dpConnect(\"LVchPINV_toSend\", str4);
                            }
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 5\\n\",
                                      str6, uadr, 0x380+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
//                            { strreplace(str4,\"Comm\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 50.0 / 1000.0);
//                              dpConnect(\"LVchPINV_toData\", str4);
                            }
                            break;
                   case 12:            /* LVchPINI                          */
//                            fprintf(fsdi,\"%s  = %s %x d IO VT_UI1\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI1 ALL 6\\n\",
                                      str6, uadr, 0x380+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 1.0 / 100.0);
//                              dpConnect(\"LVchPINI_toData\", str4);
                            }
                            break;
                   case 13:            /* MOch_Tm0                          */
//                            fprintf(fsdi,\"%s  = %s %x e IO VT_UI2\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI2 ALL 1\\n\",
                                      str6, uadr, 0x480+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI2\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 1.0);
//                              dpConnect(\"MOch_Tm0_toData\", str4);
                            }
                            break;
                   case 14:            /* MOch_Tm1                          */
//                            fprintf(fsdi,\"%s  = %s %x f IO VT_UI2\\n\",
//                                    str5, uadr, 0x2500 + chan);
                              if(chan == 0)
                            { strreplace(str6,\"Chan0\",\"Chan\");
                              fprintf(fpdi,\"%s   = %s %x VT_UI2 ALL 3\\n\",
                                      str6, uadr, 0x480+iden);
                            }
                              if(Serv == 0x8)
                            { strreplace(str4,\"Send\",\"Recv\");
                              setOPCAddress(str4, str8,
                                           \"VT_UI2\",\"IN\",\"CANopen\",1,\"Moni\");
                              setConversion(str4, \"IN\", 0.0, 1.0);
//                              dpConnect(\"MOch_Tm1_toData\", str4);
                            }
                            break;
                   case 15:            /* LVchDTrp                          */
                            fprintf(fsdi,\"%s  = %s %x 5 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1.0 / 2.0);
//                              dpConnect(\"LVchDTrp_toSend\", str4);
                            }
//                            fprintf(fpdi,\"%s  = %s %x VT_UI1 %d   1\\n\",
//                                    str6, uadr, 0x180+iden, chan);
                            break;
                   case 16:            /* LVchCTrp                          */
                            fprintf(fsdi,\"%s  = %s %x 6 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 0.0, 1.0 / 2.0);
//                              dpConnect(\"LVchCTrp_toSend\", str4);
                            }
//                            fprintf(fpdi,\"%s  = %s %x VT_UI1 %d   2\\n\",
//                                    str6, uadr, 0x180+iden, chan);
                            break;
                   case 17:            /* LVchTLim                          */
                            fprintf(fsdi,\"%s  = %s %x 7 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 128.0, 1.0);
//                              dpConnect(\"LVchTLim_toSend\", str4);
                            }
//                            fprintf(fpdi,\"%s  = %s %x VT_UI1 %d   3\\n\",
//                                    str6, uadr, 0x180+iden, chan);
                            break;
                   case 18:            /* LVchTTrp                          */
                            fprintf(fsdi,\"%s  = %s %x 8 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                              strreplace(str4,\"Send\",\"Comm\");
                              setConversion(str4, \"OUT\", 128.0, 1.0);
//                              dpConnect(\"LVchTTrp_toSend\", str4);
                            }
//                            fprintf(fpdi,\"%s  = %s %x VT_UI1 %d   4\\n\",
//                                    str6, uadr, 0x180+iden, chan);
                            break;
                   case 19:            /* LVchCLKS                          */
                            fprintf(fsdi,\"%s  = %s %x 9 IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                            }
//                            fprintf(fpdi,\"%s  = %s %x VT_UI1 %d   5\\n\",
//                                    str6, uadr, 0x180+iden, chan);
                            break;
                   case 20:            /* LVchCLKR                          */
                            fprintf(fsdi,\"%s  = %s %x a IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                            }
//                            fprintf(fpdi,\"%s  = %s %x VT_UI1 %d   6\\n\",
//                                    str6, uadr, 0x180+iden, chan);
                            break;
                   case 21:            /* LVchVOut                          */
                            fprintf(fsdi,\"%s  = %s %x b IO VT_UI1\\n\",
                                    str5, uadr, 0x2500 + chan);
                              if(Serv == 0x8)
                            { setOPCAddress(str4, str7,
                                           \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                            }
//                            fprintf(fpdi,\"%s  = %s %x VT_UI1 %d   7\\n\",
//                                    str6, uadr, 0x180+iden, chan);
                            break;
                   default: ;
                 }
/*
                 sprintf(dstr,
                         \" Rk=%d Cr=%d Ca=%d Ix=%d %s_%s_%s:%s Us=%xh Cs=%xh\",
                 rack, crat, card, lvix, uadr,cadr,para_adr,s02w, usts, csts);
                 dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                         delay(1); /* Debug */
               }
/*<OPC*/              
                 if(lvpa < lvmx)
               { lvpa++;
               } else
               { fclose(fopc);  fclose(fini);
                 fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
                 sprintf(estr,
 \" LV_para - %s number in 'Cnf_Para' list:%d\\n           is more than Max=%d\",
                               s02w, para+1, lvmx);
                 dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
                 dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
                 dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
                 sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
                 dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
                 while(1) { delay(1); }
               }
             }             
               if(s01i != mod2)
             { fclose(fopc);  fclose(fini);
               fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
               setValue(\"ErorIndi\",\"backCol\",\"Red\");
               sprintf(estr,
\" ModlNumb in 'Cnf_Para': %d for Para=%d\\n           not equal to ModlNumb in 'Cnf_Iden': %d\",
                             s01i, para, mod2);
               dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
               dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
               dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
               sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
               dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
               while(1) { delay(1); }
             }
             fgets(fstr, 300, finp);
             sscanf(fstr,\"%d%d%s%s %s%s%s%s%s%s %s%s%s%s%s%s %s%s%s%s%s\",
             s00i, s01i, s02w, s03w,  s04w, s05w, s06w, s07w, s08w, s09w,
             s10w, s11w, s12w, s13w, s14w,s15w,  s16w, s17w, s18w, s19w,s20w);
/*
                                           strreplace(s02w,\"\\\"\",\"\");
             strreplace(s03w,\"\\\"\",\"\");     strreplace(s04w,\"\\\"\",\"\");
             strreplace(s05w,\"\\\"\",\"\");     strreplace(s06w,\"\\\"\",\"\");
             strreplace(s07w,\"\\\"\",\"\");     strreplace(s08w,\"\\\"\",\"\");
             strreplace(s09w,\"\\\"\",\"\");     strreplace(s10w,\"\\\"\",\"\");
             strreplace(s11w,\"\\\"\",\"\");     strreplace(s12w,\"\\\"\",\"\");
             strreplace(s13w,\"\\\"\",\"\");     strreplace(s14w,\"\\\"\",\"\");
             strreplace(s15w,\"\\\"\",\"\");     strreplace(s16w,\"\\\"\",\"\");
             strreplace(s17w,\"\\\"\",\"\");     strreplace(s18w,\"\\\"\",\"\");
             strreplace(s19w,\"\\\"\",\"\");     strreplace(s20w,\"\\\"\",\"\");
             sprintf(dstr,
        \" Pa: %d %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\",
             s00i, s01i, s02w, s03w,  s04w, s05w, s06w, s07w, s08w, s09w,
             s10w, s11w, s12w, s13w, s14w,s15w,  s16w, s17w, s18w, s19w,s20w);
             dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(2);
                                                                   /* Debug */
               if(s01i >= 99999)     /* ModuleNumb - end of Para ConfigFile */
             { break;
             } para++;
           }
         } else
         { fclose(fopc);  fclose(fini);
           fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
           sprintf(estr,\" 'Cnf_Iden.txt' File opening \");
           dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
           dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
           dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
           sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
           dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
           while(1) { delay(1); }
         }
       } mod1++;
     } fclose(finp);
/*CARD*/
     if((Serv == 0x0) || (Serv == 0x4) || (Serv == 0xC))
   { sprintf(mstr,\" CARD CONFIGs LOADING (~10 sec)...\");
   } else
   { sprintf(mstr,\" CARD OPC CONFIGs CREATING (~10 sec)...\");
   }
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(1);
   finp = fopen(\"Cnf_Card.txt\",\"r\"); /* Card(s) parameters reading from DB  */
   eror = ferror(finp);
     if(!eror)
   { fgets(fstr, 300, finp);         /* Skip the first line                 */
     maxp = (2 * lvca_max) + hvca_max;    /* MaxP - MaxPara-s in 3 Cards    */
     grup=0; para=0; lvpa=0; hvpa=0;
     unit=0; while(unit < umax)
     { fgets(fstr, 300, finp);
/*
       sprintf(dstr,\" Unit=%d, LVca=%d LVpa=%d, HVca=%d HVpa=%d\",
                      unit, lvca, lvpa, hvca, hvpa);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\",dstr);delay(2);/* Debug */
       sscanf(fstr,
       \"%d %d%d%d%s%s %d%d%d%d%s %s%s%s%s%s%s %s%s%s%s%s%s %s%s%s%s%s\",
       s00i,  s01i, s02i, s03i, s04w, s05w,  s06i, s07i, s08i, s09i, s10w,
       s11w, s12w, s13w, s14w, s15w, s16w,  s17w, s18w, s19w, s20w, s21w,s22w,
       s23w, s24w, s25w, s26w, s27w);
                                        strreplace(s04w,\"\\\"\",\"\");
       strreplace(s05w,\"\\\"\",\"\");        strreplace(s10w,\"\\\"\",\"\");
       strreplace(s11w,\"\\\"\",\"\");        strreplace(s12w,\"\\\"\",\"\");
       strreplace(s13w,\"\\\"\",\"\");        strreplace(s14w,\"\\\"\",\"\");
       strreplace(s15w,\"\\\"\",\"\");        strreplace(s16w,\"\\\"\",\"\");
       strreplace(s17w,\"\\\"\",\"\");        strreplace(s18w,\"\\\"\",\"\");
       strreplace(s19w,\"\\\"\",\"\");        strreplace(s20w,\"\\\"\",\"\");
       strreplace(s21w,\"\\\"\",\"\");        strreplace(s22w,\"\\\"\",\"\");
       strreplace(s23w,\"\\\"\",\"\");        strreplace(s24w,\"\\\"\",\"\");
       strreplace(s25w,\"\\\"\",\"\");        strreplace(s26w,\"\\\"\",\"\");
       strreplace(s27w,\"\\\"\",\"\");
/*
       sprintf(dstr,
\" Ca: %d %d %d %d %s %s %d %d %d %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\",
       s00i,  s01i, s02i, s03i, s04w, s05w,  s06i, s07i, s08i, s09i, s10w,
       s11w, s12w, s13w, s14w, s15w, s16w,  s17w, s18w, s19w, s20w, s21w,s22w,
       s23w, s24w, s25w, s26w, s27w);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\",dstr);delay(2);/* Debug */
       host = s06i; if(host == 99)   /* End of Unit ConfigFile              */
       { break;
       } else
       {   if(host > 9)
         { sprintf(estr,
     \" Reading 'Cnf_Card.txt',\\n           Host number is too much, Unit: %d\",
                        unit); 
           dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
           dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
           dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
           sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
           dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
           while(1) { delay(1); }
         }
       }
       node = s07i; if(node > nmax)
       { sprintf(estr,
     \" Reading 'Cnf_Card.txt',\\n           Node number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       } if(node == 9)
       { break;
       }
       port = s08i; if(port > pmax)
       { sprintf(estr,
     \" Reading 'Cnf_Card.txt',\\n           Port number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       } if(port == 9)
       { break;
       }
       unit = s09i; if(unit > umax)
       { sprintf(estr,
     \" Reading 'Cnf_Card.txt',\\n           Unit number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       } if(unit == 99)
       { break;
       }
         if((node < nmax) && (port < pmax) && (unit < umax) && (unit !=  99))
       { rack = s01i - 1;  crat = s02i - 1;  card = s03i - 1;
           switch(card)
         { case  0: lvca =  1;  lvix =  0;  hvca =  2;  hivo = 0; break;
           case  1: lvca =  1;  hvix =  0;  hvca =  2;  hivo = 1; break;
           case  2: lvca =  3;  lvix =  1;  hvca =  2;  hivo = 0; break;
           case  3: lvca =  4;  lvix =  2;  hvca =  5;  hivo = 0; break;
           case  4: lvca =  4;  hvix =  1;  hvca =  5;  hivo = 1; break;
           case  5: lvca =  6;  lvix =  3;  hvca =  5;  hivo = 0; break;
           case  6: lvca =  7;  lvix =  4;  hvca =  8;  hivo = 0; break;
           case  7: lvca =  7;  hvix =  2;  hvca =  8;  hivo = 1; break;
           case  8: lvca =  9;  lvix =  5;  hvca =  8;  hivo = 0; break;
           case  9: lvca = 10;  lvix =  6;  hvca = 11;  hivo = 0; break;
           case 10: lvca = 10;  hvix =  3;  hvca = 11;  hivo = 1; break;
           case 11: lvca = 12;  lvix =  7;  hvca = 11;  hivo = 0; break;
           case 12: lvca = 13;  lvix =  8;  hvca = 14;  hivo = 0; break;
           case 13: lvca = 13;  hvix =  4;  hvca = 14;  hivo = 1; break;
           case 14: lvca = 15;  lvix =  9;  hvca = 14;  hivo = 0; break;
           case 15: lvca = 16;  lvix = 10;  hvca = 17;  hivo = 0; break;
           case 16: lvca = 16;  hvix =  5;  hvca = 17;  hivo = 1; break;
           case 17: lvca = 18;  lvix = 11;  hvca = 17;  hivo = 0; break;
           default: lvca =  0;  lvix = -1;  hvca =  0;  hivo = 2;
         }
         busn = (node * pmax) + port;
           if(busn < 10)
         { sprintf(padr,\"Bus0%d\", busn);
         } else
         { sprintf(padr,\"Bus%d\" , busn);
         }
         crat = (node * pmax) + (port * umax) + unit;
           if(unit < 10)             /* Crate Name (Unit ADdRess)           */
         { sprintf(uadr,\"Crate0%d\", crat); 
         } else
         { sprintf(uadr,\"Crate%d\" , crat); 
         }
           if(hivo == 0)
         {   if(lvix < 10)
           { sprintf(para_adr,\"LV_card0%d.%s\", lvix, s04w);
           } else
           { sprintf(para_adr,\"LV_card%d.%s\" , lvix, s04w);
           }
         } else
         {   if(hvix < 10)
           { sprintf(para_adr,\"HV_card0%d.%s\", hvix, s04w);
           } else
           { sprintf(para_adr,\"HV_card%d.%s\" , hvix, s04w);
           }
         }                                          /* Loading DataPoints : */
           if((Serv == 0x0) || (Serv == 0x4) || (Serv == 0xC))
         { sprintf(str1,
                 \"SCTmops1:%s.%s.%s\",uadr,para_adr,\"Name:_original.._value\");
             if(hivo == 0)
           {   if(Load == 0x4)       /* Load Config State - Off             */
             {   if((lvpa == 3) || (lvpa == 4))
               {   if(lvpa == 3)
                 { sscanf(s13w,\"%x\",s13i);
                   strreplace(str1,\"Name\",\"Send\");
                   dpSet(str1, s13i);
                 } else
                 { sscanf(s13w,\"%f\",s13f);
                   strreplace(str1,\"Name\",\"Send\");
                   dpSet(str1, s13f);
                 }
               } else
               {   if((lvpa == 1) || (lvpa == 2))
                 { sscanf(s11w,\"%f\",s11f);
                   sscanf(s12w,\"%f\",s12f);
                   sscanf(s13w,\"%f\",s13f);
                   sscanf(s14w,\"%f\",s14f);
                   sscanf(s15w,\"%f\",s15f);
                   strreplace(str1,\"Name\",\"Recv\");
                   dpSet(str1, s13f);
                   setAlerts(str1, s11f, s12f, s14f, s15f);
                 } else
                 { sscanf(s13w,\"%x\",s13i);
                   strreplace(str1,\"Name\",\"Recv\");
                   dpSet(str1, s13i);
                 }
               }
             }
               if(Load == 0x8)       /* Load Config State - Standby         */
             {   if((lvpa == 3) || (lvpa == 4))
               {   if(lvpa == 3)
                 { sscanf(s13w,\"%x\",s13i);
                   strreplace(str1,\"Name\",\"Send\");
                   dpSet(str1, s13i);
                 } else
                 { sscanf(s13w,\"%f\",s13f);
                   strreplace(str1,\"Name\",\"Send\");
                   dpSet(str1, s13f);
                 }
               } else
               {   if((lvpa == 1) || (lvpa == 2))
                 { sscanf(s17w,\"%f\",s17f);
                   sscanf(s18w,\"%f\",s18f);
                   sscanf(s19w,\"%f\",s19f);
                   sscanf(s20w,\"%f\",s20f);
                   sscanf(s21w,\"%f\",s21f);
                   strreplace(str1,\"Name\",\"Recv\");
                   dpSet(str1, s19f);
                   setAlerts(str1, s17f, s18f, s20f, s21f);
                 } else
                 { sscanf(s19w,\"%x\", s19i);
                   strreplace(str1,\"Name\",\"Recv\");
                   dpSet(str1, s19i);
                 }
               }
             }
               if(Load == 0xC)       /* Load Config State - On              */
             {   if((lvpa == 3) || (lvpa == 4))
               {   if(lvpa == 3)
                 { sscanf(s13w,\"%x\",s13i);
                   strreplace(str1,\"Name\",\"Send\");
                   dpSet(str1, s13i);
                 } else
                 { sscanf(s13w,\"%f\",s13f);
                   strreplace(str1,\"Name\",\"Send\");
                   dpSet(str1, s13f);
                 }
               } else
               {   if((lvpa == 1) || (lvpa == 2))
                 { sscanf(s23w,\"%f\",s23f);
                   sscanf(s24w,\"%f\",s24f);
                   sscanf(s25w,\"%f\",s25f);
                   sscanf(s26w,\"%f\",s26f);
                   sscanf(s27w,\"%f\",s27f);
                   strreplace(str1,\"Name\",\"Recv\");
                   dpSet(str1, s25f);
                   setAlerts(str1, s23f, s24f, s26f, s27f);
                 } else
                 { sscanf(s25w,\"%x\",s25i);
                   strreplace(str1,\"Name\",\"Recv\");
                   dpSet(str1, s25i);
                 }
               }
             }
           } else
           {   if(Load == 0x4)       /* Load Config State - Off             */
             { sscanf(s13w,\"%x\",s13i);
                 if(hvpa == 1)
               { strreplace(str1,\"Name\",\"Send\");
                 dpSet(str1, s13i);
               } else
               { strreplace(str1,\"Name\",\"Recv\");
                 dpSet(str1, s13i);
               }
             }
               if(Load == 0x8)       /* Load Config State - Standby         */
             { sscanf(s19w,\"%x\",s19i);
                 if(hvpa == 1)
               { strreplace(str1,\"Name\",\"Send\");
                 dpSet(str1, s19i);
               } else
               { strreplace(str1,\"Name\",\"Recv\");
                 dpSet(str1, s19i);
               }
             }
               if(Load == 0xC)       /* Load Config State - On              */
             { sscanf(s25w,\"%x\",s25i);
                 if(hvpa == 1)
               { strreplace(str1,\"Name\",\"Send\");
                 dpSet(str1, s25i);
               } else
               { strreplace(str1,\"Name\",\"Recv\");
                 dpSet(str1, s25i);
               }
             }
           }
             if((Serv == 0x8) || (Serv == 0xC))
           { ;
//             delay(0,05);            /* For ELMB - if OPC-server is running */
           }
         }
/*OPC>*/
         sprintf(str4,\"SCTmops1:%s.%s.%s\",uadr,para_adr,\"Send\");
           if(hivo == 0)
         { sprintf(para_adr,\"Card%d\", lvix);
         } else
         { sprintf(para_adr,\"Card%d\", hvix);
         }
                                     /* Str5/6 - OPC Item Name for Send/Recv*/
         sprintf(str5,\"%s_%s_Send%s\", uadr, s04w, para_adr);
         sprintf(str6,\"%s_%s_Recv%s\", uadr, s04w, para_adr);
                                     /* Str7/8 - Full Item Name for Connect.*/
         sprintf(str7,\"%s.%s.%s_%s_Send%s\", padr, uadr, uadr, s04w, para_adr);
         sprintf(str8,\"%s.%s.%s_%s_Recv%s\", padr, uadr, uadr, s04w, para_adr);
/*
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", str6);
                                                         delay(2); /* Debug */
           if(((usts & 0x4) > 0) && ((Serv == 0x4) || (Serv == 0x8)))
         {   switch(para)
           { case  0:                  /* LVcaStat                          */
//                      fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
//                              str5, uadr, 0x2000 + lvix);
                        if(lvix < 10)
                      { fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  1\\n\",
                                str6, uadr, 0x180+iden, card);
                      } else
                      { fprintf(fpdi,\"%s = %s %x VT_UI1 %2d  1\\n\",
                                str6, uadr, 0x180+iden, card);
                      }
                        if(Serv == 0x8)
                      { strreplace(str4,\"Send\",\"Recv\");
                        setOPCAddress(str4, str8,
                                      \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  1:                  /* LVcaTemp                          */
//                      fprintf(fsdi,\"%s  = %s %x 2 IO VT_UI1\\n\",
//                              str5, uadr, 0x2000 + lvix);
                        if(lvix < 10)
                      { fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  2\\n\",
                                str6, uadr, 0x180+iden, card);
                      } else
                      { fprintf(fpdi,\"%s = %s %x VT_UI1 %2d  2\\n\",
                                str6, uadr, 0x180+iden, card);
                      }
                        if(Serv == 0x8)
                      { strreplace(str4,\"Send\",\"Recv\");
                        setOPCAddress(str4, str8,
                                      \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                        setConversion(str4, \"IN\", 0.0, 1.0);
//                        dpConnect(\"OneToOne_toData\", str1);
                      }
                      break;
             case  2:                  /* LVcaPowr                          */
//                      fprintf(fsdi,\"%s  = %s %x 3 IO VT_UI1\\n\",
//                              str5, uadr, 0x2000 + lvix);
                        if(lvix < 10)
                      { fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  3\\n\",
                                str6, uadr, 0x180+iden, card);
                      } else
                      { fprintf(fpdi,\"%s = %s %x VT_UI1 %2d  3\\n\",
                                str6, uadr, 0x180+iden, card);
                      }
                        if(Serv == 0x8)
                      { strreplace(str4,\"Send\",\"Recv\");
                        setOPCAddress(str4, str8,
                                      \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                        setConversion(str4, \"IN\", 0.0, 1.0 / 2.5);
//                        dpConnect(\"LVcaPowr_toData\", str1);
                      }
                      break;
             case  3:                  /* LVcaMask                          */
                        if(lvix < 10)
                      { fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
                                str5, uadr, 0x2100 + lvix);
                      } else
                      { fprintf(fsdi,\"%s = %s %x 1 IO VT_UI1\\n\",
                                str5, uadr, 0x2100 + lvix);
                      }
                        if(Serv == 0x8)
                      { setOPCAddress(str4, str7,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
//                      fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  1\\n\",
//                              str6, uadr, 0x180+iden, card);
                      break;
             case  4:                  /* LVcaTrip                          */
                        if(lvix < 10)
                      { fprintf(fsdi,\"%s  = %s %x 2 IO VT_UI1\\n\",
                                str5, uadr, 0x2100 + lvix);
                      } else
                      { fprintf(fsdi,\"%s = %s %x 2 IO VT_UI1\\n\",
                                str5, uadr, 0x2100 + lvix);
                      }
                        if(Serv == 0x8)
                      { setOPCAddress(str4, str7,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                         strreplace(str1,\"Send\",\"Comm\");
                         setConversion(str4, \"OUT\", 0.0, 2.5);
//                         dpConnect(\"LVcaTrip_toSend\", str1);
                      }
//                      fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  2\\n\",
//                              str6, uadr, 0x180+iden, card);
                      break;
             case  5:                  /* HVcaStat                          */
//                      fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
//                              str5, uadr, 0x2200 + hvix);
                      fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  1\\n\",
                              str6, uadr, 0x180+iden, card);
                        if(Serv == 0x8)
                      { strreplace(str4,\"Send\",\"Recv\");
                        setOPCAddress(str4, str8,
                                      \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  6:                  /* HVcaMask                          */
                      fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
                              str5, uadr, 0x2300 + hvix);
                        if(Serv == 0x8)
                      { setOPCAddress(str4, str7,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
//                      fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  1\\n\",
//                              str6, uadr, 0x180+iden, card);
                      break;
             case  7:                  /* LVcaStat                          */
//                      fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
//                              str5, uadr, 0x2000 + lvix);
                        if(lvix < 10)
                      { fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  1\\n\",
                                str6, uadr, 0x180+iden, card);
                      } else
                      { fprintf(fpdi,\"%s = %s %x VT_UI1 %2d  1\\n\",
                                str6, uadr, 0x180+iden, card);
                      }
                        if(Serv == 0x8)
                      { strreplace(str4,\"Send\",\"Recv\");
                        setOPCAddress(str4, str8,
                                      \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  8:                  /* LVcaTemp                          */
//                      fprintf(fsdi,\"%s  = %s %x 2 IO VT_UI1\\n\",
//                              str5, uadr, 0x2000 + lvix);
                        if(lvix < 10)
                      { fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  2\\n\",
                                str6, uadr, 0x180+iden, card);
                      } else
                      { fprintf(fpdi,\"%s = %s %x VT_UI1 %2d  2\\n\",
                                str6, uadr, 0x180+iden, card);
                      }
                        if(Serv == 0x8)
                      { strreplace(str4,\"Send\",\"Recv\");
                        setOPCAddress(str4, str8,
                                      \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                        setConversion(str4, \"IN\", 0.0, 1.0);
//                        dpConnect(\"OneToOne_toData\", str1);
                      }
                      break;
             case  9:                  /* LVcaPowr                          */
//                      fprintf(fsdi,\"%s  = %s %x 3 IO VT_UI1\\n\",
//                              str5, uadr, 0x2000 + lvix);
                        if(lvix < 10)
                      { fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  3\\n\",
                                str6, uadr, 0x180+iden, card);
                      } else
                      { fprintf(fpdi,\"%s = %s %x VT_UI1 %2d  3\\n\",
                                str6, uadr, 0x180+iden, card);
                      }
                        if(Serv == 0x8)
                      { strreplace(str4,\"Send\",\"Recv\");
                        setOPCAddress(str4, str8,
                                      \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                        setConversion(str4, \"IN\", 0.0, 1.0 / 2.5);
//                        dpConnect(\"LVcaPowr_toData\", str1);
                      }
                      break;
             case 10:                  /* LVcaMask                          */
                        if(lvix < 10)
                      { fprintf(fsdi,\"%s  = %s %x 1 IO VT_UI1\\n\",
                                str5, uadr, 0x2100 + lvix);
                      } else
                      { fprintf(fsdi,\"%s = %s %x 1 IO VT_UI1\\n\",
                                str5, uadr, 0x2100 + lvix);
                      }
                        if(Serv == 0x8)
                      { setOPCAddress(str4, str7,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
//                      fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  1\\n\",
//                              str6, uadr, 0x180+iden, card);
                      break;
             case 11:                  /* LVcaTrip                          */
                        if(lvix < 10)
                      { fprintf(fsdi,\"%s  = %s %x 2 IO VT_UI1\\n\",
                                str5, uadr, 0x2100 + lvix);
                      } else
                      { fprintf(fsdi,\"%s = %s %x 2 IO VT_UI1\\n\",
                                str5, uadr, 0x2100 + lvix);
                      }
                        if(Serv == 0x8)
                      { setOPCAddress(str4, str7,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                        strreplace(str1,\"Send\",\"Comm\");
                        setConversion(str4, \"OUT\", 0.0, 2.5);
//                        dpConnect(\"LVcaTrip_toSend\", str1);
                      }
//                      fprintf(fpdi,\"%s  = %s %x VT_UI1 %2d  2\\n\",
//                              str6, uadr, 0x180+iden, card);
                      break;
             default: ;
           }
         }
/*<OPC*/
/*
         sprintf(dstr,\" Rk=%d Cr=%d Ca=%d LVix=%d HVix=%d %s_%s:%s\",
                        rack, crat, card, lvix, hvix, uadr, para_adr, s04w);
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(1);
                                                                   /* Debug */
           if(hivo == 0)
         { lvpa++; if(lvpa >= lvca_max)
           { lvpa = 0;
           }
         } if(hivo > 0)
         { hvpa++; if(hvpa >= hvca_max)
           { hvpa = 0;
           }
         }
         para++; if(para >= maxp)
         { para = 0;
           grup++; if(grup >= 6)     /* 6 - number of Card groups: LV+HV+LV */
           { unit++;
           }
         }
       }
     } fclose(finp);
   } else
   { fclose(fopc);  fclose(fini);  fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
     sprintf(estr,\" 'Cnf_Crate.txt' File opening \");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
     sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   }
/*CRATE*/
     if((Serv == 0x0) || (Serv == 0x4) || (Serv == 0xC))
   { sprintf(mstr,\" CRATE CONFIGs LOADING...\");
   } else
   { sprintf(mstr,\" CRATE OPC CONFIGs CREATING...\");
   }
   dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);   delay(1);
   finp = fopen(\"Cnf_Crate.txt\",\"r\");/* Crate(s) parameters reading from DB */
   eror = ferror(finp);
     if(!eror)
   { fgets(fstr, 300, finp);         /* Skip the first line                 */
     para=0;
     unit=0;  while(unit < umax)
     { fgets(fstr, 300, finp);
/*
       sprintf(dstr,\" Umax=%d CRmax=%d Unit=%d Para=%d\",umax,crmx, unit,para);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(2);
                                                                   /* Debug */
       sscanf(fstr,
             \"%d %d%d%s%s %d%d%d%d%s %s%s%s%s%s%s %s%s%%s%s%s%s s%s%s%s%s\",
       s00i,  s01i, s02i, s03w, s04w,  s05i, s06i, s07i, s08i, s09w,
       s10w, s11w, s12w, s13w, s14w,s15w,  s16w, s17w, s18w, s19w, s20w,s21w,
       s22w, s23w, s24w, s25w, s26w);
       strreplace(s03w,\"\\\"\",\"\");        strreplace(s04w,\"\\\"\",\"\");
       strreplace(s09w,\"\\\"\",\"\");        strreplace(s10w,\"\\\"\",\"\");
       strreplace(s11w,\"\\\"\",\"\");        strreplace(s12w,\"\\\"\",\"\");
       strreplace(s13w,\"\\\"\",\"\");        strreplace(s14w,\"\\\"\",\"\");
       strreplace(s15w,\"\\\"\",\"\");        strreplace(s16w,\"\\\"\",\"\");
       strreplace(s17w,\"\\\"\",\"\");        strreplace(s18w,\"\\\"\",\"\");
       strreplace(s19w,\"\\\"\",\"\");        strreplace(s20w,\"\\\"\",\"\");
       strreplace(s21w,\"\\\"\",\"\");        strreplace(s22w,\"\\\"\",\"\");
       strreplace(s23w,\"\\\"\",\"\");        strreplace(s24w,\"\\\"\",\"\");
       strreplace(s25w,\"\\\"\",\"\");        strreplace(s26w,\"\\\"\",\"\");
/*
       sprintf(dstr,
\" Cr: %d %d %d %s %s %d %d %d %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\",
       s00i,  s01i, s02i, s03w, s04w,  s05i, s06i, s07i, s08i, s09w,
       s10w, s11w, s12w, s13w, s14w,s15w,  s16w, s17w, s18w, s19w, s20w,s21w,
       s22w, s23w, s24w, s25w, s26w);
       dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(2);
                                                                   /* Debug */
       host = s05i; if(host == 99)   /* End of Unit ConfigFile              */
       { break;
       } else
       {   if(host > 9)
         { sprintf(estr,
    \" Reading 'Cnf_Crate.txt',\\n           Host number is too much, Unit: %d\",
                      unit); 
           dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
           dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
           dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
           sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
           dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
           while(1) { delay(1); }
         }
       }
       node = s06i; if(node > nmax)
       { sprintf(estr,
       \" Reading 'Cnf_Crate.txt',\\n        Node number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       } if(node == 9)
       { break;
       }
       port = s07i; if(port > pmax)
       { sprintf(estr,
    \" Reading 'Cnf_Crate.txt',\\n           Port number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       } if(port == 9)
       { break;
       }
       unit = s08i; if(unit > umax)
       { setValue(\"ErorIndi\",\"backCol\",\"Red\");
         sprintf(estr,
    \" Reading 'Cnf_Crate.txt',\\n           Unit number is too much, Unit: %d\",
                      unit); 
         dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
         dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
         dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
         sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
         dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
         while(1) { delay(1); }
       } if(unit == 99)
       { break;
       }
         if((node < nmax) && (port < pmax) && (unit < umax) && (unit !=  99))
       { rack = s01i - 1;  crat = s02i - 1;
         busn = (node * pmax) + port;
           if(busn < 10)
         { sprintf(padr,\"Bus0%d\", busn);
         } else
         { sprintf(padr,\"Bus%d\" , busn);
         }
         crat = (node * pmax) + (port * umax) + unit;
           if(unit < 10)             /* Crate Name (Unit ADdRess)           */
         { sprintf(uadr,\"Crate0%d\", crat); 
         } else
         { sprintf(uadr,\"Crate%d\" , crat); 
         }
         sprintf(para_adr,\"Controller.%s\", s03w);
         sprintf(str1,\"SCTmops1:%s.%s.%s\",
                       uadr,para_adr,\"Name:_original.._value\");
           if(Load == 0x4)           /* Load Config State - Off             */
         {   if(1)//(para < 1)
           { sscanf(s12w,\"%x\",s12i);
             strreplace(str1,\"Name\",\"Send\");
             dpSet(str1, s12i);
           } else
           { sscanf(s10w,\"%f\",s10f);
             sscanf(s11w,\"%f\",s11f);
             sscanf(s12w,\"%f\",s12f);
             sscanf(s13w,\"%f\",s13f);
             sscanf(s14w,\"%f\",s14f);
             strreplace(str1,\"Name\",\"Recv\");
             dpSet(str1, s12f);
             setAlerts(str1, s10f, s11f, s13f, s14f);
           }
         }
           if(Load == 0x8)           /* Load Config State - Standby         */
         {   if(1)//(para < 1)
           { sscanf(s18w,\"%x\",s18i);
             strreplace(str1,\"Name\",\"Send\");
             dpSet(str1, s18i);
           } else
           { sscanf(s16w,\"%f\",s16f);
             sscanf(s17w,\"%f\",s17f);
             sscanf(s18w,\"%f\",s18f);
             sscanf(s19w,\"%f\",s19f);
             sscanf(s20w,\"%f\",s20f);
             strreplace(str1,\"Name\",\"Recv\");
             dpSet(str1, s18f);
             setAlerts(str1, s16f, s17f, s19f, s20f);
           }
         }
           if(Load == 0xC)           /* Load Config State - On              */
         {   if(1)//(para < 1)
           { sscanf(s24w,\"%x\",s24i);
             strreplace(str1,\"Name\",\"Send\");
             dpSet(str1, s24i);
           } else
           { sscanf(s22w,\"%f\",s22f);
             sscanf(s23w,\"%f\",s23f);
             sscanf(s24w,\"%f\",s24f);
             sscanf(s25w,\"%f\",s25f);
             sscanf(s26w,\"%f\",s26f);
             strreplace(str1,\"Name\",\"Recv\");
             dpSet(str1, s24f);
             setAlerts(str1, s22f, s23f, s25f, s26f);
           }
         }
/*OPC>*/
//         sprintf(str2,\"SCTmops1:%s.%s\",uadr,\"Stat:_original.._value\");
         sprintf(str4,\"SCTmops1:%s.%s.%s\",uadr,para_adr,\"Send\");
                                     /* Str5/6 - OPC Item Name for Send/Recv*/
//         sprintf(para_adr,\"Contrl\");
//         sprintf(str5,\"%s_%s__Set%s\", uadr, s03w, para_adr);
//         sprintf(str6,\"%s_%s_Read%s\", uadr, s03w, para_adr);
                                     /* Str7/8 - Full Item Name for Connect.*/
         sprintf(str7,\"%s.%s.%s__Set\", padr, uadr, uadr);
         sprintf(str8,\"%s.%s.%s_Read\", padr, uadr, uadr);
/*
         setValue(\"ConfInfo\",\"text\", str4);              delay(2); /* Debug */
           if(((usts & 0x4) > 0) && ((Serv == 0x4) || (Serv == 0x8)))
         {   switch(para)
           { case  0:                  /* CC_Reset                          */
////                      fprintf(fsdi,\"%s = %s %x 0 IO VT_UI1\\n\",
////                              str5, uadr, 0x2800);
//                      fprintf(fpdi,\"%s = %s %x VT_UI1  %d  1\\n\",
//                              str5, uadr, 0x400+iden, para);
//                        if(Serv == 0x8)
//                      { setOPCAddress(str4, str7,
//                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                      }
                      break;
             case  1:                  /* CCch_Set                          */
////                      fprintf(fsdi,\"%s     = %s %x 0 IO VT_UI1\\n\",
////                              str5, uadr, 0x2900);
                      fprintf(fpdi,
                              \"%s__Set                = %s %x VT_UI1  0\\n\",
                                                   uadr, uadr, 0x400+iden);
//                      fprintf(fpdi,\"%s = %s %x VT_UI2  %d  2\\n\",
//                              str5, uadr, 0x400+iden, para);
                        if(Serv == 0x8)
                      { setOPCAddress(str4, str7,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                      break;
             case  2:                  /* CCchRead                          */
////                      fprintf(fsdi,\"%s     = %s %x 0 IO VT_UI1\\n\",
////                              str5, uadr, 0x2a00);
                      fprintf(fpdi,
                              \"%s_Read                = %s %x VT_UI1  0\\n\",
                                                   uadr, uadr, 0x500+iden);
//                      fprintf(fpdi,\"%s = %s %x VT_UI2  %d  3\\n\",
//                              str5, uadr, 0x500+iden, para);
                        if(Serv == 0x8)
                      { setOPCAddress(str4, str8,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                      break;
             default: ;
           }
         }
/*<OPC*/
/*
       sprintf(dstr,\" Rk=%d Cr=%d %s_%s:%s\",rack, crat, uadr, para_adr, s03w);
       setValue(\"ConfInfo\",\"text\", dstr);                delay(1); /* Debug */
       } para++;
         if(para >= crmx)
       {
//           if((Serv == 0x4) || (Serv == 0x8))
//         { fprintf(fpdi,\"%s__Set                = %s %x VT_UI1  0\\n\",
//                                                  uadr, uadr, 0x400+iden);
//           fprintf(fpdi,\"%s_Read                = %s %x VT_UI1  0\\n\",
//                                                  uadr, uadr, 0x500+iden);
//         }
         para = 0;  unit++;
       }
     } fclose(finp);
   } else
   { fclose(fopc);  fclose(fini);  fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
     sprintf(estr,\" 'Cnf_Crate.txt' File opening \");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
     sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   }
/*OPC>*/
       if((Serv == 0x4) || (Serv == 0x8))
     { fclose(fini);  fclose(fsdi);  fclose(fpdo);  fclose(fpdi);
       fsdi= fopen(\"OPCsdi.bak\",\"r\");/* ConfigFile for OPC SDoItem param-s  */
       fpdo= fopen(\"OPCpdo.bak\",\"r\");/* ConfigFile for OPC PDO  parameters  */
       fpdi= fopen(\"OPCpdi.bak\",\"r\");/* ConfigFile for OPC PDoItem param-s  */
       fini= fopen(\"OPCini.bak\",\"r\");/* ConfigFile for OPC INItial param-s  */
       int2= 1000; //(umax * (lvca_max + hvca_max + crmx)) +
          //(umax * 48 * (lvmx + hvmx));  /* 48 - Chan-s number in the Crate*/
       int1=0; while(int1 < int2)
       { fgets(fstr, 300, fsdi);       // int3 = fstr;
           if(1)//int3 != 0)
         { fprintf(fopc, fstr);
         } else
         { break;
         } int1++;
       }
       int2 = 20;                    /* 20 - PDOs number_Max                */
       int1=0; while(int1 < int2)
       { fgets(fstr, 300, fpdo);       // int3 = fstr;
           if(1)//int3 != 0)
         { fprintf(fopc, fstr);
         } else
         { break;
         } int1++;
       }
       int2 = 100; //( 6 * umax)     /* 100 - PDO Items number_Max in Crate */
       int1=0; while(int1 < int2)
       { fgets(fstr, 300, fpdi);       // int3 = fstr;
           if(1)//int3 != 0)
         { fprintf(fopc, fstr);
         } else
         { break;
         } int1++;
       }
       int2 = 10;                    /* 10 - Init points number_Max         */
       int1=0; while(int1 < int2)
       { fgets(fstr, 300, fini);       // int3 = fstr;
           if(1)//int3 != 0)
         { fprintf(fopc, fstr);
         } else
         { break;
         } int1++;
       } fclose(fsdi);  fclose(fpdo);  fclose(fpdi);  fclose(fini);
         fclose(fopc);
     }
/*<OPC*/
   } else
   { sprintf(estr,\" 'Cnf_Para.txt' File opening \");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr);
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
     dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
     sprintf(mstr,\" PUSH EXIT [X] BUTTON \");
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
     while(1) { delay(1); }
   }
/*ARCH*/
   dpGet(\"SCTmops1:Arch.Stat:_original.._value\", arch);
     if(Load == 0x8)
   {   if(arch > 0)
     { sprintf(mstr,\" ARCHIVE CONNECTIONS (~55 sec)...\");
     } else
     { sprintf(mstr,\" ARCHIVE DISCONNECTIONS (~55 sec)...\");
     } dpSet(\"SCTmops1:Moni.Name:_original.._value\", mstr);  delay(1);
   }
/*chan*/
// host=0; while(host < hmax)
// {
     node=0; while(node < nmax)
     { port=0; while(port < pmax)
       { unit=0; while(unit < umax)
         { crat = (node * pmax) + (port * umax) + unit;
             if(crat < 10)
           { sprintf(uadr,
                     \"SCTmops1:Crate0%d%s\",crat,\".Stat:_original.._value\");
           } else
           { sprintf(uadr,
                     \"SCTmops1:Crate%d%s\" ,crat,\".Stat:_original.._value\");
           }
           dpGet(uadr, usts);
           strreplace(uadr,\".Stat:_original.._value\",\"\");
           chan=0; while(chan < cmax)
           {   if(chan < 10)
             { sprintf(cadr,\"%s%s%d.HV_Stat:_original.._value\",
                             uadr,\".Channel0\",chan);
             } else
             { sprintf(cadr,\"%s%s%d.HV_Stat:_original.._value\",
                             uadr,\".Channel\" ,chan);
             } dpGet(cadr, stat);
               if(Load == 0x8)
             { strreplace(cadr,\".HV_Stat:_original.._value\",
                               \".HVchStat.Recv:_archive.._type\");
                 if(((usts & 0xC) >= 0x4) && ((stat & 0xC) >= 0x4) &&
                     (arch > 0))
               { para=0; while(para < hvmx)
                 {   switch(para)
                   { case  1: strreplace(cadr,\"HVchStat\",\"HVchVolt\");  break;
                     case  2: strreplace(cadr,\"HVchVolt\",\"HVchCurr\");  break;
//                     case  3: strreplace(cadr,\"HVchCurr\",\"HVchITrp\");  break;
//                     case  4: strreplace(cadr,\"HVchITrp\",\"HVchRamp\");  break;
                     default: ;
                   }
                   sprintf(str9,\"%s\",cadr);
                   strreplace(str9,\"_archive.._type\",\"_archive.._archive\");
                   sprintf(str8,\"%s\",cadr);
                   strreplace(str8,\"_archive.._type\",\"_archive.1._type\");
                   sprintf(str7,\"%s\",cadr);
                   strreplace(str7,\"_archive.._type\",\"_archive.1._class\");
                   sprintf(str6,\"%s\",\"SCTmops1:_ValueArchive_1\");
                   eror = dpSet(cadr, DPCONFIG_DB_ARCHIVEINFO,
                                str9, TRUE,
                                str8, DPATTR_ARCH_PROC_VALARCH, str7, str6);
                   sprintf(str5,\"%s\",\"DP_ARCH IS SET\");
/*
                   sprintf(dstr,\" %s: %s\", cadr, str5);
                   strreplace(dstr,\":_archive.._type\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                   para++;
                 }
               } else
               { para=0; while(para < hvmx)
                 {   switch(para)
                   { case  1: strreplace(cadr,\"HVchStat\",\"HVchVolt\");  break;
                     case  2: strreplace(cadr,\"HVchVolt\",\"HVchCurr\");  break;
//                     case  3: strreplace(cadr,\"HVchCurr\",\"HVchITrp\");  break;
//                     case  4: strreplace(cadr,\"HVchITrp\",\"HVchRamp\");  break;
                     default: ;
                   }
                   eror = dpSet(cadr, DPCONFIG_NONE);
                   sprintf(str7,\"%s\",cadr);
                   sprintf(str5,\"%s\",\"DP_ARCH  RESET\");
/*
                   sprintf(dstr,\" %s: %s\", cadr, str5);
                   strreplace(dstr,\":_archive.._type\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                   para++;
                 }
               }
                 if(((usts & 0xC) >= 0x4) && ((stat & 0xC) >= 0x4) &&
                     (arch > 0))
               { para=0; while(para < lvmx)
                 {   switch(para)
//                   { case  0: strreplace(cadr,\"HVchRamp\",\"LVchStat\");  break;
                   { case  0: strreplace(cadr,\"HVchCurr\",\"LVchStat\");  break;
                     case  1: strreplace(cadr,\"LVchStat\",\"LVch_Vcc\");  break;
                     case  2: strreplace(cadr,\"LVch_Vcc\",\"LVps_Vcc\");  break;
                     case  3: strreplace(cadr,\"LVps_Vcc\",\"LVretVcc\");  break;
                     case  4: strreplace(cadr,\"LVretVcc\",\"LVch_Icc\");  break;
                     case  5: strreplace(cadr,\"LVch_Icc\",\"LVch_Vdd\");  break;
                     case  6: strreplace(cadr,\"LVch_Vdd\",\"LVps_Vdd\");  break;
                     case  7: strreplace(cadr,\"LVps_Vdd\",\"LVretVdd\");  break;
                     case  8: strreplace(cadr,\"LVretVdd\",\"LVch_Idd\");  break;
                     case  9: strreplace(cadr,\"LVch_Idd\",\"LVchVCSV\");  break;
                     case 10: strreplace(cadr,\"LVchVCSV\",\"LVchVCSI\");  break;
                     case 11: strreplace(cadr,\"LVchVCSI\",\"LVchPINV\");  break;
                     case 12: strreplace(cadr,\"LVchPINV\",\"LVchPINI\");  break;
                     case 13: strreplace(cadr,\"LVchPINI\",\"MOch_Tm0\");  break;
                     case 14: strreplace(cadr,\"MOch_Tm0\",\"MOch_Tm1\");  break;
//                     case 15: strreplace(cadr,\"MOch_Tm1\",\"LVchDTrp\");  break;
//                     case 16: strreplace(cadr,\"LVchDTrp\",\"LVchCTrp\");  break;
//                     case 17: strreplace(cadr,\"LVchCTrp\",\"LVchTLim\");  break;
//                     case 18: strreplace(cadr,\"LVchTLim\",\"LVchTTrp\");  break;
//                     case 19: strreplace(cadr,\"LVchTTrp\",\"LVchCLKS\");  break;
//                     case 20: strreplace(cadr,\"LVchCLKS\",\"LVchCLKR\");  break;
//                     case 21: strreplace(cadr,\"LVchCLKR\",\"LVchVOut\");  break;
                     default: ;
                   }
                   sprintf(str9,\"%s\",cadr);
                   strreplace(str9,\"_archive.._type\",\"_archive.._archive\");
                   sprintf(str8,\"%s\",cadr);
                   strreplace(str8,\"_archive.._type\",\"_archive.1._type\");
                   sprintf(str7,\"%s\",cadr);
                   strreplace(str7,\"_archive.._type\",\"_archive.1._class\");
                   sprintf(str6,\"%s\",\"SCTmops1:_ValueArchive_1\");
                   eror = dpSet(cadr, DPCONFIG_DB_ARCHIVEINFO,
                                str9, TRUE,
                                str8, DPATTR_ARCH_PROC_VALARCH, str7, str6);
                   sprintf(str5,\"%s\",\"DP_ARCH IS SET\");
/*
                   sprintf(dstr,\" %s: %s\", cadr, str5);
                   strreplace(dstr,\":_archive.._type\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                   para++;
                 }
               } else
               { para=0; while(para < lvmx)
                 {   switch(para)
//                   { case  0: strreplace(cadr,\"HVchRamp\",\"LVchStat\");  break;
                   { case  0: strreplace(cadr,\"HVchCurr\",\"LVchStat\");  break;
                     case  1: strreplace(cadr,\"LVchStat\",\"LVch_Vcc\");  break;
                     case  2: strreplace(cadr,\"LVch_Vcc\",\"LVps_Vcc\");  break;
                     case  3: strreplace(cadr,\"LVps_Vcc\",\"LVretVcc\");  break;
                     case  4: strreplace(cadr,\"LVretVcc\",\"LVch_Icc\");  break;
                     case  5: strreplace(cadr,\"LVch_Icc\",\"LVch_Vdd\");  break;
                     case  6: strreplace(cadr,\"LVch_Vdd\",\"LVps_Vdd\");  break;
                     case  7: strreplace(cadr,\"LVps_Vdd\",\"LVretVdd\");  break;
                     case  8: strreplace(cadr,\"LVretVdd\",\"LVch_Idd\");  break;
                     case  9: strreplace(cadr,\"LVch_Idd\",\"LVchVCSV\");  break;
                     case 10: strreplace(cadr,\"LVchVCSV\",\"LVchVCSI\");  break;
                     case 11: strreplace(cadr,\"LVchVCSI\",\"LVchPINV\");  break;
                     case 12: strreplace(cadr,\"LVchPINV\",\"LVchPINI\");  break;
                     case 13: strreplace(cadr,\"LVchPINI\",\"MOch_Tm0\");  break;
                     case 14: strreplace(cadr,\"MOch_Tm0\",\"MOch_Tm1\");  break;
//                     case 15: strreplace(cadr,\"MOch_Tm1\",\"LVchDTrp\");  break;
//                     case 16: strreplace(cadr,\"LVchDTrp\",\"LVchCTrp\");  break;
//                    case 17: strreplace(cadr,\"LVchCTrp\",\"LVchTLim\");  break;
//                     case 18: strreplace(cadr,\"LVchTLim\",\"LVchTTrp\");  break;
//                     case 19: strreplace(cadr,\"LVchTTrp\",\"LVchCLKS\");  break;
//                     case 20: strreplace(cadr,\"LVchCLKS\",\"LVchCLKR\");  break;
//                     case 21: strreplace(cadr,\"LVchCLKR\",\"LVchVOut\");  break;
                     default: ;
                   }
                   eror = dpSet(cadr, DPCONFIG_NONE);
                   sprintf(str7,\"%s\",cadr);
                   sprintf(str5,\"%s\",\"DP_ARCH  RESET\");
/*
                   sprintf(dstr,\" %s: %s\", cadr, str5);
                   strreplace(dstr,\":_archive.._type\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                   para++;
                 }
               }
             } chan++;
           }
/*hv_card*/
           card=0; while(card < 6)
           {   if(Load == 0x8)
             { sprintf(cadr,\"%s.HV_card0%d.HVcaStat.Recv:_archive.._type\",
                               uadr, card);
                 if(((usts & 0xC) >= 0x4) && (arch > 0))
               { para=0; while(para < hvca_max)
                 {   switch(para)
                   {
//                     case  1: strreplace(cadr,\"HVcaStat\",\"HVcaMask\");  break;
                     default: ;
                   }
                   sprintf(str9,\"%s\",cadr);
                   strreplace(str9,\"_archive.._type\",\"_archive.._archive\");
                   sprintf(str8,\"%s\",cadr);
                   strreplace(str8,\"_archive.._type\",\"_archive.1._type\");
                   sprintf(str7,\"%s\",cadr);
                   strreplace(str7,\"_archive.._type\",\"_archive.1._class\");
                   sprintf(str6,\"%s\",\"SCTmops1:_ValueArchive_1\");
                   eror = dpSet(cadr, DPCONFIG_DB_ARCHIVEINFO,
                                str9, TRUE,
                                str8, DPATTR_ARCH_PROC_VALARCH, str7, str6);
                   sprintf(str5,\"%s\",\"DP_ARCH IS SET\");
/*
                   sprintf(dstr,\" %s: %s\", cadr, str5);
                   strreplace(dstr,\":_archive.._type\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                   para++;
                 }
               } else
               { para=0; while(para < hvca_max)
                 {   switch(para)
                   {
//                     case  1: strreplace(cadr,\"HVcaStat\",\"HVcaMask\");  break;
                     default: ;
                   }
                   eror = dpSet(cadr, DPCONFIG_NONE);
                   sprintf(str7,\"%s\",cadr);
                   sprintf(str5,\"%s\",\"DP_ARCH  RESET\");
/*
                   sprintf(dstr,\" %s: %s\", cadr, str5);
                   strreplace(dstr,\":_archive.._type\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                   para++;
                 }
               }
             } card++;
           }
/*lv_card*/
           card=0; while(card < 12)
           {   if(Load == 0x8)
             {   if(card < 10)
               { sprintf(cadr,\"%s.LV_card0%d.LVcaStat.Recv:_archive.._type\",
                               uadr, card);
               } else
               { sprintf(cadr,\"%s.LV_card%d.LVcaStat.Recv:_archive.._type\",
                               uadr, card);
               }
                 if(((usts & 0xC) >= 0x4) && (arch > 0))
               { para=0; while(para < hvca_max)
                 {   switch(para)
                   { case  1: strreplace(cadr,\"LVcaStat\",\"LVcaTemp\");  break;
                     case  2: strreplace(cadr,\"LVcaTemp\",\"LVcaPowr\");  break;
//                     case  3: strreplace(cadr,\"LVcaPowr\",\"LVcaMask\");  break;
//                     case  4: strreplace(cadr,\"LVcaMask\",\"LVcaTrip\");  break;
                     default: ;
                   }
                   sprintf(str9,\"%s\",cadr);
                   strreplace(str9,\"_archive.._type\",\"_archive.._archive\");
                   sprintf(str8,\"%s\",cadr);
                   strreplace(str8,\"_archive.._type\",\"_archive.1._type\");
                   sprintf(str7,\"%s\",cadr);
                   strreplace(str7,\"_archive.._type\",\"_archive.1._class\");
                   sprintf(str6,\"%s\",\"SCTmops1:_ValueArchive_1\");
                   eror = dpSet(cadr, DPCONFIG_DB_ARCHIVEINFO,
                                str9, TRUE,
                                str8, DPATTR_ARCH_PROC_VALARCH, str7, str6);
                   sprintf(str5,\"%s\",\"DP_ARCH IS SET\");
/*
                   sprintf(dstr,\" %s: %s\", cadr, str5);
                   strreplace(dstr,\":_archive.._type\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                   para++;
                 }
               } else
               { para=0; while(para < hvmx)
                 {   switch(para)
                   { case  1: strreplace(cadr,\"LVcaStat\",\"LVcaTemp\");  break;
                     case  2: strreplace(cadr,\"LVcaTemp\",\"LVcaPowr\");  break;
//                     case  3: strreplace(cadr,\"LVcaPowr\",\"LVcaMask\");  break;
//                     case  4: strreplace(cadr,\"LVcaMask\",\"LVcaTrip\");  break;
                     default: ;
                   }
                   eror = dpSet(cadr, DPCONFIG_NONE);
                   sprintf(str7,\"%s\",cadr);
                   sprintf(str5,\"%s\",\"DP_ARCH  RESET\");
/*
                   sprintf(dstr,\" %s: %s\", cadr, str5);
                   strreplace(dstr,\":_archive.._type\",\"\");
                   strreplace(dstr,\"SCTmops1:\",\"\");
                   dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                   para++;
                 }
               }
             } card++;
           } unit++;
         }
/*crate*/
         crat=0; while(crat < umax)  /* Just Example for 'Send' parameters  */
         {   if(0)//Load == 0x8)
           {   if(crat < 10)
             { sprintf(cadr,
                      \"%s.Crate0%d.Controller.CC_Reset.Send:_archive.._type\",
                             uadr, crat);
             } else
             { sprintf(cadr,
                      \"%s.Crate%d.Controller.CC_Reset.Send:_archive.._type\",
                             uadr, crat);
             }
               if(((usts & 0xC) >= 0x4) && (arch > 0))
             { para=0; while(para < crmx)
               {   switch(para)
                 { case  1: strreplace(cadr,\"CC_Reset\",\"CCch_Set\");  break;
                   case  2: strreplace(cadr,\"CCch_Set\",\"CCchRead\");  break;
                   default: ;
                 }
                 sprintf(str9,\"%s\",cadr);
                 strreplace(str9,\"_archive.._type\",\"_archive.._archive\");
                 sprintf(str8,\"%s\",cadr);
                 strreplace(str8,\"_archive.._type\",\"_archive.1._type\");
                 sprintf(str7,\"%s\",cadr);
                 strreplace(str7,\"_archive.._type\",\"_archive.1._class\");
                 sprintf(str6,\"%s\",\"SCTmops1:_ValueArchive_1\");
                 eror = dpSet(cadr, DPCONFIG_DB_ARCHIVEINFO,
                              str9, TRUE,
                              str8, DPATTR_ARCH_PROC_VALARCH, str7, str6);
                 sprintf(str5,\"%s\",\"DP_ARCH IS SET\");
/*
                 sprintf(dstr,\" %s: %s\", cadr, str5);
                 strreplace(dstr,\":_archive.._type\",\"\");
                 strreplace(dstr,\"SCTmops1:\",\"\");
                 dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                 para++;
               }
             } else
             { para=0; while(para < crmx)
               {   switch(para)
                 { case  1: strreplace(cadr,\"CC_Reset\",\"CCch_Set\");  break;
                   case  2: strreplace(cadr,\"CCch_Set\",\"CCchRead\");  break;
                   default: ;
                 }
                 eror = dpSet(cadr, DPCONFIG_NONE);
                 sprintf(str7,\"%s\",cadr);
                 sprintf(str5,\"%s\",\"DP_ARCH  RESET\");
/*
                 sprintf(dstr,\" %s: %s\", cadr, str5);
                 strreplace(dstr,\":_archive.._type\",\"\");
                 strreplace(dstr,\"SCTmops1:\",\"\");
                 dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);
                                                        delay(1);  /* Debug */
                 para++;
               }
             }
           } crat++;
         } port++;
       } node++;
     }
//   host++;
// }
     if(arch == 0x4)
   { dpSet(\"SCTmops1:Arch.Stat:_original.._value\", 0x8);
   }
   dpSet(\"SCTmops1:Hmax.Stat:_original.._value\", 0x0);   /* Green Background*/
   sprintf(dstr,\" Enter PASSword for    Control Panel access: \");
   dpSet(\"SCTmops1:Hmax.Name:_original.._value\", dstr);
   dpSet(\"SCTmops1:Nmax.Stat:_original.._value\", 0x0);   /* Green Background*/
   sprintf(dstr,\" Enter PASSword for Diagnostic Panel access: \");
   dpSet(\"SCTmops1:Nmax.Name:_original.._value\", dstr);
   dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x0);   /* Green Background*/
 }
 
/* ======================================================================== */
/*                          MAKE_SCAN() SUBROUTINES                         */
/* ======================================================================== */
/* CHAN DATA RANDOM GAUSSIAN SIMULATION AROUND OF THE NORMAL VALUE          */
/*                                                                          */
/*                      Unum - Crate (Unit) system NUMber                   */
/*                      From - Start FROM what Chan       ( '0' or '24' )   */
/*                                                                          */
 RandomData_32Chan(int Unum, int From)
 { int     chan, usts, stat, int1;
   float   bias, rndm, warl, warh;
   dyn_int inpi, outi;
   string  uadr, cadr, dstr;
   
     if(Unum < 10)
   { sprintf(uadr,\"SCTmops1:Crate0%d.Stat:_original.._value\", Unum);
   } else
   { sprintf(uadr,\"SCTmops1:Crate%d.Stat:_original.._value\" , Unum);
   } dpGet(uadr, usts);
   strreplace(uadr,\".Stat:_original.._value\",\"\");
     if((usts & 0x4C) == 0x44)
   { chan=From; while(chan < (From + 24))
     {   if(chan < 10)
       { sprintf(cadr,\"%s.Channel0%d.HV_Stat:_original.._value\",uadr, chan);
       } else
       { sprintf(cadr,\"%s.Channel%d.HV_Stat:_original.._value\" ,uadr, chan);
       } dpGet(cadr, stat);
         if((stat & 0x4C) == 0x44)
       { strreplace(cadr,\"HV_Stat\",\"LV_Stat\");
         dpGet(cadr, stat);
           if((stat & 0x4C) == 0x44) /* If HV_Para & LV_Para are included   */
         { inpi = makeDynInt();      /* '32 Random Raw Values' subroutine   */
           inpi[1] = 10000;          /* Random value Peak   = 10000 / 2     */
           inpi[2] =    10;          /* Gaussian distribution Form          */
           int1=0; while(int1 < 32)  /* Random values shift = 0             */
           { inpi[int1 + 3] = 0;        int1++;
           }
           outi = makeDynInt();
           userDefFunc(\"DllPvss\", \"Random32integers_C\", inpi, outi);

           strreplace(cadr,\"LV_Stat\",\"HVchStat.Recv\");
           bias = 0.0;
           dpSet(cadr, bias);
           
           strreplace(cadr,\":_original.._value\",\"\");
           strreplace(cadr,\"HVchStat\",\"HVchVolt\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[ 2] - 5000;
           rndm = rndm / 100.0;                /* Sigma Control: ~ 2        */
           dpSet(cadr + \":_original.._value\", bias + rndm);

           strreplace(cadr,\"HVchVolt\",\"HVchCurr\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[ 3] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
//           strreplace(cadr,\"HVchCurr\",\"HVchITrp\");
//           strreplace(cadr,\"HVchITrp\",\"HVchRamp\");

           strreplace(cadr,\"HVchCurr\",\"LVchStat\");
           bias =   0.0;
           dpSet(cadr + \":_original.._value\", bias);
           
           strreplace(cadr,\"LVchStat\",\"LVch_Vcc\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[ 7] - 5000;
           rndm = rndm / 1000.0;               /* Sigma Control: ~ 0.2      */
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVch_Vcc\",\"LVps_Vcc\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[ 8] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVps_Vcc\",\"LVretVcc\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[ 9] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVretVcc\",\"LVch_Icc\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[10] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVch_Icc\",\"LVch_Vdd\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[11] - 5000;
           rndm = rndm / 1000.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVch_Vdd\",\"LVps_Vdd\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[12] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVps_Vdd\",\"LVretVdd\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[13] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVretVdd\",\"LVch_Idd\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[14] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVch_Idd\",\"LVchVCSV\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[15] - 5000;
           rndm = rndm / 1000.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVchVCSV\",\"LVchVCSI\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[16] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVchVCSI\",\"LVchPINV\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[17] - 5000;
           rndm = rndm / 1000.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVchPINV\",\"LVchPINI\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[18] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"LVchPINI\",\"MOch_Tm0\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[19] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
           
           strreplace(cadr,\"MOch_Tm0\",\"MOch_Tm1\");
           dpGet(cadr + \":_alert_hdl.3._l_limit\", warl,
                 cadr + \":_alert_hdl.3._u_limit\", warh);
           bias = (warl + warh) / 2;  rndm = outi[20] - 5000;
           rndm = rndm / 100.0;
           dpSet(cadr + \":_original.._value\", bias + rndm);
//           strreplace(cadr,\"MOch_Tm1\",\"LVchDTrp\");
//           strreplace(cadr,\"LVchDTrp\",\"LVchCTrp\");
//           strreplace(cadr,\"LVchCTrp\",\"LVchTLim\");
//           strreplace(cadr,\"LVchTLim\",\"LVchTTrp\");
//           strreplace(cadr,\"LVchTTrp\",\"LVchCLKS\");
//           strreplace(cadr,\"LVchCLKS\",\"LVchCLKR\");
//           strreplace(cadr,\"LVchCLKR\",\"LVchVOut\");
/*
             if((Unum == 0) && (chan== 0))
           { sprintf(dstr,\" %s Bias=%3.1f Rand=%3.1f\",cadr, bias, rndm);
             strreplace(dstr,\"SCTmops1:\",\"\");
             dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(1);
           }                                                       /* Debug */
         }
       } chan++;
     }
   }
 }" 0
EE E E 1 -1 -1 0  0 790
"" 0 1
EE 2
"CBRef""0"
"EClose"E
""
DISPLAY_LAYER, 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
LAYER, 0 
1
LANG:1 6 Layer1
6 0
"Border1"
""
1 0 795 E E E 1 E 1 E N {0,0,0} E N {51,102,153} E E
 E E
1 0 0 0 0 0
EE E
0
1
LANG:1 0 
1
"dashclr"N "_Transparent"
E E 0 1 1 0 1 E U  1 E 0 0 1000 800
2 1
"ErorIndi"
""
1 115 1727 E E E 1 E 1 E N {0,0,0} E N {204,204,204} E E
 E E
1 0 0 0 0 0
EE E
0
1
LANG:1 0 
1
"dashclr"N "_Transparent"
"/* Error Indicator
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
/*===================================-======================================*/
/*                         ERROR INDICATION PANEL                           */
/*-----------------------------------=--------------------------------------*/
/* AUTHORs:        S.G.Basiladze

   DESIGN ISSUEs:  This object has a colour indicator of an error message

   MODIF_HISTORY:  01.03.2001 - first version
                   08.09.2003 - 2-nd  version, Error Indicator is modified
  ===================================-======================================*/

main()
{ dyn_errClass err;

   dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x0);
   dpSet(\"SCTmops1:Eror.Numb:_original.._value\", 0);
   setValue(\"ErorIndi\",\"text\",\"\");
   dpConnect(\"ErrorIndicator\",\"SCTmops1:Eror.Stat:_online.._value\");
   err = getLastError();
     if(dynlen(err) > 0)
   { setValue(\"\", \"color\", \"_dpdoesnotexist\");
   }
 }

/* SHOW DCS ERRORs IN TEXT PANEL                                            */
/*                                                                          */
/*                      Ecod - Error CODe - ALWAYS is ODD                   */
/*                             Bits  0- 1:  Severity of Error:              */
/*                                            0 - Normal (No Error),        */
/*                                            2 - Warning,                  */
/*                                            1 - Alarm,                    */
/*                                            3 - Fatal                     */
/*                                                                          */
 ErrorIndicator(string Dapo, int Eror)
 { int    ecod, enmb;
   string estr, stri;

   dpGet(\"SCTmops1:Eror.Stat:_original.._value\", ecod);
     if((ecod & 0x3) > 0)
   { dpGet(\"SCTmops1:Eror.Name:_original.._value\", estr);
       if((ecod & 0x1) == 0)
     { setValue(\"ErorIndi\",\"backCol\",\"Yellow\");
       dpGet(\"SCTmops1:Warn.Numb:_original.._value\", enmb);
       enmb++;
       dpSet(\"SCTmops1:Warn.Numb:_original.._value\", enmb);
       sprintf(stri,\" WARNING %2d:%s \", enmb, estr);
     } else
     { setValue(\"ErorIndi\",\"backCol\",\"Red\");
       dpGet(\"SCTmops1:Eror.Numb:_original.._value\", enmb);
       enmb++;
       dpSet(\"SCTmops1:Eror.Numb:_original.._value\", enmb);
       sprintf(stri,\" ERROR %2d:%s \", enmb, estr);
     }
     setValue(\"ErorIndi\",\"text\", stri);
/**/
     sprintf(stri,\"\\n %s \\n\", stri);
     Debug(stri);                                             /* Debugger   */
   } else
   { setValue(\"ErorIndi\",\"backCol\",\"Green\");
     setValue(\"ErorIndi\",\"text\",\" NO ERRORs \");
   }
 }" 0
 E 0 1 1 0 1 E U  1 E 12 722 428 788
1 2 0 "s" 0 0 0 64 0 0  12 722
 1
1
LANG:1 119 -microsoft windows-Courier New-normal-r-normal-*-*-110-100-100-*-*-iso8859-1|-12,0,0,0,400,0,0,0,0,3,2,1,49,Courier New
0 ""
1
LANG:1 10  NO ERRORs
1 6 0 "0" 6
0
1 7 0 "1" 6
0
1 8 0 "2" 6
0
1 9 0 "3" 44
0
1 10 0 "4" 44
0
1 11 0 "5" 44
0
4 28
"Line13"
""
1 10 791 E E E 1 E 1 E N {255,255,255} E N {255,255,255} E E
 E E
9 0 0 0 0 0
EE E
0
1
LANG:1 0 
1
"dashclr"N "_Transparent"
E E 0 2 1 0 1 E  990 791 10 791
4 27
"Line12"
""
1 10 792 E E E 1 E 1 E N {0,0,0} E N {255,255,255} E E
 E E
8 0 0 0 0 0
EE E
0
1
LANG:1 0 
1
"dashclr"N "_Transparent"
E E 0 1 1 0 1 E  990 792 10 792
2 29
"MoniIndi"
""
1 1102 2995 E E E 1 E 1 E N {0,0,0} E N {204,204,204} E E
 E E
10 0 0 0 0 0
EE E
0
1
LANG:1 0 
1
"dashclr"N "_Transparent"
"/* Monitor & Debug Indicator
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
/*===================================-======================================*/
/*                 MONITOR & DEBUGGER INDICATION OBJECT                     */
/*-----------------------------------=--------------------------------------*/
/* AUTHORs:        S.G.Basiladze

   DESIGN ISSUEs:  This object has a colour indicator of the Monitoring
                   and Debugger messages

   MODIF_HISTORY:  01.03.2001 - first version
                   22.12.2002 -  2-nd version, Colours made standard
                   27.09.2003 -  3-rd version, Message is taking from DaPo
  ===================================-======================================*/

main()
{ dyn_errClass eror;

  dpSet(\"SCTmops1:Moni.Name:_original.._value\", \"\");
  dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x0);
  setValue(\"MoniIndi\",\"text\",\"\");
  dpConnect(\"MoniDebugger\",\"SCTmops1:Moni.Name:_original.._value\");
  eror = getLastError();
    if(dynlen(eror) > 0)
  { setValue(\"\", \"color\", \"_dpdoesnotexist\");
  }
}

/* SHOW 'WHAT SYSTEM IS DOING' AND DEBUG MESSAGES IN THE TEXT PANEL         */
/*                                                                          */
 MoniDebugger(string Dapo, int Stat)
 { int    stat;
   string mstr;

   dpGet(\"SCTmops1:Moni.Stat:_original.._value\", stat);
   switch(stat & 0x7)
   { case  0:                        /* Normal Status                       */
              setValue(\"MoniIndi\",\"backCol\",\"Green\");
              break;
     case  2:                        /* Warning Status                      */
              setValue(\"MoniIndi\",\"backCol\",\"Yellow\");
              break;
     case  1:                        /* Alarm   Status                      */
              setValue(\"MoniIndi\",\"backCol\",\"Red\");
              break;
     case  3:                        /* Disable Status                      */
              setValue(\"MoniIndi\",\"backCol\",\"Grey\");
              break;
     default: setValue(\"MoniIndi\",\"backCol\",\"Blue\");
   }
   dpGet(\"SCTmops1:Moni.Name:_original.._value\", mstr);
   setValue(\"MoniIndi\",\"text\", mstr);
 }" 0
 E 0 1 1 0 1 E U  1 E 617 722 988 743
1 2 0 "s" 0 0 0 64 0 0  617 722
 1
1
LANG:1 119 -microsoft windows-Courier New-normal-r-normal-*-*-110-100-100-*-*-iso8859-1|-12,0,0,0,400,0,0,0,0,3,2,1,49,Courier New
0 ""
1
LANG:1 34                 Monitor & Debugger
14 3
"DiagIndi"
""
1 611 767 E E E 1 E 1 E N "_WindowText" E N {204,204,204} E E
 E E
3 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 119 -microsoft windows-Courier New-normal-r-normal-*-*-110-100-100-*-*-iso8859-1|-12,0,0,0,400,0,0,0,0,3,2,1,49,Courier New
0 ""
612 765 991 791
3 "s" 0 0 0 0 0 0 
"/* PASSword Diagnostic
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
main()
{
  setValue(\"\",\"backCol\",\"Green\");
  setValue(\"\",\"foreCol\",\"Green\");
  setValue(\"\",\"text\",\"\");
}" 0

"/* PASSword Control
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
/*===================================-======================================*/
/*                 PASSWORD CONTROL & INDICATION OBJECT                     */
/*-----------------------------------=--------------------------------------*/
/* AUTHORs:        S.G.Basiladze

   DESIGN ISSUEs:  This object may be used for password control and
                   as indicator of (Host) system structure messages

   MODIF_HISTORY:  01.03.2001 - first version
                   27.09.2003 -  2-nd version, Message is taking from DaPo
  ===================================-======================================*/

main()
{ dyn_errClass eror;

  dpSet(\"SCTmops1:Nmax.Name:_original.._value\", \"\");
  dpSet(\"SCTmops1:Nmax.Stat:_original.._value\", 0x0);
  setValue(\"\",\"backCol\",\"Green\");       setValue(\"\",\"foreCol\",\"Black\");
  delay(2);
  setValue(\"\",\"text\",\" Enter PASSword for Diagnostic Panel access: \");
  dpConnect(\"DiagIndicator\",\"SCTmops1:Nmax.Name:_original.._value\");
}

/* SHOW DEBUG MESSAGES IN THE TEXT PANEL                                    */
/*                                                                          */
 DiagIndicator(string Dapo, int Stat)
 { int    stat;
   string mstr;

   dpGet(\"SCTmops1:Nmax.Stat:_original.._value\", stat);
   switch(stat & 0x7)
   { case  0:                        /* Normal Status                       */
              setValue(\"DiagIndi\",\"backCol\",\"Green\");
              break;
     case  2:                        /* Warning Status                      */
              setValue(\"DiagIndi\",\"backCol\",\"Yellow\");
              break;
     case  1:                        /* Alarm   Status                      */
              setValue(\"DiagIndi\",\"backCol\",\"Red\");
              break;
     case  3:                        /* Disable Status                      */
              setValue(\"DiagIndi\",\"backCol\",\"Grey\");
              break;
     default: setValue(\"DiagIndi\",\"backCol\",\"Blue\");
   }
   dpGet(\"SCTmops1:Nmax.Name:_original.._value\", mstr);
   setValue(\"DiagIndi\",\"text\", mstr);
 }" 0

"/* PASSword Diagnostic
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
main()
{ string pass;

  getValue(\"\",\"text\", pass);
    if(pass == \"\")
  { ChildPanelOnCentralModal(\"_SCT_Diagn_MoPS.pnl\",\"\",\"\");
  } else
  { setValue(\"\",\"backCol\",\"Red\");
    setValue(\"\",\"foreCol\",\"Blue\");
    setValue(\"\", \"text\",\" Incorrect password, please try again...\");
  } delay(2);
  setValue(\"\",\"backCol\",\"Green\");
  setValue(\"\",\"foreCol\",\"Black\");
  setValue(\"\",\"text\",\" Enter PASSword for Diagnostic Panel access: \");
}" 0

14 4
"CommIndi"
""
1 611 745 E E E 1 E 1 E N "_WindowText" E N {204,204,204} E E
 E E
4 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 119 -microsoft windows-Courier New-normal-r-normal-*-*-110-100-100-*-*-iso8859-1|-12,0,0,0,400,0,0,0,0,3,2,1,49,Courier New
0 ""
612 743 991 769
3 "s" 0 0 0 0 0 0 
"/* PASSword Control
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
main()
{
  setValue(\"\",\"backCol\",\"Green\");
  setValue(\"\",\"foreCol\",\"Green\");
  setValue(\"\",\"text\",\"\");
}" 0

"/* PASSword Control
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
/*===================================-======================================*/
/*                 PASSWORD CONTROL & INDICATION OBJECT                     */
/*-----------------------------------=--------------------------------------*/
/* AUTHORs:        S.G.Basiladze

   DESIGN ISSUEs:  This object may be used for password control and
                   as indicator of (Host) system structure messages

   MODIF_HISTORY:  01.03.2001 - first version
                   27.09.2003 -  2-nd version, Message is taking from DaPo
  ===================================-======================================*/

main()
{ dyn_errClass eror;

  dpSet(\"SCTmops1:Hmax.Name:_original.._value\", \"\");
  dpSet(\"SCTmops1:Hmax.Stat:_original.._value\", 0x0);
  setValue(\"\",\"backCol\",\"Green\");       setValue(\"\",\"foreCol\",\"Black\");
  delay(2);
  setValue(\"\",\"text\",\" Enter PASSword for Control    Panel access: \");
  dpConnect(\"CommIndicator\",\"SCTmops1:Hmax.Name:_original.._value\");
}

/* SHOW DEBUG MESSAGES IN THE TEXT PANEL                                    */
/*                                                                          */
 CommIndicator(string Dapo, int Stat)
 { int    stat;
   string mstr;

   dpGet(\"SCTmops1:Hmax.Stat:_original.._value\", stat);
   switch(stat & 0x7)
   { case  0:                        /* Normal Status                       */
              setValue(\"CommIndi\",\"backCol\",\"Green\");
              break;
     case  2:                        /* Warning Status                      */
              setValue(\"CommIndi\",\"backCol\",\"Yellow\");
              break;
     case  1:                        /* Alarm   Status                      */
              setValue(\"CommIndi\",\"backCol\",\"Red\");
              break;
     case  3:                        /* Disable Status                      */
              setValue(\"CommIndi\",\"backCol\",\"Grey\");
              break;
     default: setValue(\"CommIndi\",\"backCol\",\"Blue\");
   }
   dpGet(\"SCTmops1:Hmax.Name:_original.._value\", mstr);
   setValue(\"CommIndi\",\"text\", mstr);
 }" 0

"/* PASSword Control
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
main()
{ string pass;

  getValue(\"\",\"text\", pass);
    if(pass == \"\")
  { ChildPanelOnCentralModal(\"_SCT_Comm_MoPS.pnl\",\"\",\"\");
  } else
  { setValue(\"\",\"backCol\",\"Red\");
    setValue(\"\",\"foreCol\",\"Blue\");
    setValue(\"\", \"text\",\" Incorrect password, please try again...\");
  } delay(2);
  setValue(\"\",\"backCol\",\"Green\");
  setValue(\"\",\"foreCol\",\"Black\");
  setValue(\"\",\"text\",\" Enter PASSword for Control    Panel access: \");
}" 0

1 12 0 "" 35
0
1 13 0 "" 36
0
1 14 0 "" 37
0
1 15 0 "" 38
0
1 16 0 "" 39
0
1 17 0 "" 40
0
1 18 0 "" 12
0
1 19 0 "" 11
0
1 20 0 "" 24
0
1 21 0 "" 41
0
1 22 0 "" 42
0
1 23 0 "" 13
0
1 25 1 "" 1
0
14 30
"ScanIndi"
""
1 897 10 E E E 1 E 1 E N {0,0,0} E N {255,255,255} E E
 E E
10 0 0 0 0 0
EE E
0
1
LANG:1 0 
0
1
LANG:1 119 -microsoft windows-Courier New-normal-r-normal-*-*-110-100-100-*-*-iso8859-1|-12,0,0,0,400,0,0,0,0,3,2,1,49,Courier New
0 ""
895 8 991 34
3 "s" 0 0 0 0 0 0 
E
"/* Scan Indicator
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
main()
{ dyn_errClass eror;

  dpConnect(\"ShowScan\",\"SCTmops1:Scan.Numb:_original.._value\");
  setValue(\"ScanIndi\",\"backCol\",\"Green\");
  setValue(\"ScanIndi\",\"text\",\" Scan:     0\");
  eror = getLastError();
    if(dynlen(eror) > 0)
  { setValue(\"\", \"color\", \"_dpdoesnotexist\");
  }
}

 ShowScan(string Dapo, int Scan)
 { int    scan;
   string stri;
 
   setValue(\"ScanIndi\",\"backCol\",\"Yellow\");
   dpGet(\"SCTmops1:Scan.Numb:_original.._value\", scan);
   sprintf(stri,\" Scan: %5d\", scan);
   setValue(\"ScanIndi\",\"text\", stri);
   delay(1);
   setValue(\"ScanIndi\",\"backCol\",\"Green\");
 }" 0

E
0
LAYER, 1 
1
LANG:1 6 Layer2
0
LAYER, 2 
1
LANG:1 6 Layer3
0
LAYER, 3 
1
LANG:1 6 Layer4
0
LAYER, 4 
1
LANG:1 6 Layer5
0
LAYER, 5 
1
LANG:1 6 Layer6
0
LAYER, 6 
1
LANG:1 6 Layer7
0
LAYER, 7 
1
LANG:1 6 Layer8
0
3 0 ""
"_SCT_Stat_MoPS.pnl" 440 710 T 6 1 0 1  -1 23  
0
3 1 ""
"objects\\SCT_mTAB_MoPS.pnl" 10 10 T 7 1 0 1  -20 442  
0
0