- Posts: 4
- Thank you received: 0
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 or issues. You do not have to own a commercial license in order to use the OPC Labs support. Our team is actively monitoring the forums, and provides replies as soon as possible.
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.
Looping with the RTD function
- glenn@awscontractorsinc.com
-
Topic Author
- Offline
- Senior Member
-
Please Log in or Create an account to join the conversation.
- glenn@awscontractorsinc.com
-
Topic Author
- Offline
- Senior Member
-
- Posts: 4
- Thank you received: 0
Please Log in or Create an account to join the conversation.
Additional information: I have also looked at the unexpected Excel termination. We might be able to fix that. However, I am still not sure that if fixed, you will get the results you expect. Specifically, since the RTD function is based on subscriptions, when any OPC item is first requested, the server may not have the data at that initial moment, And it is OK for the server to send Bad status in the initial notification. The code you currently have (the original one - the one which assigns to .Value) will get that first notification, so it's not guaranteed to be the actual value you are after.
Best regards
Please Log in or Create an account to join the conversation.
thank you for more details.
For what you are doing, I tend to think that using the explicit operation calls (such as do an OPC Read when you need the data) would be more appropriate than the use of the RTD function, which is specialized a) to do subsriptions, not Read-s, and b) provide data to formulas dynamically when they change - and not when you need them. In our QuickOPC product, there are APIs just for that, and it works well.
If you want to use the RTD function nevertheless, what you described only reinforced my opinion that you should set the formulas and not the values. Try replacing the statement that sets the value with this one:
ActiveSheet.Range("D" & Index).Formula = "=RTD(""opclabs.office.excel.connectivityrtdserver"", """", ""opcuaattribute"", ""opc.tcp://192.168.2.201:4840/UADiscovery"", """ & topicstring1 & """, """", """")"
Best regards
Please Log in or Create an account to join the conversation.
- glenn@awscontractorsinc.com
-
Topic Author
- Offline
- Senior Member
-
- Posts: 4
- Thank you received: 0
In previous older applications I would use some software component to read/write the recipe array directly to the PLC. If I can't get RTD to work, my next step is to look at going that route with some OPCUA components. My experience has been these components tend to get flakey or complicated when used in VBA (if they even work at all in an Excel VBA module). Thus this odd workaround using the RTD function.
Suggestions?
Please Log in or Create an account to join the conversation.
I think that there are actually 2 issues in your post:
1. Why the Excel closes or crashes with the code you provided.
2. Is the code you provided actually going to do what you want, if it worked?
At the moment I have doubts about #2, and it makes no sense to go deeper into #1 without having #2 clarified first.
The RTD function is special in that its result can change dynamically. That works in a formula in a cell. If you, however, evaluate that function inside the VBA code, you end up with a static value (number, typically). Your code then assigns this value to the cell. So if the code had worked, in the best case, you would end up with cells filled with static OPC values valid at the time you ran the code.
If your intent was to end up with cells that contain dynamic data, your code should set the *formulas* inside the cells (and the formulas should contain the RTD function), and not the *values* of the cells.
Let me know if I got it wrong or if you need further help.
Best regards
Please Log in or Create an account to join the conversation.
- glenn@awscontractorsinc.com
-
Topic Author
- Offline
- Senior Member
-
- Posts: 4
- Thank you received: 0
Sub RefreshRTD()
For Index = 1 To 1 'Change this loop upper limit to 2 and Excel crashes'
topicstring1 = "nsu=CODESYSSPV3/3S/IecVarAccess ;ns=4;s=|var|Turck/ARM/WinCE TV.Application.GVL.RandomNum[" & Index & "]"
ActiveSheet.Range("D" & Index).Value = Application.WorksheetFunction.RTD("opclabs.office.excel.connectivityrtdserver", "", "opcuaattribute", _
"opc.tcp://192.168.2.201:4840/UADiscovery", topicstring1, "", "", "Value;""""")
Next
End Sub
Please Log in or Create an account to join the conversation.
