94 lines
2.5 KiB
Markdown
94 lines
2.5 KiB
Markdown
```markdown
|
||
## OPC-UA
|
||
|
||
#### OPC 读取数值
|
||
|
||
* 方法说明
|
||
|
||
读取 OPC server 中的某个地址位的值。
|
||
|
||
```python
|
||
def read_opc_value(address: str | int) -> any:
|
||
```
|
||
|
||
* 输入参数
|
||
* `address`:str 类型,读取的地址位。
|
||
* 输出参数
|
||
* 读到的值。
|
||
* 异常
|
||
|
||
读取失败会抛出 `RuntimeError` 异常 "read_opc_value error"。
|
||
|
||
* 方法说明
|
||
|
||
```python
|
||
def read_opc_value(namespace_index: int, address: str | int) -> any:
|
||
```
|
||
|
||
* 输入参数
|
||
* `namespace_index`:int 类型,命名空间索引
|
||
* `address`:str 类型,读取的地址位。地址类型 g=550e8400-e29b-41d4-a716-446655440000: g= 表示地址类型是 UUID;i=1008: i= 表示地址类型是 number;b=EAk=: b= 表示地址类型是 Opaque;s=1009: s= 表示地址类型是字符串
|
||
* 输出参数
|
||
* 读到的值。
|
||
* 异常
|
||
|
||
读取失败会抛出 `RuntimeError` 异常 "read_opc_value error"。
|
||
|
||
#### OPC 订阅方式读取数值
|
||
|
||
* 方法说明
|
||
|
||
通过订阅的方式,读取 OPC server 中的某个地址位的值。
|
||
|
||
```python
|
||
def read_opc_value_by_subscription(namespace_index: int, address: str) -> any:
|
||
```
|
||
|
||
* 输入参数
|
||
* `namespace_index`:int 类型,命名空间索引。
|
||
* `address`:str 类型,读取的地址位。地址类型 g=550e8400-e29b-41d4-a716-446655440000: g= 表示地址类型是 UUID;i=1008: i= 表示地址类型是 number;b=EAk=: b= 表示地址类型是 Opaque;s=1009: s= 表示地址类型是字符串
|
||
* 输出参数
|
||
* 读到的值。
|
||
* 异常
|
||
|
||
读取失败会抛出 `RuntimeError` 异常 "read_opc_value error"。
|
||
|
||
#### OPC 写入数值
|
||
|
||
* 方法说明
|
||
|
||
向 OPC server 中的某个地址位写入值。
|
||
|
||
```python
|
||
def write_opc_value(address: str | int, value: any) -> bool:
|
||
```
|
||
|
||
* 输入参数
|
||
* `address`:str 类型,表示写入的地址。
|
||
* `value`:any 类型,写入的值。
|
||
* 输出参数
|
||
|
||
成功返回 `True`,失败返回 `False`。
|
||
* 异常
|
||
|
||
本方法不抛出异常。
|
||
|
||
* 方法说明
|
||
|
||
向 OPC server 中的某个地址位写入值。
|
||
|
||
```python
|
||
def write_opc_value(namespace_index: int, address: str | int, value: any) -> bool:
|
||
```
|
||
|
||
* 输入参数
|
||
* `namespace_index`:int 类型,命名空间索引
|
||
* `address`:str 类型,表示写入的地址。地址类型 g=550e8400-e29b-41d4-a716-446655440000: g= 表示地址类型是 UUID;i=1008: i= 表示地址类型是 number;b=EAk=: b= 表示地址类型是 Opaque;s=1009: s= 表示地址类型是字符串
|
||
* `value`:any 类型,写入的值。
|
||
* 输出参数
|
||
|
||
成功返回 `True`,失败返回 `False`。
|
||
* 异常
|
||
|
||
本方法不抛出异常。
|
||
``` |