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
TrackMaxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kcarrimCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.