Would it be possible to have an expression to change a string to an integer?
I could really need the atoi in Mappview
Hi Stefaan,
mappView does have the ability to do simple mathematical operations, but I don’t think it can do something as complex as an atoi conversion natively. However, you can use the function brsatoi within a PLC program instead if you transmit the value via OpcUa back to a program. Then, you could display the value in mappView as a string but store it in the backend as an int or vice-versa.
Another possibility is snippets. Snippets allow you to insert a variable value into a string of text. For example:
This is not exactly an atoi conversion since you don’t have access to the new string, but it can be displayed on the HMI as text.
Do you have a particular use case for this conversion? It seems much simpler to just use a mappView widget that matches the datatype you want to use. Perhaps if you explain more we can help you find a better solution.
Hi Marcus,
I’m trying to put all my code concerning the visualization in mappView.
I work with a lot of dropboxes and I need the value and not the index of the selection.
The reason is that the dataprovider changes and the position of the value changes.
This value I use work with listbindings or compound widgets.
For the time being I work with this work around:
So I have the a Numeric value, but this is a lot of code.
Luckily I only have to go to 40 for the moment.
But I do this on different locations, there for I was looking for an expression.
I was also thinking about this Expression as mathematical solution:
But I can’t use the BOOL to to the calculation.
BOOL_TO_INT(stringValue = "0")*0 + BOOL_TO_INT(stringValue = "1")*1 + BOOL_TO_INT(stringValue = "2")*2 +…
I hope this explains my thoughts a little.
Thanks for sharing! I do understand more about what you’re looking to accomplish.
I commend your efforts to try to do everything within mappView, but I honestly think you’ll have a much easier time if you make a helper program within Automation Studio to handle some of the more complicated parts of your visualization. Every project I’ve worked on has had a “VisCtrl” or similarly named task. This really helps because while mappView has a lot of functionality, it’s not meant to do nearly as much as backend program code and therefore doesn’t have as much functionality as you’ll get with an ST or C program.
For instance, take the workaround you shared. It’s great that you found a workaround, but I’m sure that writing in each individual case took some time, and it breaks as soon as you have more than 40 elements in your dropdown. However you can replicate this exact functionality much more robustly in a backend program with just one line of code using the brsatoi function.
If you’re worried about resources, your task will probably be quite simple and will therefore not take much time to run. You can also put it in a lower priority cyclic task class that runs every 500ms or more depending on what else is running in that task.
When I followed the course about MappView I was told to do as much as possible in Mappview
“In mapp View, the content and layout of the HMI application are completely separate from the machine logic”
I also want to this because of the multiclient/MultiUser. It looks easier to run everything on each users browser. Otherwise I have to run a backend program for different users.
I already did this for custom dropdownmenu’s, but it’s also a lot of work.
Concerning the time to write the workaround code, you can do a lot with with cope/paste and replace all, but you have to be aware to use parts in the name to modify, that are easy to select.