RCT电力通信协议的实现

rctclient的Python项目详细描述


rctclient-Python实现rctpower股份有限公司的“串行通信协议”

这个Python模块实现了RCT Power GmbH的“串行通信协议”,用于他们的太阳能生产线 逆变器。它还包括一个对象ID的注册表和一个命令行工具。为了发展 包括简单的模拟器。在

本项目与RCT Power GmbH没有任何关联或支持

下面是快速入门指南,项目文档位于Read the Docs。在

安装

使用pip安装和更新:

$ pip install -U rctclient

要安装CLI工具所需的依赖项,请执行以下操作:

^{pr2}$

示例

让我们阅读当前电池的充电状态:

importsocket,select,sysfromrctclient.frameimportReceiveFrame,SendFramefromrctclient.registryimportREGISTRYasRfromrctclient.typesimportCommandfromrctclient.utilsimportdecode_value# open the socket and connect to the remote device:sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)sock.connect(('192.168.0.1',8899))# query information about an object ID (here: battery.soc):object_info=R.get_by_name('battery.soc')# construct a SendFrame that will send a read command for the object ID we want, and send itsend_frame=SendFrame(command=Command.READ,id=object_info.object_id)sock.send(send_frame.data)# loop until we got the entire response frameframe=ReceiveFrame()whileTrue:ready_read,_,_=select.select([sock],[],[],2.0)ifsockinready_read:# receive content of the input bufferbuf=sock.recv(256)# if there is content, let the frame consume itiflen(buf)>0:frame.consume(buf)# if the frame is complete, we're doneifframe.complete():breakelse:# the socket was closed by the device, exitsys.exit(1)# decode the frames payloadvalue=decode_value(object_info.response_data_type,frame.data)# and print the result:print(f'Response value: {value}')

从命令行读取值

模块安装rctclient命令(需要click)。子命令read-values从中读取单个值 并返回其输出。下面是一个调用示例,使用具有详细输出的对象ID:

$ rctclient read-value --verbose --host 192.168.0.1 --id 0x959930BF
#413 0x959930BF battery.soc         SOC (State of charge)              0.29985150694847107

如果没有--verbose,则只打印接收到的值。如下所示,其中 --name参数代替--id

$ rctclient read-value --host 192.168.0.1 --name battery.soc
0.2998138964176178

这使得它适合于只需要一些值的脚本环境。如果添加了--debug 在子命令名称之前,日志级别设置为DEBUG,所有日志消息都发送到stderr,这允许 脚本继续处理stdout上的值,同时允许观察代码的内部工作。在

生成文档

文档是使用Sphinx生成的,并且要求将软件安装到本地环境(例如。 通过virtualenv)。使用存储库的本地克隆,请执行以下操作(如果需要,请先激活virtualenv 期望的):

$ pip install -e .[docs,cli]
$ cd docs
$ make clean html

文档被放入docs/_build/html目录中,只需将浏览器指向index.html文件即可。在

文档在每次提交后也会自动生成,可以在 https://rctclient.readthedocs.io/。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java RFID不完整输出?   java如何构造一个for循环来查找每个数组的第一个索引的总和   java Eclipse AST解析器正在删除我的规则   安卓如何在java中创建“可重写”配置?   java每次我向应用程序添加图像时,它都会崩溃   Java 8流到文件   EntityNotFoundException的java可能原因   java多线程为什么下面的程序表现得如此怪异?   java footprint soap api+mavenjaxb2plugin   java MongoDB锁定,直到找到结果   java重写Jtable选项卡行为转到下一个可编辑单元格   java关于方法和创建另一个方法   java将人脸与图像分离   java复制Spring批处理作业实例   java TextView不会更改为新设置的文本