List binding

<< 点击显示目录 >>

主页  mappView帮助助手 > mapp View帮助信息 > 工程 > 变量和数据 > Binding >

List binding

如果需要从一个值的列表中获得一个值,那么就使用列表绑定。

通过列表绑定,定义了一个值的列表和一个选择器。

选择器的值定义了列表中哪个元素将被选中。

列表中的元素的值定义了哪个值被绑定。

选择是通过元素的索引进行的。

如果选择器被设置为一个在列表中没有定义索引的值,那么选择器被重置为最近的有效索引。

如果不喜欢这种行为,那么  必须定义一个 默认的元素

选择的变量可以用一个 值绑定,也可以 用一个 节点绑定

数据的转发取决于所选择的绑定类型。

 

类型为 "opcUa "的列表的例子

<Binding mode="oneWay">
  <Source xsi:type="listElement" >
 <Selector xsi:type="session" refId="::SYSTEM:clientInfo.slotId" attribute="value"  />
 <be:List xsi:type="be:opcUa" attribute="value" >
   <bt:Element index="0" refId="::AsGlobalPV:ClientInfo[0].isLoggedIn" />
   <bt:Element index="1" refId="::AsGlobalPV:ClientInfo[1].isLoggedIn" />
   <bt:Element index="2" refId="::AsGlobalPV:ClientInfo[2].isLoggedIn" />
   <bt:Element index="3" refId="::AsGlobalPV:ClientInfo[3].isLoggedIn" />
   <bt:Element index="4" refId="::AsGlobalPV:ClientInfo[4].isLoggedIn" />
 </be:List>
  </Source>
  <Target xsi:type="brease" contentRefId="myContent" widgetRefId="LogoutButton1" attribute="visible" />
</Binding>

"Session "类型列表的例子

<Binding mode="oneWay">
  <Source xsi:type="listElement" >
 <Selector xsi:type="session" refId="selectorVar" attribute="value"  />
 <be:List xsi:type="be:session" attribute="value" >
   <bt:Element index="0" refId="var1" />
   <bt:Element index="1" refId="var2" />
   <bt:Element index="2" refId="var3" />
 </be:List>
  </Source>
  <Target xsi:type="brease" contentRefId="myContent" widgetRefId="LogoutButton1" attribute="visible" />
</Binding>

"brease "类型列表的例子

<Binding mode="oneWay">
  <Source xsi:type="listElement" >
 <Selector xsi:type="session" refId="selectorVar" attribute="value"  />
 <be:List xsi:type="be:brease" contentRefId="contentId1" >
   <bt:Element index="0" widgetRefId="numericInput1" attribute="value" />
   <bt:Element index="1" widgetRefId="numericInput2" attribute="value" />
   <bt:Element index="2" widgetRefId="numericInput3" attribute="value" />
 </be:List>
  </Source>
  <Target xsi:type="opcUa" refId="::Prg1:Var1" attribute="value" />
</Binding>

列表中的元素不一定来自数组,它们也可以是具有相同类型的不同变量(例如opcUa)。

 

重要的是。列表只允许作为源,不允许作为目标!

在XML中,这意味着<Target xsi:type="listElement">是不允许的!

支持opcUa、brease和session类型的列表。

 

 

对于一个列表,XML元素、列表的类型和列表中的元素都在它们自己的XML命名空间中。由于这个原因,名称空间必须在XML中指定。

 

For the list: xmlns:be="http://www.br-automation.com/iat2015/bindingListEmbedded/engineering/v2"

XML element: be:List

Types: be:opcUa, be:brease, be:session

 

For the elements: xmlns:bt="http://www.br-automation.com/iat2015/bindingListTypes/engineering/v2"

XML element: bt:Element

 

使用案例

从一个数组中动态地选择一个OPC UA变量

默认元素

如果选择器被设置为一个在列表中没有定义索引的值,那么默认元素被选择(与 "switch-case-default "控制结构相当)。使用默认元素是可选的。默认元素必须被定义在列表的最后,在其他元素之后。

默认元素的定义方式与其他元素相同,但没有索引。

<Binding mode="oneWay">
  <Source xsi:type="listElement" >
    <Selector xsi:type="brease" widgetRefId="Selector1" contentRefId="Content1" attribute="selectedIndex"  />
    <be:List xsi:type="be:opcUa" attribute="value" >
      <bt:Element index="0" refId="::Program1:Temperatures[0]" />
      <bt:Element index="1" refId="::Program1:Temperatures[1]" />
      <bt:Element index="2" refId="::Program1:Temperatures[2]" />
      <bt:Default refId="::Program1:Temperatures[0]" />
    </be:List>
  </Source>
  <Target xsi:type="brease" widgetRefId="NumericOutput1" contentRefId="Content1" attribute="value" />
</Binding>

可重复使用的列表

可以在 .bindingList 文件中创建和命名价值 列表。然后可以通过选择列表的名称在绑定中使用这些列表。

列表的定义方式与上面所示相同。

<List xsi:type="opcUa" id="LoggedInList" attribute="value">
  <bt:Element index="0" refId="::AsGlobalPV:ClientInfo[0].isLoggedIn" />
  <bt:Element index="1" refId="::AsGlobalPV:ClientInfo[1].isLoggedIn" />
  <bt:Element index="2" refId="::AsGlobalPV:ClientInfo[2].isLoggedIn" />
  <bt:Element index="3" refId="::AsGlobalPV:ClientInfo[3].isLoggedIn" />
  <bt:Element index="4" refId="::AsGlobalPV:ClientInfo[4].isLoggedIn" />
</List>

对于一个外包列表,只有XML标签 元素 位于一个单独的XML命名空间中。出于这个原因,必须只指定这个标签的命名空间。

在一个绑定中使用列表绑定

<Binding mode="oneWay">
  <Source xsi:type="listElement">
    <Selector xsi:type="session" refId="::SYSTEM:clientInfo.slotId" attribute="value" />
    <List refId="LoggedInList" />
  </Source>
  <Target xsi:type="brease" contentRefId="myContent" widgetRefId="LogoutButton1" attribute="visible" />
</Binding>

这使我们有可能不止一次地使用一个值列表。