Advertisement
leandrobpedro

Untitled

Jun 21st, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 32.18 KB | None | 0 0
  1. Sub cmdCriaAlarmes_Click()
  2.     SetFocus()
  3.    
  4.     If MsgBox("As discretas, comandos e alarmes antigos serão apagados, confirma ?",vbYesno+vbQuestion,"Confirma")=vbNo Then Exit Sub
  5.     'Msgbox "Função está desativada"
  6.     'EXIT SUB
  7.    
  8.     ' Create folder "Comandos" on "AuxGateway.DNP".
  9.     Call MakeFolder()
  10.  
  11.     Set fso = CreateObject("Scripting.FileSystemObject")
  12.     Set f = fso.OpenTextFile("C:\LogCmdCriaAlarmes.log", 2,true)
  13.    
  14.     NomeSE = Application.GetObject("autoTelas.autoDadosTelas.DadosImportacao.NomeSE").Value
  15.     DriverAquisicao = Application.GetObject(NomeSE & "_IO_01").PathName
  16.     DriverDestinoPOName = "DNP3SlavePO"
  17.     ' DriverDestinoCODName = "DNP3SlaveCOD"
  18.     DriverDestinoPO=Application.GetObject("Distribuicao." & DriverDestinoPOName).PathName
  19.     ' DriverDestinoCOD=Application.GetObject("Distribuicao." & DriverDestinoCODName).PathName
  20.     xoComandoDocString = "Objeto criado automaticamente pela rotina cmdCriaAlarmes"
  21.     EndD=3000 : EndA = 3000 : EndC = 3000
  22.    
  23.     AtmRase = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.RASEXML_OBJ").Value,";")
  24.     AtmRaseD = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.RASEDXML_OBJ").Value,";")
  25.     AtmParalelismo = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.ParalelismoXML_OBJ").Value,";")
  26.     AtmIAD = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.IADXML_OBJ").Value ,";")
  27.     AtmTCD = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.TCDXML_OBJ").Value ,";")
  28.     AtmTCB = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.TCBXML_OBJ").Value ,";")
  29.     AtmTCT = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.TCTXML_OBJ").Value ,";")
  30.     AtmTSP = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.TSPXML_OBJ").Value ,";")
  31.     AtmRASEBF = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.RASEBFXML_OBJ").Value ,";")  
  32.     AtmAlim = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.AlimentadorXML_OBJ").Value ,";")   
  33.     AtmSecc = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.ChaveXML_OBJ").Value ,";")
  34.     AtmDisj = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.DisjuntorXML_OBJ").Value ,";"
  35.     AtmTrafo = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.TrafoXML_OBJ").Value ,";")
  36.     AtmCheckParam = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.CHECKPARAMXML_OBJ").Value ,";")
  37.     AtmRedundancia = split(Application.GetObject("autoTelas.autoDadosTelas.PropriedadesObjetos.RedundanciaXML_OBJ").Value ,";")
  38.    
  39.     If NOT ObjetoExiste(NomeSE) Then
  40.         Msgbox "Subestação não encontrada na aplicação!"
  41.         exit sub
  42.     End if
  43.  
  44.     Set SE = Application.GetObject(NomeSE)
  45.     If ObjetoExiste(NomeSE & ".Protections.RASE") Then
  46.         Set ProtectionRase = Application.GetObject(NomeSE & ".Protections.RASE")
  47.     Else
  48.         Set ProtectionRase = Nothing
  49.     End If
  50.  
  51.     'Limpa as medidas e comandos relacionadas com os objetos de automatismo (RASET, IAD, etc)
  52.     If ObjetoExiste(NomeSE & ".Protections") Then
  53.         For each elem in SE.Item("Protections")
  54.             PercorreProtecoes elem
  55.         Next
  56.     End If
  57.     ApagaMedidasSE SE
  58.     'Limpa os objetos xoComando criados automaticamente por esta rotina anteriormente
  59.     If ObjetoExiste("AuxGateway") Then
  60.         ApagaxoComando Application.GetObject("AuxGateway")
  61.     End If 
  62.        
  63.    
  64.     'Cria as medidas,comandos e alarmes da SE
  65.     If ObjetoExiste(NomeSE & ".Protections") Then
  66.         'Cria Alarmes
  67.         Set FolderArray = CreateObject("System.Collections.ArrayList")
  68.         FolderArray.Add Application.GetObject("Geral")
  69.         FolderArray.Add Application.GetObject("autoDados.Automatismo")
  70.         For Each Folder in Application.GetObject("autoDados.[Subestação]")
  71.             FolderArray.Add Folder
  72.         Next
  73.         For Each Folder in FolderArray
  74.             For Each atm in Folder
  75.                 Select CASE TypeName(atm)
  76.                     Case "XATM_RaseT"
  77.                         VerificaPropAtm SE.Item("Protections"), AtmRase , atm
  78.                     Case "XATM_RaseD"      
  79.                         VerificaPropAtm SE.Item("Protections"), AtmRaseD, atm
  80.                     Case "XATM_Paralelismo"
  81.                         VerificaPropAtm SE.Item("Protections"), AtmParalelismo, atm            
  82.                     Case "XATM_IAD"
  83.                         VerificaPropAtm SE.Item("Protections"), AtmIAD, atm
  84.                     Case "XATM_TCD"
  85.                         VerificaPropAtm SE.Item("Protections"), AtmTCD, atm
  86.                     Case "XATM_TCB"
  87.                         VerificaPropAtm SE.Item("Protections"), AtmTCB, atm    
  88.                     Case "XATM_TCT"
  89.                         VerificaPropAtm SE.Item("Protections"), AtmTCT, atm
  90.                     Case "XATM_TSP"
  91.                         VerificaPropAtm SE.Item("Protections"), AtmTSP, atm
  92.                     Case "XATM_RaseBF"
  93.                         VerificaPropAtm SE.Item("Protections"), AtmRASEBF, atm 
  94.                     Case "XATM_Alim"
  95.                         If ObjetoExiste("[" & NomeSE & "].[" & atm.Name & "]") Then
  96.                             VerificaPropAtm SE.Item(atm.Name), AtmAlim, atm
  97.                         End If     
  98.                     Case "XATM_Secc"
  99.                         If ObjetoExiste("[" & NomeSE & "].[" & atm.Name & "]") Then
  100.                             VerificaPropAtm SE.Item(atm.Name), AtmSecc, atm
  101.                         End If 
  102.                     Case "XATM_Disj_Red"
  103.                         If ObjetoExiste("[" & NomeSE & "].[" & atm.Name & "]") Then
  104.                             VerificaPropAtm SE.Item(atm.Name), AtmDisj, atm
  105.                         End If     
  106.                     Case "XATM_Trafo"
  107.                         If ObjetoExiste("[" & NomeSE & "].[" & atm.Name & "]") Then
  108.                             VerificaPropAtm SE.Item(atm.Name), AtmTrafo, atm
  109.                         End If 
  110.                     Case "XATM_CheckParam"
  111.                         VerificaPropAtm SE, AtmCheckParam, atm
  112.                     Case "xatm_redundancia"
  113.                         VerificaPropAtm SE.Item("Protections"), AtmRedundancia, atm
  114.                 End Select
  115.                
  116.             Next
  117.         Next   
  118.     End If 
  119.    
  120.     Application.GetObject(DriverAquisicao).Save()
  121.     Application.GetObject(DriverDestinoPO).Save()
  122.     ' Application.GetObject(DriverDestinoCOD).Save()
  123.     Application.GetObject("AuxGateway").Save()
  124.     Application.GetObject("Geral").Save()
  125.     SE.Save()
  126.    
  127.     MsgBox "Alarmes criados com sucesso !" & vbCrLf & _
  128.            "Os texto foram criados genericamente para todos os alarmes, será necessário" & vbcrlf & _
  129.            "rever todas as descrições dos alarmes referentes ao automatismo"
  130.    
  131. End Sub
  132.  
  133. Public DriverDestinoPO, DriverDestinoCOD, DriverOrigem, EndD, EndA, EndC, DriverAquisicao, DriverDestinoPOName,DriverDestinoCODName,xoComandoDocString,ProtectionRase,f
  134.  
  135. '-------------------------------------------------------------------------------------
  136. '-------------------------------------------------------------------------------------
  137. '---------------------Rotinas para apagar medidas e tags------------------------------
  138. '-------------------------------------------------------------------------------------
  139. '-------------------------------------------------------------------------------------
  140. Sub PercorreProtecoes(protection)
  141.     Select Case protection.ProtectionType
  142.         Case "RASET", "RASE"
  143.             If AtmExiste("XATM_RaseT") = True Then
  144.                 ApagaMedidasProtecao protection
  145.             End If
  146.         Case "TCD"
  147.             If AtmExiste("XATM_TCD") = True Then
  148.                 ApagaMedidasProtecao protection
  149.             End If
  150.         Case "TCB"
  151.             If AtmExiste("XATM_TCB") = True Then
  152.                 ApagaMedidasProtecao protection
  153.             End If
  154.         Case "TCT"
  155.             If AtmExiste("XATM_TCT") = True Then
  156.                 ApagaMedidasProtecao protection
  157.             End If
  158.         Case "Paralelo"
  159.             If AtmExiste("XATM_Paralelismo") = True Then
  160.                 ApagaMedidasProtecao protection
  161.             End If
  162.         Case "RASED"
  163.             If AtmExiste("XATM_RaseD") = True Then
  164.                 ApagaMedidasProtecao protection
  165.             End If
  166.         Case "IAD"
  167.             If AtmExiste("XATM_IAD") = True Then
  168.                 ApagaMedidasProtecao protection
  169.             End If
  170.         Case "TSP"
  171.             If AtmExiste("XATM_TSP") = True Then
  172.                 ApagaMedidasProtecao protection
  173.             End If
  174.         Case "RASEBF"
  175.             If AtmExiste("XATM_RaseBF") = True Then
  176.                 ApagaMedidasProtecao protection
  177.             End If
  178.         Case "UAC"
  179.             If StrComp(Left(protection.Name,6),"Redund") = 0 Then
  180.                 ApagaMedidasProtecao protection
  181.             End If     
  182.     End Select
  183. End Sub
  184.  
  185. Function AtmExiste(Tipo)
  186.     Dim Retorno
  187.     Retorno = False
  188.     For each Atm in Application.GetObject("autoDados.Automatismo")
  189.         If TypeName(Atm) = Tipo Then
  190.             Retorno = True
  191.             Exit for
  192.         End If
  193.     Next
  194.     AtmExiste = Retorno
  195. End Function
  196.  
  197. Sub ApagaMedidasProtecao(protection)
  198.     If ObjetoExiste(protection.pathName & ".Measurements") Then
  199.         For Each discreta in protection.Item("Measurements")
  200.             ApagaIOTags discreta
  201.             discreta.parent.DeleteObject discreta.Name
  202.         Next
  203.     End If
  204.     If ObjetoExiste(protection.pathName & ".Commands") Then
  205.         If protection.ProtectionType <> "Paralelo" Then
  206.             For Each comando in protection.Item("Commands")
  207.                 comando.parent.DeleteObject comando.Name
  208.             Next
  209.         End If
  210.     End If 
  211. End Sub
  212.  
  213. Sub ApagaMedidasSE(Obj)
  214.     For Each ChildObj in Obj
  215.         Select Case TypeName(ChildObj)
  216.             Case "PowerDiscreteMeasurement","PowerDiscreteCommand","PowerAnalogMeasurement"
  217.                 If Left(ChildObj.Name,4) = "ATM_" Then
  218.                     Obj.DeleteObject ChildObj.Name
  219.                 End If
  220.             Case "PowerTerminal"           
  221.             Case Else
  222.                 ApagaMedidasSE ChildObj
  223.         End Select 
  224.     Next
  225. End Sub
  226. Sub ApagaIOTags(discreta)
  227.     If ObjetoExiste(discreta.PathName & ".Scada") Then
  228.         If ObjetoExiste(discreta.Item("Scada").Tag) Then
  229.             Set tag = Application.GetObject(discreta.Item("Scada").Tag)
  230.             ' For Each DriverDestino in Array(DriverDestinoPO,DriverDestinoCOD)
  231.             For Each DriverDestino in Array(DriverDestinoPO)
  232.                 IOTagDistrPathName = DriverDestino & ".[" & tag.Parent.Name & "].[" & tag.Name & "]"
  233.                 If ObjetoExiste(IOTagDistrPathName) Then
  234.                     Set IOTagDistr = Application.GetObject(IOTagDistrPathName)
  235.                     IOTagDistr.Parent.DeleteObject IOTagDistr.Name
  236.                 End If
  237.             Next       
  238.             tag.parent.DeleteObject tag.name
  239.         End If
  240.     End If
  241. End Sub
  242. Sub ApagaxoComando(Obj)
  243.     For Each ChildObj in Obj
  244.         If TypeName(ChildObj) = "xoComando" Then
  245.             If ChildObj.DocString = xoComandoDocString Then
  246.                 Obj.DeleteObject ChildObj.Name
  247.             End If
  248.         Else
  249.             ApagaxoComando ChildObj
  250.         End If
  251.     Next
  252. End Sub
  253.  
  254. '-----------------------------------FIM-----------------------------------------------
  255.  
  256.  
  257.  
  258. '-------------------------------------------------------------------------------------
  259. '-------------------------------------------------------------------------------------
  260. '-----------------------Rotinas para criar medidas e alarmes--------------------------
  261. '-------------------------------------------------------------------------------------
  262. '-------------------------------------------------------------------------------------
  263.  
  264. Sub VerificaPropAtm(ParentObj, Prop, objAtm)
  265.     NomeProt =""
  266.     ProtectionType = ""
  267.     Select CASE TypeName(objAtm)
  268.         Case "XATM_RaseT"
  269.             NomeProt ="RASET"
  270.         Case "XATM_RaseD"      
  271.             NomeProt="RASED"   
  272.         Case "XATM_RaseBF"     
  273.             NomeProt="RASEBF"
  274.         Case "XATM_Paralelismo"
  275.             NomeProt="Paralelo"
  276.         Case "XATM_IAD"
  277.             NomeProt="IAD"
  278.         Case "XATM_TCD"
  279.             NomeProt="TCD"
  280.         Case "XATM_TCB"
  281.             NomeProt="TCB" 
  282.         Case "XATM_TCT"
  283.             NomeProt="TCT"
  284.         Case "XATM_TSP"
  285.             NomeProt="TSP" 
  286.         Case "xatm_redundancia"
  287.             NomeProt="Redundância"
  288.             ProtectionType = "UAC" 
  289.         Case else
  290.             NomeProt=""                        
  291.     End Select
  292.    
  293.    
  294.     If NomeProt <> "" Then
  295.         If ObjetoExiste(ParentObj.PathName & ".[" & NomeProt & "]") Then
  296.             Set Protecao = ParentObj.Item(NomeProt)
  297.         Else
  298.             Set Protecao = ParentObj.AddObject("PowerProtectionDevice",true,NomeProt)
  299.         End If
  300.         Protecao.DocString = NomeProt
  301.         If ProtectionType <> "" Then
  302.             Protecao.ProtectionType = ProtectionType
  303.         Else       
  304.             Protecao.ProtectionType = NomeProt
  305.         End If
  306.         Set NewParentObj = Protecao
  307.     Else
  308.         Set NewParentObj = ParentObj
  309.     End If 
  310.    
  311.     For i=0 to Ubound(Prop)
  312.         ArrProp = split(Prop(i),":")
  313.         If (Ubound(ArrProp)>=5) And (FiltroMedidas(ArrProp(0)) = False) Then
  314.             CriaMedidas ArrProp,NewParentObj, objAtm
  315.         End If
  316.     Next
  317. End sub
  318.  
  319. Function FiltroMedidas(Propriedade)
  320.  
  321.     Dim Retorno
  322.     Retorno = False
  323.    
  324.     Select Case Screen.Item("ImageListTrafo").Index
  325.         Case "1TRDJ", "1TRSC" '1 Trafo
  326.             Select Case Propriedade
  327.                 Case "BloqAutomaticoCompTR2", "BloqAutomaticoCompTR3", "BloqAutomaticoMeiaTR2", "BloqAutomaticoMeiaTR3", _
  328.                         "PreCondicoesCompTR2", "PreCondicoesCompTR3", "PreCondicoesMeiaTR2", "PreCondicoesMeiaTR3"
  329.                     Retorno = True
  330.             End Select
  331.         Case "2TR2SC", "2TRDJ", "2TRSC", "2TRSCLT" '2 Trafos
  332.             Select Case Propriedade
  333.                 Case "BloqAutomaticoCompTR3", "BloqAutomaticoMeiaTR3", "PreCondicoesCompTR3", "PreCondicoesMeiaTR3"
  334.                     Retorno = True
  335.             End Select
  336.     End Select
  337.    
  338.     'If (Propriedade = "PosConsist") Or (Propriedade = "Defeito") Then
  339.     '   Retorno = True
  340.     'End If
  341.    
  342.     FiltroMedidas = Retorno
  343.  
  344. End Function
  345.  
  346. Sub CriaMedidas(ArrProp, ParentObj, atm)
  347.  
  348.         NomeMedida = ""
  349.         IsStepCommand = False
  350.         If (TypeName(atm) = "XATM_Alim") And ((ArrProp(1) = "CmdSetPrioridade") Or (ArrProp(1) = "Prioridade")) Or _
  351.             (TypeName(atm) = "XATM_RaseT") And (ArrProp(1) = "CmdResetPrioridades") Or _
  352.             (TypeName(atm) = "XATM_Trafo") And ((ArrProp(1) = "CmdAumPot") Or (ArrProp(1) = "CmdDimPot") Or (ArrProp(1) = "PotenciaNominal")) Then
  353.             Set Eqp = ProtectionRase
  354.             If TypeName(ProtectionRase) = "Nothing" Then
  355.                 Mensagem "Não foi possível encontrar a proteção RASE nesta subestação. Algumas medidas não serão criadas. Crie a proteção RASE e execute novamente para garantir que todas as medidas sejam criadas adequadamente."
  356.             End If 
  357.             If TypeName(atm) = "XATM_Alim" Then
  358.                 NomeMedida = atm.Name
  359.             ElseIf TypeName(atm) = "XATM_RaseT" Then
  360.                 NomeMedida = "Reset"
  361.             ElseIf TypeName(atm) = "XATM_Trafo" Then
  362.                 NomeMedida = "Potencia" & Replace(atm.Name,"-","")
  363.                 IsStepCommand = True
  364.             End If
  365.         ElseIf Ubound(ArrProp) >= 6 Then
  366.             EqpPath = ArrProp(6)
  367.             If (Left(EqpPath,3) = "SE.") Or (EqpPath = "SE") Then
  368.                 EqpPath = ParentObj.Context("Substation").PathName & Right(EqpPath,Len(EqpPath)-2)
  369.             End If
  370.             Eqp = -999
  371.             EqpPath = Replace(EqpPath,"Configuração","[Configuração]")
  372.             On Error Resume Next
  373.                 Set Eqp = Application.GetObject(EqpPath)
  374.             On Error GoTo 0
  375.             If Left(TypeName(Eqp),5) <> "Power" Then
  376.                 Mensagem "Error ao definir o caminho do equipamento onde a medida " & ArrProp(1) & " do objeto " & atm.PathName & " será criada. " & chr(13) & _
  377.                         "O PathName """ & EqpPath & """ definido no InternalTag do objeto autoTelas.autoDadosTelas.PropriedadesObjetos é inválido!" & chr(13) & _
  378.                         "Esta medida e seus respectivos IOTags não serão criados."
  379.                 Exit Sub
  380.             End If
  381.         Else
  382.             Set Eqp = ParentObj
  383.         End If 
  384.        
  385.         If TypeName(Eqp) <> "Nothing" Then
  386.             If (TypeName(atm) = "XATM_CheckParam") Then
  387.                 MeasPrefix = "ATM_"
  388.             ElseIf (TypeName(atm) = "xatm_redundancia") Then
  389.                 MeasPrefix = ""
  390.             ElseIf TypeName(Eqp) = "PowerProtectionDevice" Then
  391.                 Select CASE TypeName(atm)
  392.                     Case "XATM_IAD"
  393.                         Set Disj = atm.Disjuntor
  394.                         MeasPrefix = Left(atm.Name,Len(atm.Name)-1) & " (" & Disj.Name & ")" & " - "
  395.                     Case "XATM_TCD"
  396.                         Set Disj = atm.Disjuntor
  397.                         MeasPrefix = Left(atm.Name,Len(atm.Name)-1) & " (" & Disj.Name & ")" & " - "
  398.                     Case "XATM_TCT"
  399.                         Set TR = atm.Transformador
  400.                         MeasPrefix = Left(atm.Name,Len(atm.Name)-1) & " (" & TR.Name & ")" & " - "
  401.                     Case else
  402.                         MeasPrefix = atm.Name & " - "
  403.                 End Select 
  404.             Else
  405.                 MeasPrefix = "ATM_"
  406.             End If
  407.             If NomeMedida = "" Then
  408.                 NomeMedida = MeasPrefix & ArrProp(1)
  409.             End If 
  410.            
  411.             TagReferencia=""
  412.             If (TypeName(atm) = "xatm_redundancia") And (ArrProp(4)="CMDCOS") Then
  413.                 Set TagRedundanciaFolder = GetOrAddObject(Application.GetObject("Geral"),"TagRedundancia","DataFolder","",True)
  414.                 Set TagReferenciaObj = GetOrAddObject(TagRedundanciaFolder,ArrProp(1),"InternalTag","",True)
  415.                 TagReferencia = TagReferenciaObj.PathName
  416.                 On Error Resume Next
  417.                     Execute  "atm." & ArrProp(1) & " = """ & TagReferencia & """"
  418.                 On Error GoTo 0
  419.             Else
  420.                 TagReferencia = replace(atm.PathName,"autoDados", "autoInterface") & ".[" & ArrProp(0) & "]"
  421.             End If 
  422.             If (TypeName(atm) = "XATM_CheckParam") Or (TypeName(atm) = "xatm_redundancia") Then
  423.                 LinkWithValueProperty = False
  424.             Else
  425.                 LinkWithValueProperty = True
  426.             End If 
  427.  
  428.             Select CASE TypeName(atm)
  429.                 Case "XATM_IAD"
  430.                     Set Disj = atm.Disjuntor
  431.                     atmName = Left(atm.Name,Len(atm.Name)-1) & " (" & Disj.Name & ")" & " - "
  432.                 Case "XATM_TCD"
  433.                     Set Disj = atm.Disjuntor
  434.                     atmName = Left(atm.Name,Len(atm.Name)-1) & " (" & Disj.Name & ")" & " - "
  435.                 Case "XATM_TCT"
  436.                     Set TR = atm.Transformador
  437.                     atmName = Left(atm.Name,Len(atm.Name)-1) & " (" & TR.Name & ")" & " - "
  438.                 Case else
  439.                     atmName = atm.Name
  440.             End Select     
  441.  
  442.             If (InStr(1,atmName,"RASE",vbTextCompare) = 1) And (Len(atmName) > 4) Then
  443.                 If Mid(atmName,5,1) <> "-" Then
  444.                     atmName = Left(atmName,4) & "-" & Right(atmName,Len(atmName)-4)
  445.                 End If
  446.             ElseIf (TypeName(atm) = "XATM_CheckParam") Then
  447.                 atmName = ""   
  448.             ElseIf (TypeName(atm) = "xatm_redundancia") Then
  449.                 atmName = "Redundância"
  450.             End If 
  451.            
  452.             Select CASE TypeName(atm)
  453.                 Case "XATM_IAD", "XATM_TCD", "XATM_TCT"
  454.                     Descricao = atmName & ArrProp(5)
  455.                 Case else
  456.                     Descricao = atmName & IIf(atmName <> ""," - ","") & ArrProp(5)
  457.             End Select
  458.  
  459.             Nome = ""
  460.             Nome = ArrProp(0) & " - " & atm.Name
  461.    
  462.             If (ArrProp(2)="bool") Or (ArrProp(2)="integer") Then
  463.                
  464.                 If ArrProp(2)="bool" Then
  465.                     IsDiscrete = True
  466.                     NomePastaDosTags = "Digitais"
  467.                     ConfigEndAq = "1:1:202"
  468.                     ConfigEndDist = "21:1:202"
  469.                     Endereco = EndD
  470.                     EndD = EndD + 1
  471.                     TipoDaMedida = "PowerDiscreteMeasurement"
  472.                     ScadaSourceTypeName = "PowerDiscreteScadaSource"
  473.                     If ArrProp(1) = "ServidorAtivo" Then
  474.                         MeasurementType = "ElipseE3"
  475.                     Else
  476.                         MeasurementType = "Atuação"
  477.                     End If 
  478.                 Else
  479.                     IsDiscrete = False
  480.                     NomePastaDosTags = "Analogicos"
  481.                     ConfigEndAq = "1:1:3205"
  482.                     ConfigEndDist = "12:1:3205"
  483.                     Endereco = EndA
  484.                     EndA = EndA + 1
  485.                     TipoDaMedida = "PowerAnalogMeasurement"
  486.                     ScadaSourceTypeName = "PowerAnalogScadaSource"
  487.                     If InStr(1,ArrProp(1),"Potencia",vbTextCompare) > 0 Then
  488.                         MeasurementType = "PowerGeneric"
  489.                     Else
  490.                         MeasurementType = "Prioridade"
  491.                     End If 
  492.                 End If
  493.                
  494.                 TagAquisicao = ""
  495.                 TagAquisicao = NomePastaDosTags & ".[" & Nome & "]"
  496.    
  497.                 'Cria a tag de aquisicao
  498.                 Set TagAq = CriaTag(DriverAquisicao &"."& TagAquisicao, ConfigEndAq)
  499.                 TagAq.N4=Endereco
  500.  
  501.                 'Cria tag PO_SLAVE
  502.                 PathTagDestino=""
  503.                 PathTagDestino=DriverDestinoPO & "." & NomePastaDosTags & ".[" & Nome & "]"
  504.                 CriaDestinoTag PathTagDestino, ConfigEndDist,  Endereco, TagReferencia,  atm.Name & " " &  ArrProp(5) , atm.Name & " " &  ArrProp(5), LinkWithValueProperty
  505.        
  506.                 'Cria tag COD_SLAVE
  507.                 ' PathTagDestinoCOD=""
  508.                 ' PathTagDestinoCOD=DriverDestinoCOD & "." & NomePastaDosTags & ".[" & Nome & "]"
  509.                 ' CriaDestinoTag PathTagDestinoCOD, ConfigEndDist,  Endereco, TagReferencia,  atm.Name & " " &  ArrProp(5) , atm.Name & " " &  ArrProp(5), LinkWithValueProperty
  510.    
  511.                 Set Measurements = GetOrAddObject(Eqp,"Measurements","PowerMeasurementGroup","",True)
  512.                 Set Medida = GetOrAddObject(Measurements,NomeMedida,TipoDaMedida,"",False)
  513.                 Set ScadaSource = GetOrAddObject(Medida,"Scada",ScadaSourceTypeName,"",False)
  514.                 ScadaSource.Tag = TagAq.pathname & ".Value"
  515.                 Medida.DocString = Descricao
  516.                 Medida.MeasurementType = MeasurementType
  517.                 Medida.ActiveSource = 1
  518.                 Medida.Activate
  519.                 ScadaSource.Activate
  520.                
  521.                 If (StrComp(ArrProp(1),"Prioridade",vbTextCompare) = 0) And (TypeName(Medida) = "PowerAnalogMeasurement") Then
  522.                     Set OperatorSource = GetOrAddObject(Medida,"Operator","PowerAnalogOperatorSource","",True)
  523.                     OperatorSource.Value = "ControleTR01"
  524.                 End If
  525.                
  526.                 If IsDiscrete Then
  527.                     If ObjetoExiste(Medida.PathName & "." & ArrProp(1))=False Then
  528.                         Set alr = Medida.AddObject("DigitalAlarmSource",true,ArrProp(1))
  529.                     Else
  530.                         Set alr = Medida.Item(ArrProp(1))
  531.                     End If
  532.                     If MeasurementType = "ElipseE3" Then
  533.                         alr.DigitalMessageText = atmName & IIf(atmName <> ""," - ","") &  ArrProp(5) & " - Elipse E3 - B"
  534.                         alr.DigitalReturnMessageText = atmName & IIf(atmName <> ""," - ","") &  ArrProp(5) & " - Elipse E3 - A"
  535.                     Else
  536.                         alr.DigitalMessageText = atmName & IIf(atmName <> ""," - ","") &  ArrProp(5) & " - Atuado"
  537.                         alr.DigitalReturnMessageText = atmName & IIf(atmName <> ""," - ","") &  ArrProp(5) & " - Desatuado"
  538.                     End If
  539.                     alr.DocString = Descricao
  540.                     alr.Digital = True
  541.                     If (InStr(1,ArrProp(1),"PreCond",vbTextCompare) > 0) Or (ArrProp(1) = "ServidorAtivo") Then
  542.                         IsEvent = True
  543.                     Else
  544.                         IsEvent = False
  545.                     End If 
  546.                     If IsEvent Then
  547.                         alr.Deactivate()
  548.                         alr.Event = True
  549.                         alr.Activate()
  550.                     End If 
  551.                     If (InStr(1,ArrProp(1),"PotenciaExcedida",vbTextCompare) = 1) Then
  552.                         alr.Delay = 60000
  553.                     End If
  554.                     If (InStr(1,ArrProp(1),"Automatico",vbTextCompare) > 1) Or (InStr(1,ArrProp(1),"PreCond",vbTextCompare) > 0) Then
  555.                         alr.Delay = 30000
  556.                     End If
  557.                 End If 
  558.             End If
  559.    
  560.             If ArrProp(4)="CMDCOS" Then
  561.            
  562.                 Endereco = EndC
  563.                 EndC = EndC + 1
  564.                 CaminhoTag = ".Comandos.[" & Nome & "]"
  565.    
  566.                 'Cria a tag de aquisicao
  567.                 Set TagAq = CriaTag(DriverAquisicao & CaminhoTag, "1:5:1201")
  568.                 TagAq.N4=Endereco
  569.    
  570.                 'Cria tag PO_SLAVE
  571.                 PathTagDestino=""
  572.                 PathTagDestino=DriverDestinoPO & CaminhoTag
  573.                 CriaDestinoTag PathTagDestino, "12:5:1201",  Endereco, "", ArrProp(5), "", LinkWithValueProperty
  574.                 CriaObjComando CaminhoTag, DriverDestinoPOName, Nome, PathTagDestino, TagReferencia
  575.    
  576.                 'Cria tag COD_SLAVE
  577.                 ' PathTagDestinoCOD=""
  578.                 ' PathTagDestinoCOD=DriverDestinoCOD & CaminhoTag
  579.                 ' CriaDestinoTag PathTagDestinoCOD, "12:5:1201",  Endereco, "", ArrProp(5), "", LinkWithValueProperty
  580.                 ' CriaObjComando CaminhoTag, DriverDestinoCODName, Nome, PathTagDestinoCOD, TagReferencia
  581.                
  582.                 Set Commands = GetOrAddObject(Eqp,"Commands","PowerCommandGroup","",True)
  583.                 If IsStepCommand Then
  584.                     Set cmd_discreto = GetOrAddObject(Commands,NomeMedida,"PowerStepCommand","",False)
  585.                 Else
  586.                     If StrComp(ArrProp(1),"CmdNormalizar",vbTextCompare) = 0 Then
  587.                         Set cmd_discreto = GetOrAddObject(Commands,Replace(NomeMedida,"Normalizar","Liberar_Normalizar"),"PowerDiscreteCommand","",False)
  588.                     ElseIf StrComp(ArrProp(1),"CmdLiberar",vbTextCompare) = 0 Then
  589.                         Set cmd_discreto = GetOrAddObject(Commands,Replace(NomeMedida,"Liberar","Liberar_Normalizar"),"PowerDiscreteCommand","",False)
  590.                     Else
  591.                         Set cmd_discreto = GetOrAddObject(Commands,NomeMedida,"PowerDiscreteCommand","",False)
  592.                     End If
  593.                 End If 
  594.                
  595.                 If StrComp(ArrProp(1),"CmdNormalizar",vbTextCompare) = 0 Then
  596.                     cmd_discreto.DocString = Replace(Descricao,"normalizar","Liberar / Normalizar")
  597.                 ElseIf StrComp(ArrProp(1),"CmdLiberar",vbTextCompare) = 0 Then
  598.                     cmd_discreto.DocString = Replace(Descricao,"liberar","Liberar / Normalizar")
  599.                 Else
  600.                     cmd_discreto.DocString = Descricao
  601.                 End If
  602.                
  603.                 Set InterlocksArray = CreateObject("System.Collections.ArrayList")
  604.                
  605.                 If StrComp(ArrProp(1),"CmdBloqueioOper",vbTextCompare) = 0 Then
  606.    
  607.                     cmd_discreto.CommandType = "Bloquear"
  608.                     cmd_discreto.Conversion = "DNP_TripClose_PulseOn_Inv"
  609.                     cmd_discreto.Activate()
  610.                    
  611.                     InterlocksArray.Add Array(MeasPrefix & "BloqueioOperador",1)
  612.                     CreateCommandUnit cmd_discreto,"Bloquear","Bloquear",TagAq.PathName,InterlocksArray
  613.                    
  614.                     InterlocksArray.Clear
  615.                     InterlocksArray.Add Array(MeasPrefix & "BloqueioOperador",0)
  616.                     CreateCommandUnit cmd_discreto,"Desbloquear","Desbloquear",TagAq.PathName,InterlocksArray
  617.                
  618.                 ElseIf StrComp(ArrProp(1),"CmdHabTrocaAuto",vbTextCompare) = 0 Then
  619.    
  620.                     cmd_discreto.CommandType = "Habilitacao"
  621.                     cmd_discreto.Conversion = "DNP_TripClose_PulseOn_Inv"
  622.                     cmd_discreto.Activate()
  623.                    
  624.                     InterlocksArray.Add Array(MeasPrefix & "TrocaAutoDesabilitada",1)
  625.                     CreateCommandUnit cmd_discreto,"Desabilitar","Desabilitar",TagAq.PathName,InterlocksArray
  626.                    
  627.                     InterlocksArray.Clear
  628.                     InterlocksArray.Add Array(MeasPrefix & "TrocaAutoDesabilitada",0)
  629.                     CreateCommandUnit cmd_discreto,"Habilitar","Habilitar",TagAq.PathName,InterlocksArray
  630.  
  631.                 ElseIf (StrComp(ArrProp(1),"CmdLiberar",vbTextCompare) = 0) Or (StrComp(ArrProp(1),"CmdNormalizar",vbTextCompare) = 0) Then
  632.    
  633.                     cmd_discreto.CommandType = "Liberacao"
  634.                     cmd_discreto.Conversion = "DNP_Close_PulseOn"
  635.                     cmd_discreto.Activate()
  636.                    
  637.                     If StrComp(ArrProp(1),"CmdLiberar",vbTextCompare) = 0 Then            
  638.                         InterlocksArray.Add Array(MeasPrefix & "BloqueioAutomaticoLib",1)
  639.                         InterlocksArray.Add Array(MeasPrefix & "BloqueioOperador",1)
  640.                         InterlocksArray.Add Array(MeasPrefix & "BloqueioGeral",1)
  641.                         InterlocksArray.Add Array(MeasPrefix & "PreCondicoesLib",0)
  642.                            
  643.                         CreateCommandUnit cmd_discreto,"Liberar","Liberar",TagAq.PathName,InterlocksArray  
  644.                    
  645.                     ElseIf StrComp(ArrProp(1),"CmdNormalizar",vbTextCompare) = 0 Then
  646.                         InterlocksArray.Add Array(MeasPrefix & "BloqueioAutomaticoNorm",1)
  647.                         InterlocksArray.Add Array(MeasPrefix & "BloqueioOperador",1)
  648.                         InterlocksArray.Add Array(MeasPrefix & "BloqueioGeral",1)
  649.                         InterlocksArray.Add Array(MeasPrefix & "PreCondicoesNorm",0)
  650.                        
  651.                         CreateCommandUnit cmd_discreto,"Normalizar","Normalizar",TagAq.PathName,InterlocksArray
  652.                        
  653.                     End If
  654.                    
  655.                 ElseIf (StrComp(ArrProp(1),"CmdReset",vbTextCompare) = 0) Or (StrComp(ArrProp(1),"CmdResetPrioridades",vbTextCompare) = 0) Then
  656.    
  657.                     cmd_discreto.CommandType = "Reset"
  658.                     cmd_discreto.Conversion = "DNP_Close_PulseOn"
  659.                     cmd_discreto.Activate()
  660.                            
  661.                     CreateCommandUnit cmd_discreto,"Reset","Reset",TagAq.PathName,InterlocksArray  
  662.                    
  663.                 ElseIf IsStepCommand Then
  664.                    
  665.                     cmd_discreto.CommandType = "Potencia"
  666.                     cmd_discreto.Conversion = "DNP_Close_PulseOn"
  667.                     cmd_discreto.Activate()
  668.                    
  669.                     If StrComp(ArrProp(1),"CmdAumPot",vbTextCompare) = 0 Then
  670.                         CreateCommandUnit cmd_discreto,"Subir","StepUp",TagAq.PathName,InterlocksArray
  671.                     Else
  672.                         CreateCommandUnit cmd_discreto,"Descer","StepDown",TagAq.PathName,InterlocksArray
  673.                     End If
  674.                    
  675.                 Else
  676.    
  677.                     cmd_discreto.CommandType = "Ativar"
  678.                     cmd_discreto.Conversion = "PulseON"
  679.                     cmd_discreto.Activate()
  680.  
  681.                     Select Case ArrProp(1)
  682.                         Case "CmdSetPrioridade"
  683.                             CreateCommandUnit cmd_discreto,"Prioridade","Ativar",TagAq.PathName,InterlocksArray
  684.                         Case "CmdTransfABsemIsolacao", "CmdTransfABcomIsolacao", "CmdTransfBAsemIsolacao", "CmdTransfBAcomIsolacao"
  685.                             CreateCommandUnit cmd_discreto,"Transferir","Ativar",TagAq.PathName,InterlocksArray
  686.                         Case Else
  687.                             CreateCommandUnit cmd_discreto,"Ativar","Ativar",TagAq.PathName,InterlocksArray
  688.                     End Select 
  689.                 End If
  690.             End If
  691.         End If 'TypeName(Eqp) <> "Nothing"
  692.  
  693. End sub
  694.  
  695. Sub CreateCommandUnit(ParentObj,CommandUnitName,CommandName,OperateWriteTag,InterlocksArray)
  696.    
  697.     If ObjetoExiste(ParentObj.PathName & ".UnidadeComando1") Then
  698.         OriginalName = "UnidadeComando1"
  699.     Else
  700.         OriginalName = "UnidadeComando2"
  701.     End If 
  702.     Set CommandUnit = GetOrAddObject(ParentObj,CommandUnitName,"PowerCommandUnit",OriginalName,False)
  703.     CommandUnit.OperateWriteTag = OperateWriteTag
  704.     CommandUnit.CommandName = CommandName
  705.     CommandUnit.Activate()
  706.    
  707.     For Each InterlockArray in InterlocksArray
  708.         Set Interlocks = GetOrAddObject(CommandUnit ,"Interlocks", "PowerInterlockGroup", "", True)
  709.         Set InterlockUnit = GetOrAddObject(Interlocks, InterlockArray(0), "PowerInterlockUnit", "Intertravamento1", True)
  710.         InterlockUnit.ComparisonOperator = 0
  711.         InterlockUnit.Measurement = InterlockUnit.Parent.Parent.Parent.Parent.Parent.PathName & ".Measurements.[" & InterlockArray(0) & "]"
  712.         InterlockUnit.ComparisonValue = InterlockArray(1)
  713.     Next   
  714.    
  715. End Sub
  716.  
  717. '-----------------------------------FIM-----------------------------------------------
  718.  
  719. Function ObjetoExiste(objpath)
  720.     ObjetoExiste=False
  721.     On error resume next
  722.         tst=""
  723.         tst= Application.GetObject(objpath).PathName
  724.     On error goto 0
  725.     If tst<>"" Then
  726.         ObjetoExiste=True
  727.     End If
  728. End Function
  729.  
  730. Function CriaTag(PathTagCompleto, Conf)  
  731.  
  732.     PathDriver = mid(PathTagCompleto,1,inStr(PathTagCompleto,".")-1)
  733.     PathTag = replace(PathTagCompleto, PathDriver & "." ,"")
  734.     'Verifica se o driver existe
  735.     If ObjetoExiste(PathDriver)=False Then
  736.         Mensagem("O Driver "& PathDriver & " NÃO existe!")
  737.         Mensagem("O ponto " & PathTag & " não foi criado")
  738.         'Exit Function
  739.     End If 
  740.  
  741.     PathTag = split(PathTag,".")
  742.     'Varre até o penultimo Nível
  743.     For i=0  to UBound(PathTag)-1
  744.        
  745.         Set objPai = Application.GetObject(PathDriver)
  746.  
  747.         If PathTag(i) <> "" Then
  748.             on error resume next
  749.                 tst = -999
  750.                 tst = objPai.Item(replace(replace(PathTag(i),"[","") ,"]","")).PathName  
  751.             on error goto 0
  752.             If tst=-999 Then  
  753.                 Set NewObj = objPai.AddObject("IOFolder",True, replace(replace(PathTag(i),"[","") ,"]","") )
  754.             Else
  755.                 Set NewObj = objPai.Item(replace(replace(PathTag(i),"[","") ,"]",""))
  756.             End If
  757.             PathDriver = NewObj.PathName
  758.         End If 
  759.     Next
  760.    
  761.     'Cria a tag
  762.      on error resume next
  763.         tst = -999
  764.         Set tgCriada = NewObj.Item(replace( replace(PathTag(UBound(PathTag)),"[","") ,"]",""))
  765.         tst = tgCriada.PathName  
  766.     on error goto 0
  767.    
  768.     If tst=-999 Then
  769.         Set tg = NewObj.AddObject("IOTag",True,  replace( replace(PathTag(UBound(PathTag)),"[","") ,"]","") )
  770.         tg.AdviseType=0
  771.         Set TagDrv=tg
  772.     Else
  773.         tgCriada.AdviseType=0
  774.         Set TagDrv = tgCriada
  775.     End If
  776.  
  777.     If Conf<>"" then
  778.         cnf = Split(Conf, ":")
  779.         TagDrv.N1 = cLng(cnf(0))
  780.         TagDrv.N2 = cLng(cnf(1))
  781.         TagDrv.N3 = cLng(cnf(2))
  782.     End If
  783.     TagDrv.N4 = Endereco
  784.     TagDrv.DocString = Desc
  785.     TagDrv.AdviseType=0
  786.     If TagDrv.N2 = 5 Then
  787.         TagDrv.AllowRead = False
  788.         TagDrv.AllowWrite = True   
  789.     Else
  790.         TagDrv.AllowRead = True
  791.         TagDrv.AllowWrite = False
  792.     End If
  793.    
  794.     Set CriaTag = TagDrv
  795.    
  796. End Function
  797.  
  798. Sub CriaDestinoTag(PathTag, Conf,  Endereco, TagDrvReferencia, Desc, Estado, LinkWithValueProperty)
  799.     If ObjetoExiste(PathTag)=False Then
  800.         Set TagDrv  = CriaTag(PathTag, "")
  801.     Else
  802.         Set TagDrv = Application.GetObject(PathTag)
  803.     End If
  804.     TagDrv.Deactivate()
  805.     If Conf<>"" then
  806.         cnf = Split(Conf, ":")
  807.         TagDrv.N1 = cLng(cnf(0))
  808.         TagDrv.N2 = cLng(cnf(1))
  809.         TagDrv.N3 = cLng(cnf(2))
  810.     End If
  811.     TagDrv.N4 = Endereco
  812.     TagDrv.DocString = Desc
  813.     TagDrv.AdviseType=0
  814.     TagDrv.AllowRead=False
  815.     TagDrv.AllowWrite=True
  816.     If TagDrv.N2=5 Then
  817.         TagDrv.EnableDriverEvent=True
  818.         TagDrv.EnableDeadband=False
  819.         TagDrv.AllowRead=True
  820.         TagDrv.AllowWrite=False
  821.     End If
  822.    
  823.     'If Estado<>"" AND TagDrv.N2<>5 Then
  824.     '   TagDrv.Links.CreateLink "Value", TagDrvReferencia & ".Value=" & Estado, 0      
  825.     'Else
  826.     If TagDrvReferencia <> "" Then
  827.         TagDrv.Links.CreateLink "Value", TagDrvReferencia & IIf(LinkWithValueProperty,".Value",""), 0  
  828.     End If 
  829.     'End If
  830.     TagDrv.Activate()
  831. End Sub
  832.  
  833.  
  834. Sub CriaObjComando(PathTag, DriverName, NomeTag, TagIn, TagOut)
  835.     'Cria objet de dados de comando
  836.     PathObj = "AuxGateway.DNP.[" & DriverName & "]" & PathTag
  837.  
  838.     NewLib = -999
  839.     If ObjetoExiste(PathObj) Then
  840.         Set NewLib = Application.GetObject(PathObj)
  841.     Else
  842.         PathObj = "AuxGateway.DNP.[" & DriverName & "]" & replace(PathTag,".[" & NomeTag & "]","")
  843.         Set NewLib = Application.GetObject(PathObj).AddObject("xoComando",True,NomeTag)
  844.     End If
  845.    
  846.     If TypeName(NewLib) = "xoComando" Then
  847.         NewLib.TagIN1=TagIn
  848.         NewLib.TagOUT1=TagOut
  849.         NewLib.ValueIn1=65
  850.         NewLib.ValueOUT1=2
  851.        
  852.         NewLib.TagIN2=cStr(TagIn)
  853.         NewLib.TagOUT2=TagOut
  854.         NewLib.ValueIn2=129
  855.         NewLib.ValueOUT2=1
  856.        
  857.         NewLib.DocString = xoComandoDocString
  858.            
  859.     End If             
  860. End Sub
  861.  
  862. Function GetOrAddObject(byRef ParentObj,ObjName,ObjType,OriginalName,MustActivate)
  863.     Obj = -999
  864.     On Error Resume Next
  865.         Set Obj = ParentObj.GetChildObject("[" & ObjName & "]")
  866.     On Error GoTo 0
  867.     If TypeName(Obj) = "Integer" Then  
  868.         On Error Resume Next
  869.             Set Obj = ParentObj.GetChildObject("[" & OriginalName & "]")
  870.         On Error GoTo 0
  871.         If TypeName(Obj) = "Integer" Then  
  872.             Set Obj = ParentObj.AddObject(ObjType,MustActivate,ObjName)
  873.         Else
  874.             Obj.Name = ObjName
  875.         End If 
  876.     ElseIf Not MustActivate Then
  877.         Obj.Deactivate()
  878.     End If
  879.     Set GetOrAddObject = Obj   
  880. End Function
  881.  
  882. Sub Mensagem(msg)  
  883.     MsgBox msg, vbInformation+vbOkOnly,"Atenção"
  884. End Sub
  885.  
  886. Sub MakeFolder()
  887.     Dim folder
  888.     Dim slave
  889.  
  890.     On Error Resume Next
  891.     Set slave = Application.GetObject("AuxGateway.DNP.DNP3SlavePO")
  892.     Set folder = slave.GetChildObject("Comandos")
  893.  
  894.     If ( Err ) Then
  895.         Set folder = slave.AddObject("DataFolder", True, "Comandos")
  896.     End If
  897.     On Error GoTo 0
  898. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement