opc icon indicating copy to clipboard operation
opc copied to clipboard

Subscribe example

Open axlev opened this issue 4 years ago • 3 comments

Hello, I have successfully browsed server for tags, and read their content. Great software and guidelines provided - thanks for that.

I am required to subscribe to be notified when a group of items was changed. Can you please refer me to a relevant example ? I am reading the OPC specification, but in go-ole package only reference I was able to find is calling a method and accessing a property. How to get an event ? Thanks for your support! Alex

axlev avatar Apr 07 '20 10:04 axlev

@alexlev2004 Thanks. A while ago, I looked quickly into the subscription model as well and made the same observations as you did: the bottleneck seems to be go-ole.

You can, however, emulate the subscription functionality pretty easily in golang by implementing an observer design pattern. Please look at the flow package that I wrote for exactly these use cases (it implements an observer at its core). You could create a simple work flow and use the "on change" filter of the flow package, for example. Hope this helps.

konimarti avatar Apr 07 '20 11:04 konimarti

Thanks for prompt answer.

@alexlev2004 Thanks. A while ago, I looked quickly into the subscription model as well and made the same observations as you did: the bottleneck seems to be go-ole.

You can, however, emulate the subscription functionality pretty easily in golang by implementing an observer design pattern. Please look at the flow package that I wrote for exactly these use cases (it implements an observer at its core). You could create a simple work flow and use the "on change" filter of the flow package, for example. Hope this helps.

Thanks for ptompt answer. The reason for subscribe model is to reduce OPC DA server networking and CPU. As far as I understood your suggestion emulates subscribe model on client side. How would it possible to achieve - enhancing go-ole or can you see any additional options? Thanks again Alex

axlev avatar Apr 07 '20 12:04 axlev

Yes. Enhancing go-ole would be the place to start. And correct, the proposed solution emulates the subscriber on the client side which is admittedly a less elegant solution. However, in our use cases with thousands of tags and reading frequency in seconds, we don't really see a bottleneck in the network or CPU usage.

konimarti avatar Apr 08 '20 09:04 konimarti