直接从Python调用PJON C++库

pjon-cython的Python项目详细描述


PJON cython

直接从Python 2或Python 3(通过Cython)调用pjon C++库< /p>

pjon(github:PJON)是一个开源、多主、多媒体(单线、双线、无线)通信协议,可用于各种平台(arduino/avr、esp8266、teensy)。

PJON是为数不多的用于微控制器的多主通信协议的开源实现之一。

Pjon cython与Pjon python之比较

^ {STR 1 } $PJON Cython 允许您通过Python通过Cython(Cy+PrpPysPython)使用C++ PJON库 pjon python是python中pjon协议的重新实现

当前状态:

仅支持pjon 11.2和以下策略:-

  • 本地udp
  • globaludp
  • 通过序列
  • 通过serialasyncnew

注意

  • pjon cython版本与pjon版本一致,表明与uc平台的c实现兼容。

python支持

python 2.7、3.4、3.5和3.6都经过了测试,并被认为是受支持的

平台支持

Linux和MacOSX被认为是受支持的。不支持Windows(抱歉!).

从PIP安装

当前版本是11.2.0

pip install pjon-cython

测试

$(which python) setup.py nosetests --with-doctest --doctest-extension=md

GlobalUDP示例

>>>importpjon_cythonasPJON>>>classGlobalUDP(PJON.GlobalUDP):...# you can overload __init__ if you want...def__init__(self,device_id):...PJON.GlobalUDP.__init__(self,device_id)...self.packets_received=0...defreceive(self,data,length,packet_info):...print("Recv ({}): {}".format(length,data))...print(packet_info)...self.packets_received+=1...self.reply(b'P')>>>g=GlobalUDP(44)>>>idx=g.send(123,b'HELO')>>># calling loop calls the PJON bus.update() and bus.receive()>>># and the return is the results of those functions ->>>packets_to_send,receive_status=g.loop()>>># packets_to_send is the Number of packets in the PJON buffer>>>packets_to_send1>>>#PJON constants are available too>>>receive_status==PJON.PJON_FAILTrue>>># When you're done with your PJON interface, you can cleanup the connection by deleting it>>>delg

通过序列示例

>>>importpjon_cythonasPJON>>>#ThroughSerial Example>>># Make sure you set self.bus.set_synchronous_acknowledge(false) on the other side>>>>>>classThroughSerial(PJON.ThroughSerial):......defreceive(self,data,length,packet_info):...ifdata.startswith(b'H'):...print("Recv ({}): {} - REPLYING".format(length,data))...self.reply(b'BONZA')...else:...print("Recv ({}): {}".format(length,data))...print('')...>>># Put your actual serial device in here...>>>ts=ThroughSerial(44,b"/dev/null",115200)>>># Send returns the packet's index in the packet buffer>>>ts.send(100,b'PING 1')0>>>ts.send(100,b'PING 2')1>>># Error handling happens through exceptions such as PJON.PJON_Connection_Lost>>>whileTrue:...packets_to_send,receive_status=ts.loop()Traceback(mostrecentcalllast):...PJON_Connection_Lost

设置可配置属性

>>>importpjon_cythonasPJON>>>classGlobalUDP(PJON.GlobalUDP):...defreceive(self,data,length,packet_info):...print("Recv ({}): {}".format(length,data))>>># GlobalUDP and LocalUDP both support set_port to configure their UDP listening port>>>g=GlobalUDP(99,8821)>>>delg>>>#They return the class object, so you can "chain them">>>pjon=GlobalUDP(100,8821).set_autoregistration(False)>>>pjon# doctest: +ELLIPSIS<__main__.GlobalUDPobjectat0x...>>>>>>># These options affect packet overhead (in bytes)>>>pjon.packet_overhead()6>>>pjon.set_crc_32(True).packet_overhead()9>>>pjon.set_packet_id(True).packet_overhead()11>>>pjon.set_synchronous_acknowledge(True).packet_overhead()11>>>pjon.set_packet_id(False).set_asynchronous_acknowledge(False).packet_overhead()9>>>pjon.set_crc_32(False).include_sender_info(False).packet_overhead()5

pyserial_Asyncio使用基于序列的策略

您可以将文件描述符传递给throughserial和throughserialasync,而不是传递串行端口字符串 允许其他库轮询串行端口的方法。

例如,请参见reticul8 项目。

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

推荐PyPI第三方库


热门话题
爪哇太阳报。安全验证器。ValidatorException:PKIX路径生成失败   java理解为什么在onDispatchTouchEvent()返回True后仍调用onClick()   java如何在资源包中使用JSF标记/如何在资源包中重写URL?   java什么是流控制异常的替代方案?   java使用Spring数据JPA/MongoDB交叉存储,一个查询可以跨越两个数据库吗?   Apache Sling/felix中的java OSGi slf4j日志记录   为什么当我们想要水平/垂直旋转矩阵时,我们要把这个项除以2?   尝试从外部网页接收JSON字符串时出现安卓 Java NullPointerException   java执行异常:从Callable调用方法时   java在jetty上以调试模式运行webapp,使用maven jetty插件在intellij中构建成功(应用程序应在调试模式下启动)   带有内存数据库的linux Java应用程序的构建时间太长   基于java的随机数单元测试算法   java类型javax。摆动JComponent无法解析   Google日历API和UI小部件Java   java tomcat没有突然和任意地响应   java无法使用jsoup在html中获取图像src   我无法让Java接受键盘输入字符串   java如何开始使用Bambol而不让部署永远继续?   java如何使用另一个类的actionPerformed方法删除一个类/组件中的按钮?   java JSON反序列化brakets{}中的一系列对象