Hi all,
i have some problem with datatyp now. If i set EvendID like the example before with Integers is running. Now i would to set MSGName like in the following code i get an empty string. Is the function writedirect not running with strings? The source of the data (MSGArray0.MSGName) is a string from PLC and the target also.
(function () {
/**
* replace module name with a custom name for the local-script.
*
* All local-script should be attached to the "custom.ls" package.
* If more than one script is required for an application, a common root package
* should be created (e.g. "custom.ls.customerName.*").
*/
var MODULE_NAME = "SelectMessageName",
ENABLE_LOGGING = true,
RECORD_LOG = false,
logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME, ENABLE_LOGGING, RECORD_LOG),
fLog = logger.fLog,
log = logger.log,
module = shmi.pkg( MODULE_NAME );
// MODULE CODE - START
/* private variables */
/* private functions */
// Called when the actions are completed, regardless of an error just for demonstrating how to
// perform other actions asynchronously
function showMessageOnCompleted(successful)
{
if (successful) {
alert("Done!");
} else {
alert("There was an error!");
}
}
/**
* Implements local-script run function.
*
* This function will be called each time a local-script will be enabled.
*
* @param {LocalScript} self instance reference of local-script control
*/
module.run = function (self) {
// Place your Code here
const im = shmi.visuals.session.ItemManager;
// Everything in WebIQ happens asynchronously so you always have to use callbacks
// Please keep in mind that your code can only retrieve item values by either subscribing to them or reading them directly
// Please note: if any of the items used are virtual items the corresponding code would have to be changed
im.readDirect(["Dialog.ArrayIndex", "MSGArray0.MSGName", "MSGArray1.MSGName", "MSGArray2.MSGName", "MSGArray3.MSGName", "MSGArray4.MSGName"], function(err, result) {
if (!err) {
if (result["Dialog.ArrayIndex"] == 0) {
im.writeDirect({"Dialog.MSGName": result["MSGArray0.MSGName"]}, function(err, result) {
if (err) {
console.error("Error occurred writing item: "+err);
showMessageOnCompleted(false);
} else showMessageOnCompleted(true);
});
}
else if (result["Dialog.ArrayIndex"] == 1) {
im.writeDirect({"Dialog.MSGName": result["MSGArray1.MSGName"]}, function(err, result) {
if (err) {
console.error("Error occurred writing item: "+err);
showMessageOnCompleted(false);
} else showMessageOnCompleted(true);
});
} else if (result["Dialog.ArrayIndex"] == 2) {
im.writeDirect({"Dialog.MSGName": result["MSGArray2.MSGName"]}, function(err, result) {
if (err) {
console.error("Error occurred writing item: "+err);
showMessageOnCompleted(false);
} else showMessageOnCompleted(true);
});
} else if (result["Dialog.ArrayIndex"] == 3) {
im.writeDirect({"Dialog.MSGName": result["MSGArray3.MSGName"]}, function(err, result) {
if (err) {
console.error("Error occurred writing item: "+err);
showMessageOnCompleted(false);
} else showMessageOnCompleted(true);
});
} else if (result["Dialog.ArrayIndex"] == 4) {
im.writeDirect({"Dialog.MSGName": result["MSGArray4.MSGName"]}, function(err, result) {
if (err) {
console.error("Error occurred writing item: "+err);
showMessageOnCompleted(false);
} else showMessageOnCompleted(true);
});
}
} else {
console.log("Could not read items: ", err, result);
showMessageOnCompleted(false);
}
});
/* called when this local-script is disabled */
self.onDisable = function () {
self.run = false; /* from original .onDisable function of LocalScript control */
};
};
// MODULE CODE - END
fLog("module loaded");
})();
... View more