smartbus.ipcclient package¶
Submodules¶
smartbus.ipcclient.client module¶
smartbus 进程间通信客户端的Python接口类客户端类型
author: | 刘雪彦 |
---|---|
date: | 2013-6-8 |
- class smartbus.ipcclient.client.Client(username=None, password=None, extInfo=None, encoding='utf-8')¶
基类:builtins.object
SmartBus IPC 客户端类
这个类封装了 SmartBus IPC 客户端的一系列方法与事件
- addr_expr¶
- clientid¶
- clienttype¶
- connect(username=None, password=None)¶
连接服务器
参数: - username (str) – 连接用户名
- password (str) – 连接密码
- info (str) – 自定义连接信息
Exc: 如果连接失败,则抛出 ConnectError 异常
- classmethod finalize()¶
释放库
- get_addr_expr()¶
- get_clientid()¶
- get_clienttype()¶
- get_unitid()¶
- classmethod initialize(clientid, clienttype, onglobalconnect=None, libraryfile='libbusipccli.so', logging_option=(True, 10, 40))¶
初始化
这是一个类方法。调用其他方法前,必须首先使用这个方法初始化库。
参数: - clientid – 客户端ID。在同一个节点中,ID必须唯一。不得小于等于16
- clienttype – 客户端类型。
- onglobalconnect –
- libraryfile –
- ..note:: 其搜索的目录次序为:
- 系统目录、../cdll/${system}/${machine}、 运行目录、当前目录、本文件目录
- classmethod instance(username=None, password=None, extInfo=None)¶
返回该类型的实例
注解
由于一个进程只能有一个实例,所以可用该方法返回目前的实例。
- invokeFlow(server, process, project, flow, parameters=, []isNeedReturn=True, timeout=30)¶
调用流程
参数: - server (int) – IPSC流程服务所在节点
- process (int) – IPSC进程索引值,同时也是该IPSC进程的 smartbus client-id
- project (str) – 流程项目名称
- flow (str) – 流程名称
- parameters (简单数据或者由简单数据组合成的int, float, str, bool , dict,或者它们的再组合数据类型。) – 流程传入参数
- isNeedReturn (bool) – 是否需要流程返回值
- timeout (int or float) – 等待流程返回超时值,单位为秒。
返回: 当需要等待流程返回值时,该返回值是 onInvokeFlowRespond() “流程返回事件”中对应的ID.
返回类型: int
- classmethod isInitialized()¶
判断是否初始化
返回: 是否已经初始化 返回类型: bool
- library¶
- onConnectFail(unitId, errno)¶
连接失败事件
参数: - unitId (int) – 单元ID
- errno (int) – 错误编码
- onConnectSuccess(unitId)¶
连接成功事件
参数: unitId (int) – 单元ID
- onDisconnect()¶
连接中断事件
- onInvokeFlowAcknowledge(packInfo, project, invokeId, ack, msg)¶
收到流程执行回执事件
在调用流程之后,通过该回调函数类型获知流程调用是否成功
参数: - packInfo (smartbus.PackInfo) – 数据包信息
- project (str) – 流程项目ID
- invokeId (int) – 调用ID
- ack (int) – 流程调用是否成功。1表示成功,其它请参靠考误码
- msg (str) – 调用失败时的信息描述
- onInvokeFlowError(packInfo, project, invokeId, errno)¶
流程调用错误事件
参数: - packInfo (smartbus.PackInfo) – 数据包信息
- project (str) – 流程项目ID
- invokeId (int) – 调用ID
- errno (int) – 错误码
- onInvokeFlowRespond(packInfo, project, invokeId, result)¶
收到流程返回数据事件
通过类类型的回调函数,获取被调用流程的“子项目结束”节点的返回值列表
参数: - packInfo (smartbus.PackInfo) – 数据包信息
- project (str) – 流程项目ID
- invokeId (int) – 调用ID
- result (int) – 返回的数据。JSON数组格式
- onInvokeFlowTimeout(packInfo, project, invokeId)¶
流程返回超时事件
参数: - packInfo (smartbus.PackInfo) – 数据包信息
- project (str) – 流程项目ID
- invokeId (int) – 调用ID
- onReceiveText(packInfo, txt)¶
收到文本事件
参数: - packInfo (smartbus.PackInfo) – 数据包信息
- txt (str) – 收到的文本
- ping(dstUnitId, dstClientId, dstClientType, data, encoding=None)¶
发送PING命令
参数: - dstUnitId (int) – 目标的smartbus单元ID
- dstClientId (int) – 目标的smartbus客户端ID
- dstClientType (int) – 目标的smartbus客户端类型
- data (str) – 要发送的数据
- encoding (str) – 数据的编码。 默认值为None,表示使用 smartbus.ipcclient.client.Client.encoding
- send(cmd, cmdType, dstUnitId, dstClientId, dstClientType, data, encoding=None)¶
发送数据
参数: - cmd – 命令
- cmdType – 命令类型
- dstUnitId – 目标节点ID
- dstClientId – 目标客户端ID
- dstClientType – 目标客户端类型
- data – 待发送数据,可以是文本或者字节数组
- encoding – 文本的编码。默认为该对象的 encoding 属性
- sendNotify(server, process, project, title, mode, expires, param)¶
发送通知消息
参数: - server (int) – 目标IPSC服务器smartbus单元ID
- process (int) – IPSC进程ID,同时也是该IPSC进程的 smartbus client-id
- project (str) – 流程项目ID
- title (str) – 通知的标示
- mode (int) – 调用模式。目前无意义,一律使用0
- expires (int, float) – 消息有效期。单位秒
- param (str) – 消息数据
返回: > 0 invoke_id,调用ID。< 0 表示错误。
返回类型: int
- unitid¶