OPC UA 质量代码 OPC quality codes 简介

本文来源:https://support.softwaretoolbox.com/app/answers/detail/a_id/414/~/opc-da-quality-codes

1. OPC Quality flags OPC质量代码

OPC质量代码表示数据值的质量状态。它与现场总线数据质量规范相似但更简单一些。这种设计使OPC服务器和客户端应用程序都可以轻松确定要实现的功能量。
These flags represent the quality state for a item’s data value. This is intended to be similar to but slightly simpler than the Fieldbus Data Quality Specification (section 4.4.1 in the H1 Final Specifications). This design makes it fairly easy for both servers and client applications to determine how much functionality they want to implement.

2. OPC 质量代码的结构

质量代码由 16 位二进制数组成。其中低 8 位为固定内容,称为标准 OPC 质量位,高 8 位为厂商自定义内容

1. 低 8 位 – OPC 标准质量位:固定意义。质量位、子状态位、限值状态位

  1. OPC质量代码的低8位,划分为3个区域
    1. 质量位域 (Quality, Q):占最高 2 位
    2. 子状态位域 (Substatus, S):占中间 4 位
    3. 限值状态位与(Limit status, L):占最低 2 位
  2. 8 位的排列方式如下:
    The low 8 bits of the Quality flags are currently defined in the form of three bit fields; Quality, Substatus and Limit status. The 8 Quality bits are arranged as follows:
	最高位 --> 最低位
	QQ SSSS LL

2. 高 8 位:厂商自定内容

质量代码的高8位可供厂商自定义。如果使用这些位,则OPC标准质量位 (质量代码低 8 位) 仍必须尽可能准确地设置,以指示客户端对返回的数据做出处理。此外,任何解释供应商特定质量信息的客户端都要确保提供这些信息的服务器使用与客户端相同的“规则”。OPC标准中未指定质量代码自定义内容的协商确定机制,一种可行的方法是调用厂商接口服务器的特定的查询接口。
The high 8 bits of the Quality Word are available for vendor specific use. If these bits are used, the standard OPC Quality bits must still be set as accurately as possible to indicate what assumptions the client can make about the returned data. In addition it is the responsibility of any client interpreting vendor specific quality information to insure that the server providing it uses the same ‘rules’ as the client. The details of such a negotiation are not specified in this standard although a QueryInterface call to the server for a vendor specific interface such as IMyQualityDefinitions is a possible approach.

3. OPC 标准质量位 (低 8 位) 的详细含义解析

  1. 质量位域 (Quality, QQ, 高 2 位) --> 子状态位域 (Substatus, SSSS, 中间 4 位)
    不同质量位域 + 不同子状态位域 = 该点的状态信息
    
  2. 限值状态位 (Limit status, LL, 低 2 位),与质量位、子状态位相互独立,再某些情况下 (如传感器故障) 能提供有用的额外诊断信息。
    The Limit Field is valid regardless of the Quality and Substatus. In some cases such as Sensor Failure it can provide useful diagnostic information.

质量位域 (Quality, QQ, 高 2 位)

十进制二进制值定义描述
000SSSSLL值不可用 (Bad)值不可用 (通信异常),具体原因见子状态位域描述 (Value is not useful for reasons indicated by the Substatus)
101SSSSLL值不确定 (Uncertain)值不确定 (通信状态未知),具体原因见子状态位域描述 (The quality of the value is uncertain for reasons indicated by the Substatus)
210SSSSLL不使用 (N/A)OPC 质量代码不使用此值 (Not used by OPC)
311SSSSLL良好 (Good)值是良好 (通信正常) 的 (The Quality of the value is Good)
  1. 不支持任何质量信息的OPC服务器,质量位域必须返回3(良好 Good)。并始终将“子状态位域”和“限制位域”设置返回0值 (即 8 位输出 = 0x00)
    支持最简单质量信息的OPC服务器只需返回“坏 (Bad)”或“好 (Good)”(质量位域 = 0 或 3),并始终将“子状态位域”和“限制位域”设置返回0值 (即8位输出 = 0x00 或 0xC0)
    A server which supports no quality information must return 3 (Good). It is also acceptable for a server to simply return Bad or Good (0x00 or 0xC0) and to always return 0 for Substatus and limit.

  2. 建议客户端:至少检查所有值的“质量位域”。
    It is recommended that clients minimally check the Quality Bit field of all results (even if they do not check the substatus or limit fields).

  3. 在“质量位域:指示了“BAD”值时,值字段的内容也必须仍然是可读的变量形式,即使它不包含准确的值。这样可简化客户端应用程序中的错误处理。
    例如:客户端在同步读取过程中,不论点位的质量如何,总是调用统一的 VariantClear() 函数进行处理,当数据质量为”Bad“时,此函数也能正常对数据流中包含的值和数据进行交互和解包。
    Even when a ‘BAD’ value is indicated, the contents of the value field must still be a well defined VARIANT even though it does not contain an accurate value. This is to simplify error handling in client applications. For example, clients are always expected to call VariantClear() on the results of a Sychronous Read. Similarly the IAdviseSink needs to be able to interpret and ‘unpack’ the Value and Data included in the Stream even if that data is BAD.

  4. 如果服务器中没有对应点位的值,则应返回一些合理的默认值,例如 NUL 字符串或 0 数值。
    If the server has no known value to return then some reasonable default should be returned such as a NUL string or a 0 numeric value.

