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.

Correct way of handling easyUAClient.MonitoredItemChanged

More
26 Oct 2016 07:49 #4507 by support
I am glad it has improved. And yes, made a note on improving the examples in this respect.

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

More
26 Oct 2016 07:47 #4506 by andis59
Just a follow up.

I have implemented the Queue for the Write and updated the program on the customers machines and almost all errors disappeared!

You should add an example that shows how to use Write within a Subscription event handler!

Thank you very much for all you help!

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

More
20 Oct 2016 17:17 #4493 by andis59
OK, I got the answer, that on the same EasyAUClient, you will not receive a new MonitoredItemChanged event until you finished handling the previous one.

I have also checked with our PLC guy and he doesn't care in which order the values are set.

So I'm going with QueueUserWorkItem

Thanks!

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

More
20 Oct 2016 11:24 #4488 by support
There are MANY ways how to hand over a piece of work from one thread to another. QueueUserWorkItem is one of them, it is suitable in some cases, but not all. If it's not good for you, look for something better. You can use e.g. the ConcurrentQueue class ( msdn.microsoft.com/en-us/library/dd267265(v=vs.110).aspx ).

On the same EasyAUClient, you will not receive a new MonitoredItemChanged event until you finished handling the previous one.

But be aware that with QueueUserWorkItem , even with knowing the above statement, on itself won't guarantee the same order of execution. You would have to wait for completion of the work inside the event handler, in order to get a guaranteed order. That's why maybe an approach like with ConcurrentQueue might be better.

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

More
20 Oct 2016 11:10 #4486 by andis59
Hello again,

I have a follow up question.

I'm guessing that the event MonitoredItemChanged can be triggered multiple times without the event hander OPCClient_MonitoredItemChanged has finished its work?

That may be a problem since the QueueUserWorkItem doesn't guarantee in which order the tasks will perform.

For each change the PLC writes, and is noticed by the subscription, I will write the same value back to the PLC.

I'm not sure how the PLC will handle if the response are not in the same order as the what it has written. I will off cause check with the PLC guy...

But my question is: Will I get a new MonitoredItemChanged event before the OPCClient_MonitoredItemChanged function has finished?

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

More
19 Oct 2016 14:41 - 19 Oct 2016 14:41 #4485 by andis59
Yes, I'm guessing that way the have two clients.

OK, I will just have one client and use it both in subscription and in the QueueUserWorkItem callback function.

Thanks!
Last edit: 19 Oct 2016 14:41 by andis59.

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

More
19 Oct 2016 14:07 #4484 by support
If the use of two EasyUAClient objects was meant to address the same issue (calling OPC operation from inside an event handler/callback), then it is not a (full) solution (in addition, with Isolated=true, it causes multiple connections be created).

So I'd suggest to first implement the ThreadPool.QueueUserWorkItem .

Best regards

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

More
19 Oct 2016 13:11 #4483 by andis59
In the current code (which BTW I haven't done) the programmer has used two different EasyUAClient for subscription and for writing

easyUAClient = new EasyUAClient { Isolated = true };
EasyUAClient.MonitoredItemChanged += OPCClient_MonitoredItemChanged;
easyUAClientWrite = new EasyUAClient { Isolated = true };

Is this needed or can I use the same client for the subscription and for the write in the queue?

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

More
19 Oct 2016 12:54 #4482 by support
Yes.

Note that you have not described your issues therefore it' possible that they have other cause. But calling EasyXXClient methods form inside the event/callback handler should be avoided anyway, that's right.

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

More
19 Oct 2016 12:50 - 19 Oct 2016 12:50 #4481 by andis59
Just so that I have understood it correctly.
It's the only Write part that should be put in the queue, not the saving of the value to a property?
Last edit: 19 Oct 2016 12:50 by andis59.

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

Moderators: support
Time to create page: 0.214 seconds