1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| Dim WithEvents Serveur As OPCServer
Dim Groupes As OPCGroups
Dim WithEvents GrpAPI1 As OPCGroup
Dim WithEvents GrpUnity As OPCGroup
Dim Objets1 As OPCItems
Dim FinCréation As Boolean
Dim Client As String
Dim Nom_Serveur As String
Dim DefaultGroupIsActive As Boolean
Dim DefaultGroupUpdateRate As Long
Dim DefaultGroupDeadband As Single
Dim AnOPCItemCollection As OPCItems
Dim IsActive As Boolean
Dim CurrentValue As Boolean
Dim n As Integer
Dim CompteurItemsGrpAPI1 As Long
Dim NomsItemsGrpAPI1() As String
Dim HandleClientGrpAPI1() As Long
Dim HandleServeurGrpAPI1() As Long
Dim ErreurGrpAPI1() As Long
Const ProgID = "Schneider-Aut.OFS"
Sub main()
Call init
End Sub
'CONNEXION
Private Sub cmdConnection_Click()
Dim i As Integer
If FinCréation = False Then
Set Serveur = New OPCServer
'connection au serveur OPC
Serveur.Connect (ProgID)
Nom_Serveur = Serveur.ServerName
Nom_Serveur_co.Text = Nom_Serveur
Adresse.Text = "10.21.67.39"
Etat.Text = "Connecté"
Client = Serveur.ClientName
Client = "Client " & (n + 1) 'si plusieurs clients
n = n + 1
Nom_client_co.Text = Client
If n = 0 Then
Nom_client_co.Text = "aucun client"
Adresse.Text = ""
Etat.Text = ""
End If
'Création de l'instance de l'objet collection de groupes
Set Groupes = Serveur.OPCGroups
'Propriétés des groupes
'Activation
DefaultGroupIsActive = Groupes.DefaultGroupIsActive
Groupes.DefaultGroupIsActive = False
'Cadence de rafraichissement
DefaultGroupUpdateRate = Groupes.DefaultGroupUpdateRate
Groupes.DefaultGroupUpdateRate = 1000
'Dead Band
DefaultGroupDeadband = Groupes.DefaultGroupDeadband
Groupes.DefaultGroupDeadband = 1
'Création de groupes
Groupes.DefaultGroupIsActive = True
Set GrpAPI1 = Groupes.Add("GrpAPI1")
'Création des instances de l'objet collection d'items
Set Objets1 = GrpAPI1.OPCItems
'Valeur par défaut pour les groupes
Objets1.DefaultIsActive = True
'Creation des items
'Initialisation du compteur d'items
CompteurItemsGrpAPI1 = 4
'Redimensionnements
ReDim NomsItemsGrpAPI1(CompteurItemsGrpAPI1)
ReDim HandleClientGrpAPI1(CompteurItemsGrpAPI1)
NomsItemsGrpAPI1(1) = "API1!heure_appuiBP0"
NomsItemsGrpAPI1(2) = "API1!heure_appuiBP1"
NomsItemsGrpAPI1(3) = "API1!heure_appuiBP2"
NomsItemsGrpAPI1(4) = "API1!heure_retourP"
HandleClientGrpAPI1(1) = 1
HandleClientGrpAPI1(2) = 2
HandleClientGrpAPI1(3) = 3
HandleClientGrpAPI1(4) = 4
'Ajout des items
Objets1.AddItems CompteurItemsGrpAPI1, NomsItemsGrpAPI1, HandleClientGrpAPI1, HandleServeurGrpAPI1, ErreurGrpAPI1
'Activation des groupes
GrpAPI1.IsActive = True
'Autorisation du contrôle de notification
GrpAPI1.IsSubscribed = True
FinCréation = True
End If
'bouttons de commande
cmdDéconnection.Enabled = True
cmdConnection.Enabled = False
End Sub
Sub Tableau_Données()
'Création du tableau pour les données enregistrées
Range("A30:D30").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
.Font.Bold = True
.Font.Size = 12
End With
Selection.Merge
ActiveCell.FormulaR1C1 = "Données enregistrées"
Range("A29").Select
Selection.Offset(2, 0) = "Heure d'appui BP0"
Selection.Offset(2, 1) = "Heure d'appui BP1"
Selection.Offset(2, 2) = "Heure d'appui BP2"
Selection.Offset(2, 3) = "Heure retour pièce"
'Création du tableau pour les données déduites
Range("E30:G30").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
.Font.Bold = True
.Font.Size = 12
End With
Selection.Merge
ActiveCell.FormulaR1C1 = "Données déduites"
Range("A29").Select
Selection.Offset(2, 4) = "Durée traitement"
Selection.Offset(2, 5) = "Nbr Pièces bonnes"
Selection.Offset(2, 6) = "Nbr pièces mauvaises"
Range("A30:G31").Select
Selection.Rows.AutoFit
Selection.Columns.AutoFit
End Sub
'DataChange
Private Sub GrpAPI1_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, HandleClientGrpAPI1() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)
Dim i As Integer
For i = 1 To NumItems
Cells(32 + HandleClientGrpAPI1(i), 4) = TimeStamps(i) ' "Date/Heure"
Next i
End Sub |
Partager