2019年10月15日

Thingworx中跑马灯和自动换页效果的实现

我们知道,在传统SCADA中,跑马灯和自动换页都是常用的功能。
跑马灯可以显示长的消息,还可以起到醒目的效果。
自动换页可以轮流显示不同区域的画面,也可以在正常和异常画面之间进行切换。
但是在Thingworx中并没有对应的widget,但是我们可以通过变通的方式实现,下面讲讲具体方法。

1. 跑马灯
从8.4版本开始,Thingworx Mashup支持keyframes效果,如以下Custom CSS代码:
-----------------------------------------------
@keyframes marquee {
0% { left: 0; }
100% { left: -100%; }
}

#root_label-3 {
    animation: marquee 5s linear infinite;
    background-color: #eee;
    color: red;
}

#root_valuedisplay-4 {
    animation: marquee 10s linear infinite;
    background-color: #eee;
    color: red;
}
-----------------------------------------------
上述代码表示Label-3及Valuedisplay-4 widget的跑马灯效果,包括时间、颜色等设置。
需要说明的是,时间长度指的是所有字符显示的长度。
Label及Valuedisplay均支持背景色定义。
Label的前景色定义无效,而Valuedisplay的前景色定义有效。

2. 自动换页
Tabs widget支持在不同Tab上显示不同的内容,我们可以利用此特性实现自动换页。
SelectedTabValue和SelectedTabName这两个属性都可以用来操作Tab的选择。
我们可以编写一个计数器(自加1及重置),并配合Auto Refresh widget来得到TabValue。
简要的步骤为:
1) 编写计数器Service。
2) 用Auto Refresh触发计数器。
3) 把计数器的值绑定给SelectedTabValue。
此外,针对正常/异常画面切换,我们可以通过编写Service或Expression的方法来给SelectedTabValue赋值。

2019年10月12日

使用Thingworx监控Kepware OPC和PLC连接状态

PTC Thingworx是当前流行的IoT平台,可以很方便地建立和Kepware OPC Server的通信,在绑定Tag后,也很容易对PLC进行读写。
Manufacturing Apps工具包自带的Controls Advisor,能够监控OPC的实时状态,但遗憾的是,不能监控Device(如PLC)级别的状态。
但是我们可以利用Thingworx平台已有的功能,通过自建Thing和Mashup进行监控,下面进行简单的说明。

1. 监控Kepware OPC Server:
1) 在Controls Advisor中,新建Gateway Server。
2) Thingworx将自动创建同名的Industrial Thing,template = PTC.Factory.KepServerThingTemplate。
3) Thingworx也将自动创建Industrial Connection,文件名后缀增加-GW, template = IndustrialGateway。
4) 我们可以利用这两个Thing的isConnected属性来监控Kepware。

2. 监控设备Device(PLC):
1) 在Controls Advisor,点击"Discover Devices",完成以后,Thingworx将为每个设备自动创建一个Thing,
  名称 = Gateway名称 + "_" + Channel名称 + "." + Device名称,
  template = PTC.Factory.DeviceThingTemplate,
  IndustrialThing属性 = Thingworx自动创建的Industrial Connection,
  OPCDAThingName属性 = Controls Advisor中创建的Gateway Server
  (IndustrialThing只能绑定用户创建的Tag, OPCDAThingName能够绑定系统Tag)
2) Enabled属性表示设备已启用,ErrorState属性表示设备出错,
  Enabled = device._System._Enabled
  ErrorState = device._System._Error