示例:创建以设备为数据源的模拟量标签
本示例用于创建以设备为数据源的模拟量标签,并配置以下设备数据源的特定标签属性:
SourceType
、Address
和 SourceDataType
。创建标签时可能出错,例如标签已存在或节点不存在时。程序中的第一个语句用于配置错误处理程序。
Sub CreateDeviceTag() On Error GoTo ErrHandler Dim userTag As Tag Set userTag = TagDB.CreateTag("Test\AnalogDevice", AnalogTag) userTag.Description = "This is a test analog device tag" userTag.SourceType = tagSourceTypeDevice userTag.Address = "S:23" userTag.SourceDataType = tagSourceDataTypeDefault userTag.WriteConfiguration 'Release resources. Set userTag = Nothing ErrHandler: If Err Then MsgBox Error 'Release resources. Set userTag = Nothing Exit Sub End If End Sub
提供反馈