leandrobpedro

GE iFix Read Real Time Data

Sep 15th, 2019 (edited)
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  2. ' Description   : Exporta dados correntes do GE iFix database (pdb)
  3. ' Author        : intech@intech-automacao.com.br
  4. ' Date          : 2019.09.13
  5. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  6. Option Explicit
  7. Sub ExportIfixCurrentPdbData()
  8.     Dim arr As Variant
  9.     Dim fds As Object
  10.     Dim i As Integer
  11.     Dim oDataGroup As Object
  12.     Dim regex As Object
  13.     Dim sFilePath As String
  14.     Dim sFolder As String
  15.     Dim sNodeName As String
  16.     Dim sReadLine As String
  17.     Dim tag As Variant
  18.  
  19.     ' Inicializa arr como Array
  20.    arr = Array()
  21.    
  22.     Set fds = CreateObject("FixDataSystems.Intellution FD Data System Control")
  23.    
  24.     ' Regular expression ignora cabecalho, comentario e linhas vazias.
  25.    Set regex = CreateObject("VBScript.RegExp")
  26.     regex.Pattern = "^(\[|\!)|^$"
  27.    
  28.     ' Pasta %temp%
  29.    sFolder = Environ("temp")
  30.     sFilePath = sFolder & "\MyPDB.csv "
  31.    
  32.     ' Exporta PDB para %temp%
  33.    Shell "dbexporter /n" & System.MyNodeName & " /o" & sFilePath & "/r"
  34.    
  35.     Open sFilePath For Input As #1
  36.    
  37.     Do Until EOF(1)
  38.         Line Input #1, sReadLine
  39.        
  40.         If Not regex.Test(sReadLine) Then
  41.             ReDim Preserve arr(UBound(arr) + 1)
  42.             arr(UBound(arr)) = Replace(Split(sReadLine, ";")(1), """", "")
  43.         End If
  44.     Loop
  45.     Close #1
  46.    
  47.     Set oDataGroup = fds.Groups.Add("DataGroup")
  48.  
  49.     ' sNodeName = "fix32." & ""
  50.    sNodeName = "fix32." & System.MyNodeName & "."
  51.     For Each tag In arr
  52.         oDataGroup.DataItems.Add sNodeName & tag & ".f_cv"
  53.     Next
  54.  
  55.     oDataGroup.Read
  56.    
  57.     For i = 1 To oDataGroup.DataItems.Count
  58.         Debug.Print arr(i - 1), oDataGroup.DataItems.Item(i).Value
  59.     Next
  60. End Sub
Add Comment
Please, Sign In to add comment