Package: pjon-cython
PJON-cythonCall the PJON C++ library directly from Python 2 or Python 3 (viaCython)PJON (Github:PJON) is an open-source, multi-master, multi-media (one-wire, two-wires, radio) communication protocol available for various platforms (Arduino/AVR, ESP8266, Teensy).PJON is one of very few open-source implementations of multi-master communication protocols for microcontrollers.PJON-cython vs PJON-pythonPJON-cythonallows you to use the C++ PJON library from Python via Cython (C++ wrappers for Python) whilePJON-pythonis a re-implementation of the PJON protocol in PythonCurrent status:Support for PJON 12 and the following strategies :-LocalUDPGlobalUDPThroughSerialThroughSerialAsyncNotePJON-cython versions are aligned with PJON versions to indicate compatibility with C implementation for uC platforms.Python supportPython 2.7, 3.4, 3.5, 3.6 and 3.7 are tested and considered supportedPlatform supportLinux and Mac OS X are considered supported. Windows is not supported (sorry!).Install from pipCurrent version is 12.0.0pipinstallpjon-cythonTesting$(whichpython)setup.pynosetests--with-doctest--doctest-extension=mdGlobalUDP example>>>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>>>delgThrough Serial example>>>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_cython._pjon_cython.PJON_Connection_LostSetting configurable properties>>>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<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()5Use serial based strategies withpyserial_AsyncioInstead of passing a serial port string, you can pass a file descriptor to the ThroughSerial and ThroughSerialAsync
methods which allows other libraries to poll the serial port.For examples, see thereticul8project.