Using filters for tags
This section describes filters and filter syntax, and provides filter examples for tags.
About filters for tags
When getting tags, you can filter them by tag identifier and tag name. Filters are strings that can be specified in RPC calls. A filter is a group of conditions and logical operators that places constraints on the returned data.
For example, when you get tags by using the GetTags
method of TagProvider
service, and you want to get information about tags with certain identifiers, then you can use the following filter to do so:
filter: { tag_id = 1001, 1002, 1003 } |
For examples of using filters for tags, see subsection "Making tag requests with filters" below.
Tag filter fields
Tag filters support basic conditions for following fields:
Field names (tag requests)
Field name |
Value type |
Description |
Condition example |
---|---|---|---|
|
Integral |
Tag identifiers |
|
|
String |
Tag names |
|
Using lists and ranges
You can specify several tag identifiers, tag names, or tag descriptions using a list syntax:
value_1, value_2, ..., value_N, ...
The following are examples of list syntax:
tag_id = 1001, 1002, 1003 tag_name = Valve.State, Valve.Pressure |
For tag identifiers, you can also specify ranges using a range syntax:
value_1-value_N
The following are examples of range syntax:
tag_id = 1001-1100 |
You can also combine lists and ranges for tag identifiers, for example:
tag_id = 1001-1100, 2000-2050 |
Combining conditions
You can combine conditions using logical operators and parentheses:
filter: { (tag_id = 1001, 1002, 1003) || (tag_name = Valve.State, Valve.Pressure) } |
Making tag requests with filters
Following TagNotifier
service method uses filters:
GetTags
You can specify a filter in the
TagsRequest
message.
In the following example, a stub requests tags with specified identifiers.
tagStub = tag_provider_service_pb2_grpc.TagProviderStub(channel)
#rpc GetTags(TagsRequest) returns(stream Tag);
request = tag_provider_service_pb2.TagsRequest(filter = "filter:{tag_id = 1000, 1001, 1002 }") response = tagStub.GetTags(request) for tag in response: print("\n\n") print("Tag:", tag.id, "| Name:", tag.briefInfo.name, "| Changed at:", datetime.datetime.utcfromtimestamp(tag.timestamp.seconds).strftime('%Y-%m-%d %H:%M:%S')) |