Use enumeration in mappView

I was wondering if I can use my enumeration in my PLC variable in the Mappview Module.
I want to create a dynamic label…
If no can I create enumeration and/or in a mappView.
Thanks,

Hi Tommy,

Enumerations are essentially just constants. They allow you to associate constant values to variables, but these variable names aren’t the same as text that can be read on an HMI.

If you want to dynamically change text based on the value of a variable, I recommend using snippets. These are described in the Automation Studio Help. You could bind the value of the enumeration to the snippet so that on both sides (code and HMI) a meaningful name is associated with the value.

1 Like

I found a thread on the forum that talk about this limitation.

I look like the implementation of the snipplet is not perfect since i read the manual and thread and this make my HMI to crash without any error…

Ok i can figure it out what was my issue, but i found that snippets can only be instancied once, soo it’s useless. The text list is still usable in dropdownbox, but this solution still doesn’t work since only index can be use no non linear incrémental can be use.
Like 1,2,3,4, work, but 1,2,164,261, doesn’t work.

Can you share a little bit more about what you’re hoping to do and the errors you’re seeing? It’s not clear from just your messages what’s happening.

I want to show the status of a node on the can bus.
The modules provide 9 state that look like 0,1,2,3,4,5,6,127 and 261
the state can be translate to text infor that look like :"INITIALISATION,RESET_COMM,RESET_APP,PRE_OPERATIONAL,STOPPED,OPERATIONAL,UNKNOW_ERROR,PRE_OPERATIONAL and OPERATIONAL + ModuleOK
I want a text output that translate the state number to the state text.

Hi Tommy,

I have a tip for you, maybe complex to implement with value like 127 and 261…

I’ve same problem but for PLCOpen state of an axis, here is a solution :

  • You use a DropDownBox where you force enable to false
  • Style your DropDownBox to look like TextOutput, think about that you need to edit Disabled style, DropDownBox will be disabled
  • Create the dataprovider you need, I’ve created yours using a python script:
# Construction of json dataprovider
text_to_write: str = "["

for i in range(0, 262):
    text: str = ""
    match i:
        case 0: text = "INITIALISATION"
        case 1: text = "RESET_COMM"
        case 2: text = "RESET_APP"
        case 3: text = "PRE_OPERATIONAL"
        case 4: text = "STOPPED"
        case 5: text = "OPERATIONAL"
        case 6: text = "UNKNOW_ERROR"
        case 127: text = "PRE_OPERATIONAL"
        case 261: text = "OPERATIONAL + Module OK"
    text_to_write += f"{{'value': '{i}', 'text': '{text}' }},"
# Delete last comma to have a valid dataprovider
text_to_write = text_to_write[:-1]

text_to_write += "]"

# Write to a file
with open("test.json", "w") as f:
    f.write(text_to_write)

You can open the content in xml where you created the DropDownBox and copy paste the dataProvider generated