子状态位域 (Substatus, SSSS, 中间 4 位)

此位域包含的内容取决于”质量位域“。

1. 不可用状态下的子状态 (QQ = 0b00)

十进制二进制值定义描述
0000000LL未指定 (Non-specific)该值不可用,但不知道具体原因 (The value is bad but no specific reason is known)
1000001LL配置错误 (Configuration Error)服务器配置存在问题。如:项目已从配置中删除 (There is some server specific problem with the configuration. For example the item is question has been deleted from the configuration.)
2000010LL未连接 (Not Connected)输入需要在逻辑上连接到某物,但实际没有连接。这种质量可能时目前没有可用的值,原因可能是数据源可能没有提供该值 (The input is required to be logically connected to something but is not. This quality may reflect that no value is available at this time, for reasons like the value may have not been provided by the data source)
3000011LL设备故障 (Device Failure)检测到设备故障 (A device failure has been detected)
4000100LL传感器故障 (Sensor Failure)检测到传感器故障(“限制位域”可以提供额外的诊断信息) (A sensor failure had been detected (the ’Limits’ field can provide additional diagnostic information in some situations))
5000101LL上一个已知值 (Last Known Value)通信故障。但是,最后一个已知值可用。该值的“新旧程度”可以从“应用程序”中的时间戳确定 (Communications have failed. However, the last known value is available. Note that the ‘age’ of the value may be determined from the TIMESTAMP in the OPCITEMSTATE)
6000110LL通信故障 (Comm Failure)通信故障。且没有最后一个已知值可用 (Communications have failed. There is no last known value is available.)
7000111LL停止服务 (Out of Service)块已关闭扫描或以其他方式锁定 当项目或包含该项目的组的活动状态为“非活动”时,也会使用此质量。 (The block is off scan or otherwise locked This quality is also used when the active state of the item or the group containing the item is InActive.)
8-15不使用 (N/A)未被 OPC 使用 (Not used by OPC)
  1. 不支持"子状态"的 OPC 服务器,子状态位域应返回 0
    Servers which do not support Substatus should return 0.
  2. 如果将“质量”设置为 BAD (0),并将“子状态”设置为 5 (上一个已知值),则可能会返回“旧”值。这种情况是质量为 BAD 时客户端仍能使用返回数据值的唯一情况。
    Note that an ‘old’ value may be returned with the Quality set to BAD (0) and the Substatus set to 5. This is for consistency with the Fieldbus Specification. This is the only case in which a client may assume that a ‘BAD’ value is still usable by the application.

2. 不确定状态下的子状态 (QQ = 0b01)

