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.
- Forum
- Discussions
- QuickOPC-UA in .NET
- Reading, Writing, Subscriptions
- WriteValue works where WriteMultiple does not
WriteValue works where WriteMultiple does not
FYI, the "Write" methods are all implemented on top of "WriteMultiple", and the "WriteValue" methods are all implemented on top of "WriteMultipleValues" methods. So, if e.g. "WriteMultiple" works, and "Write" does not, the difference must be somehow related to the arguments being passed in.
In OPC-UA, the spec is more strict about the type of value that goes to the Write service of the OPC-UA server, compared to OPC Data Access. As you can see (and the doc describes), it can get problematic at times. Basically, you either have to properly specify the type with each value written (or have the value already in the precise type), OR we (on the client side) will allow you to omit the type, at the cost of performance.
Please Log in or Create an account to join the conversation.
As I was reading the Concepts document, I discovered that, if a TypeCode is not supplied, WriteMultiple will actually do a read of the item to determine the type. I was doing this with my code and the setting the TypeCode to the return item type.
It seems to be working fine at the moment.
Please Log in or Create an account to join the conversation.
I apologize for not giving the exception earlier. It gives a BadTypeMismatch ({*** Failure -2139881472 (0x80740000): OPC-UA service result - An error specific to OPC-UA service occurred.}) which is even more strange since I get the type from it before trying to write.
When using the WriteValue, where I don't specify the type, it will write.
I am using TOP Server 5.9.170.0 - I checked the release notes for anything particular to that driver, but I didn't see anything about a bug with
Thank you again.
Please Log in or Create an account to join the conversation.
can you please give following more detail:
- What is the version of the TOP Server (the full, precise version number).
- Do you get any error, and if so, what error precisely, when you say that it does not work? Note that you need to check the output of the WriteMultiple one by one, it does not throw exceptions for this.
Please Log in or Create an account to join the conversation.
I have been using WriteMultiple to write to different PLCs and it works for all except one special case, a SLC 500 and an integer tag. I have included my code that works for all of the other scenarios.
Here is my WriteMultiple function and how I call it….
Calling routine:
DimsServerName As String
DimsTagRead(0) As String
DimsTagWrite(0) As String
DimoWriteValues(0) As Object
DimoTypeCode(0) As TypeCode
DimbResult As Boolean= False
bResult = OPC_UA_WriteMultipleItems(“192.168.2.115:49380”, “SLC500.SLC500.N7:0”, "nsu=TOP Server;ns=2;s=", “123”, oTypeCode)
End of calling routine
FunctionOPC_UA_WriteMultipleItems(ByValsServerName As String, _
ByValTags() As String, _
ByValsServerType As String, _
ByValoValues() As Object, _
ByValoTypeCode() As TypeCode) As Boolean
DimReadValues() As ValueResult= Nothing
'Read tags to get varibale types
OPC_UA_ReadMultipleItems(sServerName, Tags, sServerType, ReadValues)
DimI As Integer
DimeasyUAClient1 = New EasyUAClient()
'create an array to store the results of the write instruction
DimResults() AsOpcLabs.BaseLib.OperationResult 'OpcLabs.EasyOpc.UA.UAWriteResult
DimArgs(UBound(Tags)) As UAWriteArguments
Try
'iterate through the array and add tags and values to Argument object
ForI = LBound(Tags) ToUBound(Tags)
oTypeCode(I) = System.Type.GetTypeCode(ReadValues(I).Value.GetType())
Args(I) = NewOpcLabs.EasyOpc.UA.UAWriteArguments("opc.tcp://"& sServerName, _
sServerType & Tags(I), _
NewOpcLabs.EasyOpc.UA.UAAttributeData(oValues(I)), oTypeCode(I))
Next
IfIsNothing(Args) = False Then
'Write the items
Results = easyUAClient1.WriteMultiple(Args)
End If
Catchex As Exception
'display an exception to screen
MessageBox.Show(ex.Message)
Finally
ForI = LBound(Tags) ToUBound(Tags)
IfResults(I).Succeeded = False Then
OPC_UA_WriteMultipleItems = False 'Bad Write
Exit For
Else
OPC_UA_WriteMultipleItems = True 'Good Write
End If
Next
'Kill objects
easyUAClient1.Dispose()
IfIsNothing(easyUAClient1) = False TheneasyUAClient1 = Nothing
IfIsNothing(Results) = False ThenResults = Nothing
IfIsNothing(Args) = False ThenArgs = Nothing
End Try
End Function
If I switch to WriteValue and try to write to the int tag in the SLC 500, it will work.
I am using TOP Server, Allen-Bradley Ethernet driver, and OPC.Net UA 5.3. I have also had success using a different OPC server and WriteMultiple.
More observations I have:
When using an SLC 500, I cannot write to PLC address unless the Tag NAME is defined in TOP Server. The Tag NAME must match the PLC address. For example: SLC500.SLC500.N7:0
Defining tag name N7:0 and address N7:0 reads and writes properly to N7:0
Defining tag name SSN7:0 and address N7:0 reads properly from N7:0 but cannot write to N7:0
Removing from TOP Server tag name N7:0 and address N7:0 reads properly from N7:0 but cannot write to N7:0
Other tags, such as Strings (ST28:0) or Booleans (B3/0) seem to work OK either way.
Any ideas if this would be related to something weird in the server driver or if it something weird with WriteMultiple.
Please Log in or Create an account to join the conversation.
- Forum
- Discussions
- QuickOPC-UA in .NET
- Reading, Writing, Subscriptions
- WriteValue works where WriteMultiple does not