Welcome to hesong-ipsc-busnetcli’s documentation!¶
version: | 3.2 |
---|---|
buid at: | 2018 年 08 月 07 日 |
hesong¶
hesong package¶
Subpackages¶
hesong.ipsc package¶
Subpackages¶
smartbus 的Python封装
包括 net 与 ipc 客户端的Python类型封装
date: | 2013-7-14 |
---|---|
author: | 刘雪彦 |
-
class
hesong.ipsc.busnetcli.
Client
(client_id, client_type, master_ip, master_port, slave_ip='', slave_port=None, user='', password='', info='')¶ 基类:
hesong.ipsc.busnetcli.utils.LoggerMixin
NET 客户端
注解
使用
create()
建立实例,不要直接使用构造函数!警告
实例一旦建立,无法释放!
参数: -
activate
()¶ 激活客户端
将建立连接。连接一旦建立,就可以接受/发送数据,
注意
该函数立即返回,无论连接成功与否。 如该函数没有直接返回失败,客户端会自动尝试连接 smartbus 服务器,并在连接断开/失败时自动尝试重连
-
classmethod
create
(*args, **kwargs)¶ 建立实例
参数见构造函数
-
classmethod
find
(client_id, default=None)¶ 查找并返回实例
参数: - client_id – 要查找的实例的
client_id
- default – 如果找不到,返回这个值
返回: 找到的实例
返回类型: - client_id – 要查找的实例的
-
classmethod
initialize
(unit_id, global_connect_callback=None, lib_path='')¶ 初始化
参数: 警告
unit_id >= 16 ,且全局唯一,不得重复
全局节点客户端连接、断开事件,当smartbus上某个节点发生连接或者断开时触发。 其函数形如:
-
global_connect_callback(
-
unit_id, client_id, client_type, access_unit_id, status_code, info)
参数:
-
-
launch_flow
(server_unit_id, process_index, project_id, flow_id, mode, timeout, params)¶ 调用流程
参数: - server_unit_id (int) – 目标 IPSC 服务器 smartbus 单元ID
- process_index (int) – IPSC 进程 ID ,同时也是该 IPSC 进程的 smartbus Client ID
- project_id (str) – 流程项目ID
- flow_id (str) – 流程ID
- mode (int) – 调用模式:0 有流程返回、1 无流程返回
- timeout (float) – 有流程返回时的等待超时值(秒)
- params (list) – 流程输入参数里表。简单数据类型JSON数组。 子流程开始节点的传人参数自动变换为list类型数据。 对应的字符串内容最大长度不超过32K字节。
返回: invoke_id,调用ID,用于流程结果返回匹配用途。
返回类型:
-
notify
(server_unit_id, process_index, project_id, title, mode, expires, txt)¶ 发送通知消息
参数: 返回: 调用任务的ID。
返回类型: Except: API返回错误
-
on_connect
()¶ 连接成功
-
on_connect_fail
(error_code)¶ 连接失败
-
on_disconnect
()¶ 连接断开
-
on_flow_ack
(head, project_id, invoke_id, status_code, msg)¶ 流程启动确认
参数:
-
on_flow_error
(head, project_id, invoke_id, error_code)¶ 流程执行错误
参数:
-
on_flow_resp
(head, project_id, invoke_id, params)¶ 调用流程结果返回
参数:
-
on_flow_timeout
(head, project_id, invoke_id)¶ 流程执行超时
参数:
-
ping
(dst_unit_id, dst_client_id, dst_client_type, data=None)¶ 发送PING命令
参数:
-
classmethod
release
()¶ 释放 Library
-
send_data
(cmd, cmd_type, dst_unit_id, dst_client_id, dst_client_type, data)¶ 发送数据
参数:
-
面向对象样式的 NET 客户端 API 的 Python 封装
-
class
hesong.ipsc.busnetcli.client.
Client
(client_id, client_type, master_ip, master_port, slave_ip='', slave_port=None, user='', password='', info='')¶ 基类:
hesong.ipsc.busnetcli.utils.LoggerMixin
NET 客户端
注解
使用
create()
建立实例,不要直接使用构造函数!警告
实例一旦建立,无法释放!
参数: -
activate
()¶ 激活客户端
将建立连接。连接一旦建立,就可以接受/发送数据,
注意
该函数立即返回,无论连接成功与否。 如该函数没有直接返回失败,客户端会自动尝试连接 smartbus 服务器,并在连接断开/失败时自动尝试重连
-
classmethod
create
(*args, **kwargs)¶ 建立实例
参数见构造函数
-
classmethod
find
(client_id, default=None)¶ 查找并返回实例
参数: - client_id – 要查找的实例的
client_id
- default – 如果找不到,返回这个值
返回: 找到的实例
返回类型: - client_id – 要查找的实例的
-
classmethod
initialize
(unit_id, global_connect_callback=None, lib_path='')¶ 初始化
参数: 警告
unit_id >= 16 ,且全局唯一,不得重复
全局节点客户端连接、断开事件,当smartbus上某个节点发生连接或者断开时触发。 其函数形如:
-
global_connect_callback(
-
unit_id, client_id, client_type, access_unit_id, status_code, info)
参数:
-
-
launch_flow
(server_unit_id, process_index, project_id, flow_id, mode, timeout, params)¶ 调用流程
参数: - server_unit_id (int) – 目标 IPSC 服务器 smartbus 单元ID
- process_index (int) – IPSC 进程 ID ,同时也是该 IPSC 进程的 smartbus Client ID
- project_id (str) – 流程项目ID
- flow_id (str) – 流程ID
- mode (int) – 调用模式:0 有流程返回、1 无流程返回
- timeout (float) – 有流程返回时的等待超时值(秒)
- params (list) – 流程输入参数里表。简单数据类型JSON数组。 子流程开始节点的传人参数自动变换为list类型数据。 对应的字符串内容最大长度不超过32K字节。
返回: invoke_id,调用ID,用于流程结果返回匹配用途。
返回类型:
-
notify
(server_unit_id, process_index, project_id, title, mode, expires, txt)¶ 发送通知消息
参数: 返回: 调用任务的ID。
返回类型: Except: API返回错误
-
on_connect
()¶ 连接成功
-
on_connect_fail
(error_code)¶ 连接失败
-
on_disconnect
()¶ 连接断开
-
on_flow_ack
(head, project_id, invoke_id, status_code, msg)¶ 流程启动确认
参数:
-
on_flow_error
(head, project_id, invoke_id, error_code)¶ 流程执行错误
参数:
-
on_flow_resp
(head, project_id, invoke_id, params)¶ 调用流程结果返回
参数:
-
on_flow_timeout
(head, project_id, invoke_id)¶ 流程执行超时
参数:
-
ping
(dst_unit_id, dst_client_id, dst_client_type, data=None)¶ 发送PING命令
参数:
-
classmethod
release
()¶ 释放 Library
-
send_data
(cmd, cmd_type, dst_unit_id, dst_client_id, dst_client_type, data)¶ 发送数据
参数:
-
错误信息定义
date: | 2013-6-8 |
---|---|
author: | lxy@hesong.ent |
-
class
hesong.ipsc.busnetcli.head.
Head
(ptr)¶ 基类:
object
Smartbus通信包头信息
每当接收到数据时,所触发的事件中,都包含该类型的参数,记录了一些数据包的相关信息
对应 SMARTBUS_PACKET_HEAD 结构体的
ctypes
数据类型PacketHeader
的再次封装参数: ptr (smartbus._c.mutual.PPacketHeader) – 结构体指针 -
cmd
¶ 命令
一条 SmartBus 数据的命令关键字
-
cmd_type
¶ 命令类型
一条 SmartBus 数据的命令类型
-
data_length
¶ 正文数据长度
-
dst_unit_client_id
¶ 接收者客户端ID
-
dst_unit_client_type
¶ 接收者客户端类型
-
dst_unit_id
¶ 接收者节点ID
-
packet_size
¶ 包长度
-
src_unit_client_id
¶ 发送者客户端ID
-
src_unit_client_type
¶ 发送者客户端类型
-
src_unit_id
¶ 发送者节点ID
-
ts
¶
-
Some helper functions
-
hesong.ipsc.busnetcli.utils.
b2s_recode
(bs, source_encoding=None, target_encoding=None)¶ -
参数: 返回: 转换结果字符串
返回类型:
-
hesong.ipsc.busnetcli.utils.
s2b_recode
(s, source_encoding=None, target_encoding=None)¶ -
参数: 返回: 转换结果字符串
返回类型:
-
hesong.ipsc.busnetcli.utils.
to_bytes
(s, encoding='utf-8')¶ Convert to bytes string.
参数: - s – String to convert.
- encoding (str) – Encoding codec.
返回: bytes string, it’s bytes or str in Python 2.x, bytes in Python 3.x.
返回类型: - In Python 2, convert s to bytes if it’s unicode.
- In Python 2, return original s if it’s not unicode.
- In Python 2, it equals to
to_str()
. - In Python 3, convert s to bytes if it’s unicode or str.
- In Python 3, return original s if it’s neither unicode nor str.
-
hesong.ipsc.busnetcli.utils.
to_str
(s, encoding='utf-8')¶ Convert to str string.
参数: - s – String to convert.
- encoding (str) – Decoding codec.
返回: str string, it’s bytes in Python 2.x, unicode or str in Python 3.x.
返回类型: - In Python 2, convert s to str if it’s unicode.
- In Python 2, return original s if it’s not unicode.
- In Python 2, it equals to
to_bytes()
. - In Python 3, convert s to str if it’s bytes.
- In Python 3, return original s if it’s not bytes.
- In Python 3, it equals to
to_unicode()
.
-
hesong.ipsc.busnetcli.utils.
to_unicode
(s, encoding='utf-8')¶ Convert to unicode string.
参数: - s – String to convert.
- encoding (str) – Encoding codec.
返回: unicode string, it’s unicode in Python 2.x, str or unicode in Python 3.x.
返回类型: unicode
- In Python 2, convert s to unicode if it’s str or bytes.
- In Python 2, return original s if it’s neither str or bytes.
- In Python 3, convert s to str or unicode if it’s bytes.
- In Python 3, return original s if it’s not bytes.
- In Python 3, it equals to
to_str()
.
-
class
hesong.ipsc.busnetcli.utils.
LoggerMixin
¶ 基类:
object
Mixin Class provide a
logger
property-
classmethod
get_logger
()¶ logger instance.
返回类型: logging.Logger logger name format is ModuleName.ClassName
-
logger
¶ logger instance.
返回类型: logging.Logger logger name format is ModuleName.ClassName
-
classmethod
version