Professional OPC
Development Tools

logos

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

More
23 Jul 2025 19:15 #14338 by Kyle.Oshima@caltrol.com
This message contains secure information

Please Log in or Create an account to join the conversation.

More
23 Jul 2025 19:00 #14337 by Kyle.Oshima@caltrol.com
Thanks -- believe now have working JScript converted from VBScript example based on additional code details provided.
The following user(s) said Thank You: support

Please Log in or Create an account to join the conversation.

More
19 Jul 2025 13:04 #14332 by support
Hello.

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.

More
18 Jul 2025 20:00 #14331 by Kyle.Oshima@caltrol.com
re: Please post your code here..., see JScript code below (see attached .zip file containing .js file as well as rudimentary .asp file to run JScript in web browser) -- btw, am running latest OPC Studio 2025.1 version available for download

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 );
}

 
   

 

File Attachment:

File Name: test-quickopc.zip
File Size:1 KB
  • Please Log in or Create an account to join the conversation.

    More
    18 Jul 2025 12:13 #14330 by support
    Hello.

    Please post your code here.

    Best regards

    Please Log in or Create an account to join the conversation.

    More
    18 Jul 2025 02:00 #14329 by Kyle.Oshima@caltrol.com
    Looking for JScript version of  Examples - OPC Unified Architecture - Write and specify data type  available in online documentation -- tried to convert language syntax from available VBScript version, but JScript returns following error:

    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.

    Moderators: supportvaclav.zaloudek
    Time to create page: 0.154 seconds