I need to communicate with a PLC using OPCUA. So I found two libraries for Excel on the Siemens site.
OPC_UA_ClientLibrary.dll
OPC_UA_ExcelCLient.dll
They come with working Excel VBA examples.
The first one works, but has limitations; there is no method to read a "struct", that's a PLC node that holds multiple values. I can read/write values to a PLC tho, and also subscribe to valuesupdates (this creates an event when the PLC updates a node)
The second one seems to be an addon on the second one, and the Excel VBA example file also has possibilities to read a "struct" (and also OPC UA methods). When I create an object I can
Set g_OpcUA = New Opc_Ua_ExcelClient.OpcUaClient
or
Set g_OpcUA = New OpcUaClient
But when I register that DLL I can't use the "readvalues" method on the OPCUAobject.
Excel example:
My Access version
Btw, first you need to connect the g_OpcUA object to the OPCUA server, this works without issues. But as soon as I add the code for reading a value, I'm getting this error on the .ReadValues method when compiling:
Maybe it's a bit too simple a thought, but I was assuming that a library that works for MS Excel is compatible with MS Access? Does anybody know a way to fix this? What does this exactly mean: the function is restricted for use in the library (but it's available in Excel) or the variable types are not compatible with MS Access VBA?
I could use the other library, but than I can't read structs. Everything else works though.
OPC_UA_ClientLibrary.dll
OPC_UA_ExcelCLient.dll
They come with working Excel VBA examples.
The first one works, but has limitations; there is no method to read a "struct", that's a PLC node that holds multiple values. I can read/write values to a PLC tho, and also subscribe to valuesupdates (this creates an event when the PLC updates a node)
The second one seems to be an addon on the second one, and the Excel VBA example file also has possibilities to read a "struct" (and also OPC UA methods). When I create an object I can
Set g_OpcUA = New Opc_Ua_ExcelClient.OpcUaClient
or
Set g_OpcUA = New OpcUaClient
But when I register that DLL I can't use the "readvalues" method on the OPCUAobject.
Excel example:
Code:
Private Sub CommandButtonRead_Click()
'NodeId of Item
Dim strNodeId(0) As String
strNodeId(0) = Range("NODEID_READ").Value
Dim strValues() As String
'read value
On Error Resume Next
strValues = Sheets(3).m_OpcUaClient.ReadValues(strNodeId)
'show value
Range("VAL_READ").Value = strValues(0)
End Sub
My Access version
Code:
Private Sub cmdRead_Click()
Dim strNodeId(0) As String
strNodeId(0) = Me.NodeStart
Dim strValues() As String
'read value
On Error Resume Next
strValues = g_OpcUA.ReadValues(strNodeId)
debug.print strValues(0)
End Sub
Btw, first you need to connect the g_OpcUA object to the OPCUA server, this works without issues. But as soon as I add the code for reading a value, I'm getting this error on the .ReadValues method when compiling:
Function marked as restricted or uses a Automation type not supported in Visual Basic
Maybe it's a bit too simple a thought, but I was assuming that a library that works for MS Excel is compatible with MS Access? Does anybody know a way to fix this? What does this exactly mean: the function is restricted for use in the library (but it's available in Excel) or the variable types are not compatible with MS Access VBA?
I could use the other library, but than I can't read structs. Everything else works though.