FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
08-19-2022 01:41 PM
Hy all,
i like to set a virtual item (EventID) by local script depending by a item manipulated by and iq-button-rocker( ArrayPos). Like this small logic. The iq-button rocker is not able to use ui-actions? How can i map in every situation the PLCEventID from a Array to the virtual Item EventID depending the arrayPos? How can i run the local script every time?
If ArrayPos == 0
EventID = PLCEventID_0
If ArrayPos == 1
EventID = PLCEventID_1
Solved! Go to Solution.
08-19-2022 01:58 PM
I don't quite understand your question but I'll try to answer what I understood:
1. The IQ Rocker Button widget does not support UI Actions
That's true, because it has been created to change a specific item value - as a click on one of the buttons already increases or decreases an associated item automatically.
2. PLC Array
WebIQ does not support OPC-UA arrays at the moment for reading or writing. If you are referring to an array structure item.
3. EventID = PLCEventID_0
Something like this?
if (virtual Item attached to Rocker Button == 0) {
setItemValue($eventId, $plcEventId0);
}
where $eventId is an item name and $plcEventId0 is the value of an item
?
08-22-2022 08:10 AM - last edited on 08-23-2022 01:37 PM by HmiGuide
Hi please help, i am note fine with the syntax from javascript. Can someone check what is wrong with my code. I like to copy the value from MsgArray0.EventID or MsgArray1.EventID to Dialog.EventID depending the rocket button value Dialog.ArrayIndex.
(function () {
var MODULE_NAME = "SelectDialogArray",
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 */
/**
* 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
if (Dialog.ArrayIndex == 0) {
setitemValue(Dialog.EventID,MSGArray0.EventID);
}
if (Dialog.ArrayIndex == 1) {
setitemValue(Dialog.EventID,MSGArray1.EventID);
}
/* 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");
})();
08-22-2022 08:31 AM
My code was written in pseudocode for trying to understand what you are trying to achieve. There is no method "setItemValue" in WebIQ!
I can only help you if you answer my question in such a way that I understand exactly what you are trying to achieve, specifically:
08-22-2022 08:53 AM
Hi all,
the explanation
a IQ-Label should show with the Dialog.EventID a text localizated in english or german. Dialog.EventID is only a number to get the right text in different languages.
08-22-2022 09:32 AM - last edited on 08-24-2022 10:34 AM by HmiGuide
Thanks for the clarification. This code is untested (because I don't have your items), but it should work:
(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 = "SelectDialogArray",
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", "Dialog.ArrayIndex", "MSGArray0.EventID", "MSGArray1.EventID"], function(err, result) {
if (!err) {
if (result["Dialog.ArrayIndex"] == 0) {
im.writeDirect({"Dialog.EventID": result["MSGArray0.EventID"]}, 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.EventID": result["MSGArray1.EventID"]}, function(err, result) {
if (err) {
console.error("Error occurred writing item: "+err);
showMessageOnCompleted(false);
} else showMessageOnCompleted();
});
}
} 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");
})();
08-22-2022 09:33 AM
Regarding the localization: WebIQ already includes a complete localization solution where you define a text and can translate it. You then use the single placeholder everywhere in the HMI and depending on the localization in the HMI set it would show the correct text.
You should not use items to change any localizations form one language to the other as that's not required.
08-22-2022 10:19 AM
Hi,
thank you the code is nearly running i like.
What is the best way to change the dialog.EvendID value by click the button. So ich have to create a UI-Actions for the button-rocker? Our can i handle by click event the iq-button-rocker, so the script run if the value change?
08-22-2022 01:18 PM
Well, I would just utilize the function of the Rocker Button widget and assign the item "Dialog.EventID" to the widget.
08-23-2022 09:45 AM - last edited on 08-24-2022 10:35 AM by HmiGuide
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");
})();
08-23-2022 11:41 AM
The easiest way to find out the reason is to add two IQ Input widgets to your HMI and setting the items to Dialog.ArrayIndex and MSGArray0.MSGName (or any other one used).
Then you can see if your input and output items have the correct values. Also have a look at the browser console (F12) if any corresponding error is shown.
Your main function code can by the way be simplified into this:
module.run = function (self) {
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) {
const idx = result["Dialog.ArrayIndex"];
if (idx >= 0 && idx <= 4) {
im.writeDirect({"Dialog.MSGName": result["MSGArray" + idx + ".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");
})();