十进制二进制值定义描述
0010000LL未指定 (Non-specific)该值不可用,但不知道具体原因 (The value is uncertain but no specific reason is known)
1010001LL上次可用值 (Last Usable Value)已经停止更新此点的值。返回的值应被视为“过时”。请注意,这与子状态为 5(最后已知值)的 BAD 值不同。该状态与可检测到的通信错误或“提取”值的操作错误相关联。此错误与某些外部源无法在可接受的时间段内将某些内容“放入”值中有关。该值的“新旧”可以从“OPCITEMTIMESTAMP” 对象中的时间戳中确定。 (The value is uncertain but no specific reason is known)
2-3不使用 (N/A)未被 OPC 使用 (Not used by OPC)
4010100LL传感器不准确 (Sensor Not Accurate)传感器的输出值”固定“为极限量程(此时”限制状态位域“应为 1 或 2),或传感器内部诊断出传感器未校准(此时”限制状态位域“应为 0) (Either the value has ‘pegged’ at one of the sensor limits (in which case the limit field should be set to 1 or 2) or the sensor is otherwise known to be out of calibration via some form of internal diagnostics (in which case the limit field should be 0)
5010101LL超出工程单位 (Engineering Units Exceeded)返回的值超出为此参数定义的限制。请注意,在这种情况下的“限制”指超过设定的值范围,但不一定意味着该值超过了最大量程。 (The returned value is outside the limits defined for this parameter. Note that in this case (per the Fieldbus Specification) the ‘Limits’ field indicates which limit has been exceeded but does NOT necessarily imply that the value cannot move farther out of range)
6010110LL亚健康 (Sub-Normal)该值需要多个源才能生成,并且其良好源数少于所需的数量 (The value is derived from multiple sources and has less than the required number of Good sources.)
7-15不使用 (N/A)未被 OPC 使用 (Not used by OPC)
  1. 不支持"子状态"的 OPC 服务器,子状态位域应返回 0
    Servers which do not support Substatus should return 0.

2. 良好状态下的子状态 (QQ = 0b11)

十进制二进制值定义描述
0110000LL未指定 (Non-specific)值正常,且没有特殊状况 (The value is good. There are no special conditions)
1-5不使用 (N/A)未被 OPC 使用 (Not used by OPC)
6110000LL本地覆盖 (Local Override)该值已被覆盖。通常,这意味着输入已断开连接,并且被手动输入的值强制覆盖 (The value has been Overridden. Typically this is means the input has been disconnected and a manually entered value has been ‘forced’)
7-15不使用 (N/A)未被 OPC 使用 (Not used by OPC)
  1. 不支持"子状态"的 OPC 服务器,子状态位域应返回 0
    Servers which do not support Substatus should return 0.

极限状态位域 (Limit status, LL, 低 2 位)

无论质量和子状态如何,“限制”字段都有效。在某些情况下,例如传感器故障时,它可以提供有用的额外诊断信息。

十进制二进制值定义描述
0QQSSSS00不限 (Not Limited)该值可自由变化 (The value is free to move up or down)
1QQSSSS01低限 (Low Limited)该值已低于设定的下限 (The value is free to move up or downThe value has ‘pegged’ at some lower limit)
2QQSSSS10高限 (High Limited)该值已高于设定的上限 (The value has ‘pegged’ at some high limit)
3QQSSSS11不断 (Constant)该值是常量,不能变化 (The value is a constant and cannot move)
  1. 不支持“限值状态位域”的服务器,此位域应返回 0。
    Servers which do not support Limit should return 0.
以下是使用C#语言和OPC UA协议进行服务器通信的示例代码: ```csharp using Opc.Ua; using Opc.Ua.Client; // 创建一个UA TCP连接 var endpointUrl = "opc.tcp://localhost:62541/Quickstarts/ReferenceServer"; var endpoint = new EndpointDescription(endpointUrl); var config = EndpointConfiguration.Create(); var selectedEndpoint = CoreClientUtils.SelectEndpoint(endpointUrl, false); var endpointConfiguration = EndpointConfiguration.Create(config); var session = Session.Create( endpointConfiguration, new ConfiguredEndpoint(null, selectedEndpoint, endpointConfiguration), false, "", 60000, new UserIdentity(new AnonymousIdentityToken()), null).Result; // 读取一个节点的值 var nodeToRead = new ReadValueId { NodeId = new NodeId("ns=2;s=Machine_1/Status"), AttributeId = Attributes.Value }; var readRequest = new ReadRequest { NodesToRead = new[] { nodeToRead } }; var readResponse = session.Read(null, readRequest).Result; if (readResponse.Results[0].StatusCode == StatusCodes.Good) { var value = readResponse.Results[0].GetValueOrDefault<string>(); Console.WriteLine($"The status of Machine_1 is: {value}"); } // 写一个节点的值 var nodeToWrite = new WriteValue { NodeId = new NodeId("ns=2;s=Machine_1/TargetSpeed"), AttributeId = Attributes.Value, Value = new DataValue(50) }; var writeRequest = new WriteRequest { NodesToWrite = new[] { nodeToWrite } }; var writeResponse = session.Write(null, writeRequest).Result; if (writeResponse.Results[0].StatusCode == StatusCodes.Good) { Console.WriteLine("The target speed of Machine_1 has been set to 50."); } // 关闭连接 session.Close(); ``` 以上代码使用了Opc.Ua.Client库来创建连接、读写节点值,并且使用了异步方法来处理请求和响应。请注意,需要安装Opc.Ua.Core和Opc.Ua.Client NuGet包来使用这个库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值