<Widget xsi:type="widgets.brease.DropDownBox" id="DropDownBox1" top="90" left="325" width="320" zIndex="0" dataProvider="[{'value':'0','text':'INITIALISATION'},{'value':'1','text':'RESET_COMM'},{'value':'2','text':'RESET_APP'},{'value':'3','text':'PRE_OPERATIONAL'},{'value':'4','text':'STOPPED'},{'value':'5','text':'OPERATIONAL'},{'value':'6','text':'UNKNOW_ERROR'},{'value':'7','text':''},{'value':'8','text':''},{'value':'9','text':''},{'value':'10','text':''},{'value':'11','text':''},{'value':'12','text':''},{'value':'13','text':''},{'value':'14','text':''},{'value':'15','text':''},{'value':'16','text':''},{'value':'17','text':''},{'value':'18','text':''},{'value':'19','text':''},{'value':'20','text':''},{'value':'21','text':''},{'value':'22','text':''},{'value':'23','text':''},{'value':'24','text':''},{'value':'25','text':''},{'value':'26','text':''},{'value':'27','text':''},{'value':'28','text':''},{'value':'29','text':''},{'value':'30','text':''},{'value':'31','text':''},{'value':'32','text':''},{'value':'33','text':''},{'value':'34','text':''},{'value':'35','text':''},{'value':'36','text':''},{'value':'37','text':''},{'value':'38','text':''},{'value':'39','text':''},{'value':'40','text':''},{'value':'41','text':''},{'value':'42','text':''},{'value':'43','text':''},{'value':'44','text':''},{'value':'45','text':''},{'value':'46','text':''},{'value':'47','text':''},{'value':'48','text':''},{'value':'49','text':''},{'value':'50','text':''},{'value':'51','text':''},{'value':'52','text':''},{'value':'53','text':''},{'value':'54','text':''},{'value':'55','text':''},{'value':'56','text':''},{'value':'57','text':''},{'value':'58','text':''},{'value':'59','text':''},{'value':'60','text':''},{'value':'61','text':''},{'value':'62','text':''},{'value':'63','text':''},{'value':'64','text':''},{'value':'65','text':''},{'value':'66','text':''},{'value':'67','text':''},{'value':'68','text':''},{'value':'69','text':''},{'value':'70','text':''},{'value':'71','text':''},{'value':'72','text':''},{'value':'73','text':''},{'value':'74','text':''},{'value':'75','text':''},{'value':'76','text':''},{'value':'77','text':''},{'value':'78','text':''},{'value':'79','text':''},{'value':'80','text':''},{'value':'81','text':''},{'value':'82','text':''},{'value':'83','text':''},{'value':'84','text':''},{'value':'85','text':''},{'value':'86','text':''},{'value':'87','text':''},{'value':'88','text':''},{'value':'89','text':''},{'value':'90','text':''},{'value':'91','text':''},{'value':'92','text':''},{'value':'93','text':''},{'value':'94','text':''},{'value':'95','text':''},{'value':'96','text':''},{'value':'97','text':''},{'value':'98','text':''},{'value':'99','text':''},{'value':'100','text':''},{'value':'101','text':''},{'value':'102','text':''},{'value':'103','text':''},{'value':'104','text':''},{'value':'105','text':''},{'value':'106','text':''},{'value':'107','text':''},{'value':'108','text':''},{'value':'109','text':''},{'value':'110','text':''},{'value':'111','text':''},{'value':'112','text':''},{'value':'113','text':''},{'value':'114','text':''},{'value':'115','text':''},{'value':'116','text':''},{'value':'117','text':''},{'value':'118','text':''},{'value':'119','text':''},{'value':'120','text':''},{'value':'121','text':''},{'value':'122','text':''},{'value':'123','text':''},{'value':'124','text':''},{'value':'125','text':''},{'value':'126','text':''},{'value':'127','text':'PRE_OPERATIONAL'},{'value':'128','text':''},{'value':'129','text':''},{'value':'130','text':''},{'value':'131','text':''},{'value':'132','text':''},{'value':'133','text':''},{'value':'134','text':''},{'value':'135','text':''},{'value':'136','text':''},{'value':'137','text':''},{'value':'138','text':''},{'value':'139','text':''},{'value':'140','text':''},{'value':'141','text':''},{'value':'142','text':''},{'value':'143','text':''},{'value':'144','text':''},{'value':'145','text':''},{'value':'146','text':''},{'value':'147','text':''},{'value':'148','text':''},{'value':'149','text':''},{'value':'150','text':''},{'value':'151','text':''},{'value':'152','text':''},{'value':'153','text':''},{'value':'154','text':''},{'value':'155','text':''},{'value':'156','text':''},{'value':'157','text':''},{'value':'158','text':''},{'value':'159','text':''},{'value':'160','text':''},{'value':'161','text':''},{'value':'162','text':''},{'value':'163','text':''},{'value':'164','text':''},{'value':'165','text':''},{'value':'166','text':''},{'value':'167','text':''},{'value':'168','text':''},{'value':'169','text':''},{'value':'170','text':''},{'value':'171','text':''},{'value':'172','text':''},{'value':'173','text':''},{'value':'174','text':''},{'value':'175','text':''},{'value':'176','text':''},{'value':'177','text':''},{'value':'178','text':''},{'value':'179','text':''},{'value':'180','text':''},{'value':'181','text':''},{'value':'182','text':''},{'value':'183','text':''},{'value':'184','text':''},{'value':'185','text':''},{'value':'186','text':''},{'value':'187','text':''},{'value':'188','text':''},{'value':'189','text':''},{'value':'190','text':''},{'value':'191','text':''},{'value':'192','text':''},{'value':'193','text':''},{'value':'194','text':''},{'value':'195','text':''},{'value':'196','text':''},{'value':'197','text':''},{'value':'198','text':''},{'value':'199','text':''},{'value':'200','text':''},{'value':'201','text':''},{'value':'202','text':''},{'value':'203','text':''},{'value':'204','text':''},{'value':'205','text':''},{'value':'206','text':''},{'value':'207','text':''},{'value':'208','text':''},{'value':'209','text':''},{'value':'210','text':''},{'value':'211','text':''},{'value':'212','text':''},{'value':'213','text':''},{'value':'214','text':''},{'value':'215','text':''},{'value':'216','text':''},{'value':'217','text':''},{'value':'218','text':''},{'value':'219','text':''},{'value':'220','text':''},{'value':'221','text':''},{'value':'222','text':''},{'value':'223','text':''},{'value':'224','text':''},{'value':'225','text':''},{'value':'226','text':''},{'value':'227','text':''},{'value':'228','text':''},{'value':'229','text':''},{'value':'230','text':''},{'value':'231','text':''},{'value':'232','text':''},{'value':'233','text':''},{'value':'234','text':''},{'value':'235','text':''},{'value':'236','text':''},{'value':'237','text':''},{'value':'238','text':''},{'value':'239','text':''},{'value':'240','text':''},{'value':'241','text':''},{'value':'242','text':''},{'value':'243','text':''},{'value':'244','text':''},{'value':'245','text':''},{'value':'246','text':''},{'value':'247','text':''},{'value':'248','text':''},{'value':'249','text':''},{'value':'250','text':''},{'value':'251','text':''},{'value':'252','text':''},{'value':'253','text':''},{'value':'254','text':''},{'value':'255','text':''},{'value':'256','text':''},{'value':'257','text':''},{'value':'258','text':''},{'value':'259','text':''},{'value':'260','text':''},{'value':'261','text':'OPERATIONAL + Module OK'}]" enable="false" />
  • Last step is to create a binding from your DropDownBox, you bind “selectedIndex” to any integer or enumeration. Please use oneWay (Read Only) binding
