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.
WriteValue with Delphi
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
// This example shows how to write values into 3 nodes at once, specifying a type code explicitly. It tests for success of
// each write and displays the exception message in case of failure.
//
// Reasons for specifying the type explicitly might be:
// - The data type in the server has subtypes, and the client therefore needs to pick the subtype to be written.
// - The data type that the reports is incorrect.
// - Writing with an explicitly specified type is more efficient.
//
// Alternative ways of specifying the type are using the ValueType or ValueTypeFullName properties.
class procedure WriteMultipleValues.ValueTypeCode;
var
Arguments: OleVariant;
Client: TEasyUAClient;
I: Cardinal;
WriteResult: _UAWriteResult;
WriteValueArguments1, WriteValueArguments2, WriteValueArguments3: _UAWriteValueArguments;
Results: OleVariant;
begin
WriteValueArguments1 := CoUAWriteValueArguments.Create;
WriteValueArguments1.EndpointDescriptor.UrlString := 'http://opcua.demo-this.com:51211/UA/SampleServer';
WriteValueArguments1.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/;i=10221';
WriteValueArguments1.Value := 23456;
WriteValueArguments1.ValueTypeCode := TypeCode_Int32; // here is the type explicitly specified
WriteValueArguments2 := CoUAWriteValueArguments.Create;
WriteValueArguments2.EndpointDescriptor.UrlString := 'http://opcua.demo-this.com:51211/UA/SampleServer';
WriteValueArguments2.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/;i=10226';
WriteValueArguments2.Value := 'This string cannot be converted to Double';
WriteValueArguments2.ValueTypeCode := TypeCode_Double; // here is the type explicitly specified
WriteValueArguments3 := CoUAWriteValueArguments.Create;
WriteValueArguments3.EndpointDescriptor.UrlString := 'http://opcua.demo-this.com:51211/UA/SampleServer';
WriteValueArguments3.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/;s=UnknownNode';
WriteValueArguments3.Value := 'ABC';
WriteValueArguments3.ValueTypeCode := TypeCode_String; // here is the type explicitly specified
Arguments := VarArrayCreate([0, 2], varVariant);
Arguments[0] := WriteValueArguments1;
Arguments[1] := WriteValueArguments2;
Arguments[2] := WriteValueArguments3;
// Instantiate the client object
Client := TEasyUAClient.Create(nil);
// Modify values of nodes
TVarData(Results).VType := varArray or varVariant;
TVarData(Results).VArray := PVarArray(Client.WriteMultipleValues(
PSafeArray(TVarData(Arguments).VArray)));
// Display results
for I := VarArrayLowBound(Results, 1) to VarArrayHighBound(Results, 1) do
begin
WriteResult := IInterface(Results[I]) as _UAWriteResult;
if WriteResult.Succeeded then
WriteLn('Result ', I, ' success')
else
WriteLn('Result ', I, ': ', WriteResult.Exception.GetBaseException.Message);
end;
end;
This example works for set of basic types covered by the TypeCode enumeration. I suppose it will be sufficient for your application. There is also an option to specify other types, using the ValueTypeFullName property. If you end up needing that, let me know.
Best regards
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Looking at it, it does explain the concepts, but is missing some examples, especially for COM where the various overloads of WriteValue are not available. Please wait a little, and I will work on more documentation and some examples, and will let you know.
Also, I would be really grateful if you can report this problem to Siemens anyway, or if you know a way of doing so, let me know and I can try that myself.
Regards
Please Log in or Create an account to join the conversation.
I have just checked and even the inbuilt Siemens GUDs look the same.
How do I specify a type explicitly?
Please Log in or Create an account to join the conversation.
Its ValueRank attribute is 0, which is OneOrMoreDimensions. According to OPC UA (Vesrion 1.03) Part 3, Table 8, OneOrMoreDimensions denotes "The value is an array with one or more dimensions.".
In addition, its ArrayDimensions attribute is totally off (look at the picture you sent).
For the node to be scalar string, its ValueRank would have to be -1 (Scalar).
QuickOPC attempts to convert the value you provided to the data type of the variable. So, it tries to convert the string or decimal you pass to it to an array of something, but that fails, of course.
Either you need to write an array (which would be effectively impossible given the terribly huge number in ArrayDimensions), or the server actually expects a scalar, but is non-compliant and the vendor should fix it.
I understand this is an OPC Server in a Siemens PLC. Please let me know the PLC model and firmware version.
There may be a way around this by specifying a type explicitly in QuickOPC. Let me know if you want to pursue this way - but the non-compliance on the server part is fairly serious in my view, so that should be fixed first, because it can cause problems at other places too.
Best regards
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.