• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 832
  • Last Modified:

OPC Alarms and Events Client

Hello,

 For a VB application I would like to have a connection to an OPC Alarms & Events server. Does anyone have a code example to create a connection and catch the events from an OPC AE server?
 I've tried it out for myself but I keep getting stuck (VB crashes) when I create an OPCEventSubscription

 This is the code I created so far:

Option Explicit

Private opcAEServer As OPCEventServer
Private opcAESubscripts As OPCEventSubscriptions
Private opcAESubscript As OPCEventSubscription

Private varServers As Variant

Private Sub cmdConnect_Click()
On Error GoTo ErrorHandler

Set opcAEServer = New OPCEventServer
varServers = opcAEServer.GetOPCServers

opcAEServer.Connect varServers(0)

If opcAEServer.ServerState <> OPCServerState.OPCRunning Then
    MsgBox "OPC AE server is not running"
    Set opcAEServer = Nothing
    Exit Sub
End If

Set opcAESubscripts = opcAEServer.OPCEventSubscriptions
opcAESubscripts.DefaultBufferTime = 0
opcAESubscripts.DefaultMaxSize = 0
opcAESubscripts.DefaultIsActive = True

'Set opcAESubscript = opcAESubscripts.Add("TestApp")

Exit Sub
ErrorHandler:
MsgBox "Error Connecting to OPC AE : " & Err.Number & " " & Err.Description
End Sub

Private Sub cmdDisconnect_Click()
    opcAESubscripts.RemoveAll
    Set opcAESubscript = Nothing
    Set opcAESubscripts = Nothing
    opcAEServer.Disconnect
    Set opcAEServer = Nothing
End Sub
0
TrackMax
Asked:
TrackMax
1 Solution
 
kcarrimCommented:
0
 
TrackMaxAuthor Commented:
Hi,

I have got this information already, however it does not contain any examples of the usage of the OPC AE control. It gave up looking for it, so I'll close this topic.

Best regards,

Pieter
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now