<Binding mode="oneWay">
	<Source xsi:type="opcUa" refId="::AsGlobalPV:test_enumeration" attribute="value" />
	<Target xsi:type="brease" contentRefId="content_test" widgetRefId="DropDownBox1" attribute="selectedIndex" />
</Binding>

Hope this help !
Regards,
Florent

1 Like

If I’m understanding correctly, this can be done with a Snippet and a Text Output widget.

First, define your texts in a localizable text file:

Then, create a Snippet:

<SnippetsSet id="snippet_0" xmlns="http://www.br-automation.com/iat2015/snippet/engineering/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Snippets>
        <Snippet id="SnippetNodeStatus" xsi:type="session" type="IndexText" formatItem="IAT/NodeStatus.{1}" />
    </Snippets>
</SnippetsSet>

Finally, bind your snippet to a Text Output widget:

    <Bindings>
        <Binding mode="oneWay">
            <Source xsi:type="opcUa" refId="::Program:NodeStatus" attribute="value" />
            <Target xsi:type="snippet" refId="SnippetNodeStatus" attribute="value" />
        </Binding>
        
        <Binding mode="oneWay"> 
            <Source xsi:type="snippet" refId="SnippetNodeStatus" attribute="value" /> 
            <Target xsi:type="brease" widgetRefId="TextOutput1" contentRefId="ContentMain" attribute="value" />
        </Binding>
    </Bindings>

When I change the value of NodeStatus, the output text changes. It will work for all values that have been defined:

If you choose an undefined value, you’ll get an error:

Another option is to use a Case statement to turn your value into a string, and then bind the TextOutput widget to the string. This might be a little simpler but requires more code to execute.

1 Like

I already test snippet and the link with the IAT variable doesn’t work on my side. Even with know value i got the error -2144327652, like it missing a link with my file.
image

Also the binding of a snippet can only be done once witch is not really help full if i need to instenciated this list multiple time.

Even with know value i got the error -2144327652

This looks like an error with the texts themselves. Did you make sure to include the Localizable Texts file in the TextConfig file that’s in the Configuration View?

Also the binding of a snippet can only be done once witch is not really help full if i need to instenciated this list multiple time.

Binding a value to a snippet changes the value of the snippet. Just like any other variable, a snippet can only hold one value at a time. If you have multiple inputs going to multiple outputs, you’ll just need to make multiple snippets.

Here is my test project. I have two enumeration values mapped to two different Text Outputs in a visualization. I hope this helps you get started. If you don’t like this method, the dropdown method mentioned by @florent.boissadier is also an option.

SnippetsTest.zip (136.7 KB)

1 Like

Thanks @marcusbnr for your example help, it me to find my issue.
I was a link on the fact I was missing TextSystem config.
So I add Texconfig in the “Configuration View” and Projet.language in the “Logical View” and my snippet start working.
Again, thanks you

2 Likes