Package: gurux-serial
See AnGuruxfor an overview.Join the Gurux Community or follow@Guruxfor project updates.With gurux.serial component you can send data easily syncronously or asyncronously using serial port connection.Open Source GXNet media component, made by Gurux Ltd, is a part of GXMedias set of media components, which programming interfaces help you implement communication by chosen connection type. Gurux media components also support the following connection types: serial port.For more info check outGurux.We are updating documentation on Gurux web page.If you have problems you can ask your questions in GuruxForum.You can get source codes fromhttp://www.github.com/guruxor intall package:pipinstallgurux-commonpipinstallgurux-serialSimple exampleBefore use you must set following settings:PortNameBaudRateDataBitsParityStopBitsIt is also good to add listener to listen following events.onErroronReceivedonMediaStateChangeonTraceonPropertyChangedThis example sends data to the serial port and waits reply.
Change serial port before use.importtimefromgurux_commonimportReceiveParametersfromgurux_commonimportIGXMediaListenerfromgurux_common.enums.TraceLevelimportTraceLevelfromgurux_serialimportGXSerial#pylint: disable=no-self-argumentclasssampleclient(IGXMediaListener):def__init__(self):#List available serial ports.print("Available ports:")print(str(GXSerial.getPortNames()))#Define End Of Packet char.eop='\r'#TODO: Update correct port and serial port settings.media=GXSerial("SERIAL PORT TO USE")#Start to listen events from the media.media.addListener(self)#Show all traces.media.trace=TraceLevel.VERBOSE#Set EOP for the media.media.eop=eoptry:#Open the connection.media.open()r=ReceiveParameters()r.eop=eop#Minimium amount of bytes to receive.r.count=5#Wait reply for 2 seconds.r.waitTime=2000#############################Send data synchronously.withmedia.getSynchronous():media.send("Hello world!")#Send EOPmedia.send('\r')ret=media.receive(r)ifret:print(str(r.reply.decode("ascii")))else:raiseException("Failed to receive reply from the server.")#############################Send async data.media.send("Notify from the meter!\r")#Wait 1 second to receive reply from the server.time.sleep(1)exceptExceptionasex:print(ex)media.close()media.removeListener(self)defonError(self,sender,ex):"""Represents the method that will handle the error event of a Guruxcomponent.sender :  The source of the event.ex : An Exception object that contains the event data."""print("Error has occured. "+str(ex))defonReceived(self,sender,e):"""Media component sends received data through this method.sender : The source of the event.e : Event arguments."""print("New data is received. "+str(e))defonMediaStateChange(self,sender,e):"""Media component sends notification, when its state changes.sender : The source of the event.e : Event arguments."""print("Media state changed. "+str(e))defonTrace(self,sender,e):"""Called when the Media is sending or receiving data.sender : The source of the event.e : Event arguments."""print("trace:"+str(e))defonPropertyChanged(self,sender,e):"""Event is raised when a property is changed on a component.sender : The source of the event.e : Event arguments."""print("Property{!r}has hanged.".format(str(e)))if__name__=='__main__':sampleclient()