- Posts: 39
- Thank you received: 2
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.
JScript version of OPC-UA Write and specify data type example
- Kyle.Oshima@caltrol.com
-
Topic Author
- Offline
- Platinum Member
-
Please Log in or Create an account to join the conversation.
- Kyle.Oshima@caltrol.com
-
Topic Author
- Offline
- Platinum Member
-
- Posts: 39
- Thank you received: 2
Please Log in or Create an account to join the conversation.
Some tricks are needed to construct and deconstruct COM arrays in JScript. Below is the code of the VBScript example you referred, converted to JScript. That should help.
BTW, noticing that you came back after some time, have you purchased a commercial license already? {just interested).
// This example shows how to write a value into a single node, specifying a type code explicitly.
//
// 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.
//
// TypeCode is easy to use, but it does not cover all possible types. It is also possible to specify the .NET Type, using
// a different overload of the WriteValue method.
//
// Find all latest examples here: opclabs.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html .
// OPC client and subscriber examples in VBScript on GitHub: github.com/OPCLabs/Examples-QuickOPC-VBScript .
// Missing some example? Ask us for it on our Online Forums, www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
var typeCode_Int32 = 9
var endpointDescriptor =
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
//'" opcua.demo-this.com:51211/UA/SampleServer ";
//'" opcua.demo-this.com:51212/UA/SampleServer/ ";
// Instantiate the client object
var Client = new ActiveXObject("OpcLabs.EasyOpc.UA.EasyUAClient");
// Prepare the arguments
var WriteValueArguments1 = new ActiveXObject("OpcLabs.EasyOpc.UA.OperationModel.UAWriteValueArguments");
WriteValueArguments1.EndpointDescriptor.UrlString = endpointDescriptor
WriteValueArguments1.NodeDescriptor.NodeId.ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10221"
WriteValueArguments1.Value = 12345
WriteValueArguments1.ValueTypeCode = typeCode_Int32
var dictionary = new ActiveXObject("Scripting.Dictionary");
dictionary.Add(0, WriteValueArguments1);
var items = dictionary.Items();
// Modify value of a node
var results = Client.WriteMultipleValues(items);
var jsArray = results.toArray();
var WriteResult = jsArray[0]
if (WriteResult.Succeeded)
WScript.Echo("Success");
else {
WScript.Echo("*** Failure: " + WriteResult.Exception.GetBaseException().Message);
}
Please Log in or Create an account to join the conversation.
- Kyle.Oshima@caltrol.com
-
Topic Author
- Offline
- Platinum Member
-
- Posts: 39
- Thank you received: 2
try {
var Client = new ActiveXObject( "OpcLabs.EasyOpc.UA.EasyUAClient" );
var WriteValueArguments1 = new ActiveXObject( "OpcLabs.EasyOpc.UA.OperationModel.UAWriteValueArguments" );
WriteValueArguments1.EndpointDescriptor.UrlString = "opc.tcp://ILDDEV-PROPLUS:9409/DvOpcUaServer";
WriteValueArguments1.NodeDescriptor.NodeId.ExpandedText = "ns=2;s=0:EM1/PARAM1.CV";
WriteValueArguments1.Value = 123.456;
WriteValueArguments1.ValueTypeCode = 13;
var arguments = [];
arguments.push(WriteValueArguments1);
var results = Client.WriteMultipleValues(arguments);
Response.Write( results[0].Succeeded );
}
catch ( error ) {
Response.Write( error.name + " : " + error.message );
}
Please Log in or Create an account to join the conversation.
Please post your code here.
Best regards
Please Log in or Create an account to join the conversation.
- Kyle.Oshima@caltrol.com
-
Topic Author
- Offline
- Platinum Member
-
- Posts: 39
- Thank you received: 2
Unable to cast COM object of type 'System.__ComObject' to class type 'System.Object[]'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
Please advise.
Please Log in or Create an account to join the conversation.