smartbus.netclient package

Submodules

smartbus.netclient.client module

smartbus 网络通信客户端的Python接口类客户端类型

author:刘雪彦
date:2013-6-8
class smartbus.netclient.client.Client(localClientId, localClientType, masterHost, masterPort, slaverHost=None, slaverPort=65535, authorUsr=None, authorPwd=None, extInfo=None, encoding='utf-8')

基类:builtins.object

SmartBus Network 客户端类

这个类封装了 SmartBus Network 客户端的一系列方法与事件

addr_expr
authorPwd

密码

authorUsr

登录名

connect()

连接到服务器

Exc:如果连接失败,则抛出 ConnectError 异常
dispose()

释放客户端

encoding

收/发字符串时使用的编码。默认为 utils.default_encoding。

extInfo

连接附加信息

classmethod finalize()

释放库

classmethod getUnitId()
classmethod initialize(unitid, onglobalconnect=None, libraryfile='libbusnetcli.so', logging_option=(True, 10, 40))

初始化

调用其他方法前,必须首先初始化库

:param unitid:单元ID。在所连接到的SmartBus服务器上,每个客户端进程的单元ID都必须是全局唯一的。 :param onglobalconnect:全局连接事件回调函数 :param libraryfile:库文件。如果不指定该参数,则加载时,会自动搜索库文件,其搜索的目录次序为:系统目录、../cdll/${system}/${machine}、 运行目录、当前目录、本文件目录。见 _c_smartbus_netcli_interface.lib_filename :param logging_option:

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()
localClientId

客户端ID

localClientType

客户端类型

masterHost

SmartBus 服务主机名

masterPort

SmartBus 服务端口

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.netlient.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。None或者空表示不指明特定流程
  • title (str) – 通知的标示
  • mode (int) – 调用模式。目前无意义,一律使用0
  • expires (int, float) – 消息有效期。单位秒
  • param (str) – 消息数据
返回:

> 0 invoke_id,调用ID。< 0 表示错误。

返回类型:

int

slaverHost

SmartBus 从服务主机名

slaverPort

SmartBus 从服务端口

unitid

客户端的单元ID

Module contents

smartbus 网络通信客户端的Python接口类

date:2013-2-3
author:lxy@hesong.net