hamma86
Messages postés4Date d'inscriptionmardi 20 janvier 2009StatutMembreDernière intervention 2 juin 2011
-
2 juin 2011 à 00:18
cs_Jack
Messages postés14006Date d'inscriptionsamedi 29 décembre 2001StatutModérateurDernière intervention28 août 2015
-
2 juin 2011 à 03:52
salut à tous j'ai trouvé ce code pour la création d'un clent opc et lors de l'exucution je sais pas comment introduire le nom du serveur OPC dans le comboBox
Option Explicit
Dim WithEvents OPCMyserver As OPCServer 'OPC Server object
Dim WithEvents OPCMygroups As OPCGroups 'OPC Group object collection
Dim WithEvents OPCMygroup As OPCGroup 'OPC Group object
Dim OPCMyitems As OPCItems 'OPC Item object collection
Dim OPCMyitem As OPCItem 'OPC Item object
'Dim OPCMyBrowser As OPCBrowser 'OPC Browser object
Dim ItemServerHandles() As Long 'OPC Item Handle
Dim ClientHandles(1) As Long 'OPC Client Handle
Dim OPCItemIDs(1) As String 'OPC Item ID
Dim Errors() As Long 'OPC Item Errors
Dim BrowseLevel As Integer 'Current level in the OPC Browser
Dim ConnectFlag As Boolean
Private Sub cmdConnect_Click()
Dim vName As Variant
lblServer.Caption = cboOPC_Servers.List(cboOPC_Servers.ListIndex) 'We show the OPC server selected
If lblServer.Caption = "" Then 'If no OPC server found, we display an Error MsgBox
MsgBox "Impossible to find an active OPC server", vbOKOnly + vbExclamation
End If
If ConnectFlag = False Then 'If we are not connected
On Error GoTo ConnectError
Set OPCMyserver = New OPCServer
OPCMyserver.Connect lblServer.Caption 'We try to connect to OPC server
Set OPCMygroups = OPCMyserver.OPCGroups 'We load the OPC Groups
Set OPCMygroup = OPCMygroups.Add("boubakri_group") 'We add a group, the name is not important
Set OPCMyitems = OPCMygroup.OPCItems 'We load the OPC Items located in the OPC Group
ConnectFlag = True 'We are now connected
cmdConnect.Caption = "Disconnect"
BrowseLevel = 0 'Initializing of the position in the OPC server
Set OPCMyitems = Nothing 'Delete Item collection
Set OPCMyitem = Nothing 'Delete Item object
Set OPCMygroups = Nothing 'Delete Group collection
Set OPCMygroup = Nothing 'Delete Group object
' Set OPCMyBrowser = Nothing
OPCMyserver.Disconnect 'Diconnection
Set OPCMyserver = Nothing 'clear the OPC server object
ConnectFlag = False 'We are not connected anymore
cmdConnect.Caption = "Connect to OPC Server"
Exit Sub
ConnectError:
MsgBox "Error Connecting", vbOKOnly + vbExclamation
End Sub
Private Sub Command1_Click()
If ConnectFlag = True Then
Call cmdConnect_Click
End If
End
End Sub
Private Sub Command2_Click()
Form3.Show
End Sub
Private Sub Form_Load()
'Dim z As String
'z = InputBox("new value", "modif")
Dim Getserver As OPCServer 'declaration d'un serveur OPC
Dim Servers As Variant 'Array which contains all the OPC servers set up on the computer
Dim i As Integer 'Index of the previous array
cboOPC_Servers.Clear 'Erase the OPC servers combo box
Set Getserver = New OPCServer 'We ceate an OPC server objet instance
Servers = Getserver.GetOPCServers 'We get all the OPC servers set up on the computer
For i = LBound(Servers) To UBound(Servers) 'We add all the OPC servers found on the computer to the combo box
cboOPC_Servers.AddItem Servers(i) ' remplir la boite de dialogue des serveurs OPC oar les serveurs disponibles
Next i
Set Getserver = Nothing 'We clear the created OPC server object
'cboOPC_Servers.ListIndex = 0 'We show the fisrt OPC server found in the combo box