V 10
1
LANG:1 8 (NoName)
PANEL,261 74 626 121 N "_3DFace" 0
"/* OPC Configs Creator
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456*/
/*===================================-======================================*/
/*                         OPC SERVER CONFIGURATION                         */
/*-----------------------------------=--------------------------------------*/

main()
{ string stri;

  dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x2);
  dpSet(\"SCTmops1:Moni.Name:_original.._value\",
        \" Starting...\");                              delay(2);    /* Debug */
        
  MakeConfigs(0x0, 0x8);

  dpGet(\"SCTmops1:Moni.Name:_original.._value\", stri);
  dpSet(\"SCTmops1:Moni.Stat:_original.._value\", 0x0);
  dpSet(\"SCTmops1:Moni.Name:_original.._value\",
        \" Finished...\");                              delay(2);    /* Debug */
  dpSet(\"SCTmops1:Moni.Name:_original.._value\", stri);
}

/* ======================================================================== */
/*                        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);
     if(!connectedState)
   { ;
//     setValue(\"CommInfo\",\"text\",\" WARNING: OPC client is not connected \");
   }
//   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 AlrL, WarL, WarH, AlrH CONFIGs OF DATA_POINT */
/*                  Priority - Prior_3 > Prior_2 > Prior_1                  */
/*                                                                          */
 setAlerts(string dpConfigName, int Priority,
           float Alarm_low, float Warn_low, float Warn_high, float Alarm_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,  // alarm   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,  // alarm   high range
               //  set each range: each range consists of two values (borders)
     dpName + \":_alert_hdl.1._u_limit\", Alarm_low, 
     dpName + \":_alert_hdl.2._l_limit\", Alarm_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\", Alarm_high,
     dpName + \":_alert_hdl.5._l_limit\", Alarm_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 alarm 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 alarm High\",
               // set alert class
     dpName + \":_alert_hdl.1._class\", \"Alarm_\"+Priority+\".\", 
     dpName + \":_alert_hdl.2._class\", \"Warning_\"+Priority+\".\",
     dpName + \":_alert_hdl.4._class\", \"Warning_\"+Priority+\".\",
     dpName + \":_alert_hdl.5._class\", \"Alarm_\"+Priority+\".\",
               // 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\", Alarm_low, 
       dpName + \":_alert_hdl.2._l_limit\", Alarm_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\", Alarm_high,
       dpName + \":_alert_hdl.5._l_limit\", Alarm_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()\\n           OPC Server '\"+opcServerName+\"' does not exist\"); 
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//     Debug(
//\" ERROR in CheckOPCserver(): OPC Server: \"+opcServerName+\" does not exist\"); 
     return;
   }	       //check if OPC group exists
   group = getSystemName() + \"_\" + OPCGroup; 
     if (!dpExists(group))
   { sprintf(estr,
     \" CheckOPCserver()\\n           OPC group '\"+OPCGroup+\"' does not exist\");
     dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
     dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//     Debug(\" ERROR in 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()\\n           while configuring the peripheral address\");
            dpSet(\"SCTmops1:Eror.Name:_original.._value\", estr); 
            dpSet(\"SCTmops1:Eror.Stat:_original.._value\", 0x1);
//            Debug(
//     \" ERROR in setOPCAddress() 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);
   }	  		  
 }

/* CREATE PVSS CONFIGs AND LOAD THEM, MAKE OPC_CONFIG FILE & PVSS OPC ADDRs */
/*                                                                          */
/*                      Load -       ( if Serv == 0x0 or 0x4 or 0x8 )       */
/*                             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, Load NOTHING (OPC Run) */
/*                                                                          */
 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, open;
   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;
                                     /* Some Init Actions                   */   
     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); }
     }
   }                                 /* Str5/6 - OPC Item Name for Send/Recv*/
   sprintf(str5,\"NOT used\");            sprintf(str6,\"NOT used\");
                                     /* Str7/8 - Full Item Name for Connect.*/
   sprintf(str7,\"NOT used\");            sprintf(str8,\"NOT used\");
 
     if((Serv == 0x4) || (Serv == 0x8))
   { host=0; node=0; port=0; unit=0;
             nmax=1; pmax=1; umax=1; /* Node_max, Port_max, Unit_max in Syst*/
     iden = 1;                       /* COB_ID of ELMB (Unit)               */
     s01i = 1;                       /* s01i - Rack number (in config Table)*/
     s07w = \"0x54\";                  /* s07w - Unit 'Stat' (in config Table)*/
     fpdi = fopen(\"OPCadd.bak\",\"w\");
/*
     sprintf(dstr,
\" Init: n=%d<%d, p=%d<%d, u=%d<%d\\n       Rack=%d,       UnitStat: %sh, ID=%d\",
                          node,nmax, port,pmax, unit,umax, s01i, s07w, iden);
     dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr); delay(2);/* Debug */

                                     /* CODE FOR ADDING TO MPS_CRATES       */
     para=0; while(para < 17)        /* Para_max - may changed for Debug    */
     {   if((node < nmax) && (port < pmax) && (unit < umax) && (unit !=  99))
       { rack = s01i - 1;
         busn = (node * pmax) + port;
         sprintf(padr,\"Bus%02d\", busn);
         crat = (node * pmax * umax) + (port * umax) + unit;
         sprintf(uadr,\"Crate%02d\", crat); /* Crate Name (Unit ADdRess)      */
         sprintf(stri,\"SCTmops1:%s%s\",uadr,\".Stat:_original.._value\");
         sscanf(s07w,\"%x\",usts);        dpSet(stri, usts);
/*OPC>*/
           if(((usts & 0x4) > 0) && ((Serv == 0x4) || (Serv == 0x8)))
         { sprintf(str4,\"SCTmops1:%s.Controller\", uadr); /* For Controller  */
           sprintf(str5,\"NOT used\");    sprintf(str6,\"NOT used\");
           sprintf(str7,\"NOT used\");    sprintf(str8,\"NOT used\");
             switch(para)
           { case  0:                /* CC_Reset                            */
//                      fprintf(fpdi,
//                              \"%s_Reset               = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x300+iden);
//                      sprintf(str5,\"%s.CC_Reset.Send\", str4);
//                      sprintf(str7,\"%s.%s.%s_Reset\", padr, uadr, uadr);
//                        if(Serv == 0x8)
//                      { setOPCAddress(str5, str7,
//                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
//                      }
                      break;
             case  1:                /* CCch_Set                            */
                      fprintf(fpdi,
                              \"%s__Set                = %s %x VT_UI1  0\\n\",
                                                   uadr, uadr, 0x400+iden);
                      sprintf(str5,\"%s.CCch_Set.Send\", str4);
                      sprintf(str7,\"%s.%s.%s__Set\", padr, uadr, uadr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                      break;
             case  2:                /* CCchRead                            */
                      fprintf(fpdi,
                              \"%s_Read                = %s %x VT_UI1  0\\n\",
                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.CCchRead.Send\", str4);
                      sprintf(str7,\"%s.%s.%s_Read\", padr, uadr, uadr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                      \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                      break;
             case  3:                /* StartIVCurve                        */
//                      fprintf(fpdi,
//                              \"%s_IVcurve             = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.StartIVCurve.Send\", str4);
                      sprintf(str7,\"%s.%s.%s_IV_Send\", padr, uadr, uadr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                     \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.StartIVCurve.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_IV_Recv\", padr, uadr, uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  4:                /* CCcf_Set                            */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.CCcf_Set.Send\", str4);
                      sprintf(str7,\"%s.%s.%s_CCcf_SetSend\", padr, uadr, uadr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                     \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCcf_Set.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCcf_SetRecv\", padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  5:                /* CCcf_Rst                            */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.CCcf_Rst.Send\", str4);
                      sprintf(str7,\"%s.%s.%s_CCcf_RstSend\", padr,uadr,uadr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                     \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCcf_Rst.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCcf_RstRecv\", padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  6:                /* CCce_NMT                            */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.CCie_NMT.Send\", str4);
                      sprintf(str7,\"%s.%s.%s_CCce_NmtSend\", padr,uadr, uadr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                     \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCie_NMT.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCce_NmtRecv\", padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  7:                /* CC_error                            */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CC_error.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CC_errorRecv\", padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  8:                /* CCieStat                            */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCieStat.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCieStatRecv\", padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  9:                /* CCieBoot                            */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCieBoot.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCieBootRecv\", padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case 10:                /* CCieEcod                            */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCieEcod.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCieEcodRecv\", padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case 11:                /* CCieEcod1                           */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCieEcod1.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCieEcod1Recv\",padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case 12:                /* CCieEcod2                           */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCieEcod2.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCieEcod2Recv\",padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case 13:                /* CCieEcod3                           */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCieEcod3.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCieEcod3Recv\",padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case 14:                /* CCieEcod4                           */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCieEcod4.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCieEcodRecv\",padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case 15:                /* CCieEcod5                           */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCieEcod5.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCieEcod5Recv\",padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case 16:                /* CCcf_Ack                            */
                      fprintf(fpdi,
                              \"%s_Ackn                = %s %x VT_UI1  0\\n\",
                                                   uadr, uadr, 0x540+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.CCcf_Ack.Recv\", str4);
                        sprintf(str8,\"%s.%s.%s_CCcf_AckRecv\",padr,uadr,uadr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             default: ;
           }                         /* LVcaStat - just a Demo for testing  */
/*
             if(para == 0)
           { lvix = 0;
             sprintf(stri,\"Card%d\", lvix);
             sprintf(str4,\"SCTmops1:%s.LV_card%02d.LVcaStat.%s\",uadr,lvix,\"Send\");
//             sprintf(str5,\"%s_%s_Send%s\", uadr, \"LVcaStat\", stri);
             sprintf(str6,\"%s_%s_Recv%s\", uadr, \"LVcaStat\", stri);
//             sprintf(str7,\"%s.%s.%s_%s_Send%s\",
//                           padr, uadr, uadr, \"LVcaStat\", stri);
             sprintf(str8,\"%s.%s.%s_%s_Recv%s\",
                           padr, uadr, uadr, \"LVcaStat\", stri);
////           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\");
             }
           }
             if(para >=  0)
           { sprintf(dstr,
\" Para=%d, Padr: %s, Uadr: %s\\n Str4(DaPo): %s\\n Str5(Cfig): %s\\n Str7(Item): %s\\n Str6(Cfig): %s\\n Str8(Item): %s\",
                             para, padr, uadr, str4, str5, str7, str6, str8);
             dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(1);
           }                                                       /* Debug */
         }
/*<OPC*/
       } para++;
     }
                                     /* CODE FOR ADDING TO MPS_BUSES        */
     para=0; while(para <  6)        /* Para_max - may changed for Debug    */
     {   if((node < nmax) && (port < pmax))
       { busn = (node * pmax) + port;
         sprintf(padr,\"Bus%02d\", busn);
/*OPC>*/
           if((Serv == 0x4) || (Serv == 0x8))
         { sprintf(str4,\"SCTmops1:%s\", padr);
           sprintf(str5,\"NOT used\");    sprintf(str6,\"NOT used\");
           sprintf(str7,\"NOT used\");    sprintf(str8,\"NOT used\");
             switch(para)
           { case  0:                /* Bus_NMT                             */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.Bus_NMT.Send\", str4);
                      sprintf(str7,\"%s.Bus_NmtSend\", padr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                     \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.Bus_NMT.Recv\", str4);
                        sprintf(str8,\"%s.Bus_NmtRecv\", padr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  1:                /* Bus_NGT                             */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.Bus_NGT.Send\", str4);
                      sprintf(str7,\"%s.Bus_NgtSend\", padr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                     \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.Bus_NGT.Recv\", str4);
                        sprintf(str8,\"%s.Bus_NgtRecv\", padr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  2:                /* BusSync                             */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.BusSync.Send\", str4);
                      sprintf(str7,\"%s.BusSyncSend\", padr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                     \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.BusSync.Recv\", str4);
                        sprintf(str8,\"%s.BusSyncRecv\", padr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  3:                /* BusSyncInt                          */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                      sprintf(str5,\"%s.BusSyncInt.Send\", str4);
                      sprintf(str7,\"%s.BusSyncIntSend\", padr);
                        if(Serv == 0x8)
                      { setOPCAddress(str5, str7,
                                     \"VT_UI1\",\"OUT\",\"CANopen\",1,\"Comm\");
                      }
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.BusSyncInt.Recv\", str4);
                        sprintf(str8,\"%s.BusSyncIntRecv\", padr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  4:                /* BusPortError                        */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.BusPortError.Recv\", str4);
                        sprintf(str8,\"%s.BusPortErrorRecv\", padr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             case  5:                /* BusPortErrorCode                    */
//                      fprintf(fpdi,
//                              \"%s_                    = %s %x VT_UI1  0\\n\",
//                                                   uadr, uadr, 0x500+iden);
                        if(Serv == 0x8)
                      { sprintf(str6,\"%s.BusPortErrorCode.Recv\", str4);
                        sprintf(str8,\"%s.BusPortErrorCodeRecv\", padr);
                        setOPCAddress(str6, str8,
                                     \"VT_UI1\",\"IN\",\"CANopen\",1,\"Moni\");
                      }
                      break;
             default: ;
           }
/**/
             if(para >=  0)          /* Para_min - may changed for Debug    */
           { sprintf(dstr,
\" Para=%d, Padr: %s\\n Str4(DaPo): %s\\n Str5(Cfig): %s\\n Str7(Item): %s\\n Str6(Cfig): %s\\n Str8(Item): %s\",
                             para, padr, str4, str5, str7, str6, str8);
             dpSet(\"SCTmops1:Moni.Name:_original.._value\", dstr);  delay(1);
           }                                                       /* Debug */
         }
/*<OPC*/
       } para++;
     }
     
     
      fclose(fpdi);
   }   
 }" 0
EE E E 1 -1 -1 0  0 0
"" 0 1
EE 2
"CBRef""1"
"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
2 1
"MoniIndi"
""
1 801 10920 E E E 1 E 1 E N {0,51,255} 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"
"/* 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\", \"\");
  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 2 2 618 118
1 2 0 "s" 0 0 0 64 0 0  2 2
 1
1
LANG:1 117 -microsoft windows-Courier New-bold-r-normal-*-*-140-100-100-*-*-iso8859-1|-16,0,0,0,700,0,0,0,0,3,2,1,49,Courier New
0 ""
1
LANG:1 14    OPC Creator
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
0