// Shows how to write into multiple OPC items using a single method call, specifying their requested data types.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html .
// Missing some example? Ask us for it on our Online Forums, https://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 varTypes_I2 = 2;
var varTypes_R4 = 4;
// Instantiate the client object.
var Client = new ActiveXObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
WScript.Echo("Writing multiple item values...");
// Prepare the arguments
var requestedDataType1 = new ActiveXObject("OpcLabs.BaseLib.ComInterop.VarType");
requestedDataType1.NumericalValue = varTypes_I2;
var WriteValueArguments1 = new ActiveXObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
WriteValueArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2";
WriteValueArguments1.ItemDescriptor.ItemId = "Simulation.Register_I2";
WriteValueArguments1.ItemDescriptor.RequestedDataType = requestedDataType1; // the requested data type
WriteValueArguments1.Value = 12345;
var requestedDataType2 = new ActiveXObject("OpcLabs.BaseLib.ComInterop.VarType");
requestedDataType2.NumericalValue = varTypes_R4;
var WriteValueArguments2 = new ActiveXObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
WriteValueArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2";
WriteValueArguments2.ItemDescriptor.ItemId = "Simulation.Register_R4";
WriteValueArguments2.ItemDescriptor.RequestedDataType = requestedDataType2; // the requested data type
WriteValueArguments2.Value = 234.56;
var dictionary = new ActiveXObject("Scripting.Dictionary");
dictionary.Add(0, WriteValueArguments1);
dictionary.Add(1, WriteValueArguments2);
var items = dictionary.Items();
// Perform the write operations.
var results = Client.WriteMultipleItemValues(items);
// Display results.
var jsArray = results.toArray();
for (i = 0; i < jsArray.length; i++) {
var WriteResult = jsArray[i]
if (WriteResult.Succeeded)
WScript.Echo("Result " + i + ": Success");
else
WScript.Echo("Result " + i + " *** Failure: " + WriteResult.Exception.GetBaseException().Message);
}