Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Can SubscribeItem() be used in a web app?

More
02 Nov 2012 16:16 #1077 by support
Hello.
I can try to reproduce and have a look at what precisely is behind the exception your are getting, but.....
It make little sense to try to subscribe - and stay subscribed - as part of page request processing. Subscriptions are long-living entities, while in ASP.NET the page object only exists while the request is being processed. It may even be the reason (I have not verified) for the error: the page may be gone already, when the ItemChangedevent notification arrives.
We have specifically designed the component so that when you do repeated Reads, it will make an OPC subscription internally, so the performance of repeated Reads should not be much worse from Subscribe. So that's one way to do it - just call a Read whenever you need a value. If you truly want to subscribe - and that automatically means for extended periods of time - you need to do it at the global scope of the Web app. If you are unsure, let's discuss your needs and I will come up with hints or example code.
Best regards,
Zbynek Zahradnik

Please Log in or Create an account to join the conversation.

More
02 Nov 2012 16:09 #1075 by tlaford
I created a simple web app that has an EasyDAClient and a TextBox. By copying from the QuickStart example my code is:
Protected Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
textBox1.Text = EasyDAClient1.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Single").ToString()
End Sub

And everything works perfectly. But, if I change my to:
Protected Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
EasyDAClient1.SubscribeItem("", "OPCLabs.KitServer.2", "Demo.Single", 10000)
End Sub

Protected Sub EasyDAClient1_ItemChanged(ByVal sender As Object, ByVal e As EasyDAItemChangedEventArgs) Handles EasyDAClient1.ItemChanged
If e.Exception IsNot Nothing Then
textBox1.Text = "EXCEPTION: " & e.Exception.ToString()
Else
textBox1.Text = e.Vtq.ToString()
End If
End Sub

I end up getting a Null Reference Exception at
at System.Web.HttpApplication.ThreadContext.Enter(Boolean setImpersonationContext)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
at System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state)
at System.Web.AspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state)
at System.Web.AspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state)
at OpcLabs.EasyOpcRaw.DataAccess.RawEasyDAClient.RaiseItemChangedEvent(RawEasyDAItemChangedEventArgs itemChangedEventArgs)
at OpcLabs.EasyOpcRaw.DataAccess.RawEasyDAClient.RaiseEvent(CEasyEvent* Event)
at OpcLabs.EasyOpcRaw.DataAccess.CDAInnerPump.DeliverEvent(CDAInnerPump* , CEasyEvent* Event)
at CEasyAbstractPump.ProcessEventList(CEasyAbstractPump* , CList* EventList)
at CEasyAbstractPump.ExecuteEvents(CEasyAbstractPump* )
at OpcLabs.EasyOpcRaw.DataAccess.RawEasyDAClient.EventsProcess()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Is there something special I need to do when configuring this event handler in my web application?

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.052 seconds