Skip to main content

Gurux serial media is used to commmunication with serial port connections.

Project description

See An Gurux for an overview.

Join the Gurux Community or follow @Gurux for 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 out Gurux.

We are updating documentation on Gurux web page.

If you have problems you can ask your questions in Gurux Forum.

Note! Minimum requirements for Gurux project is Python 3.6. This is because projects are depending on Flag and IntFlag.

You can get source codes from http://www.github.com/gurux or intall package:

pip install gurux-common
pip install gurux-serial

Simple example

Before use you must set following settings:

  • PortName
  • BaudRate
  • DataBits
  • Parity
  • StopBits

It is also good to add listener to listen following events.

  • onError
  • onReceived
  • onMediaStateChange
  • onTrace
  • onPropertyChanged

and if in server mode following events might be important.

  • onClientConnected
  • onClientDisconnected
#Change name of the COM port to correct one.
cl = new GXSerial("COM1")
cl.baudRate = BAUD_RATE_9600
cl.dataBits = 8
cl.parity = Parity.None
cl.stopBits = StopBits.ONE
cl.open()

Data is send with send command:

cl.send("Hello World!")

In default mode received data is coming as asynchronously from OnReceived event. Event listener is added like this:

  1. Ads class that you want to use to listen media events and derive class from IGXMediaListener.
class GXNetListener(IGXMediaListener):
    """Media listener."""

    def onError(sender, ex):
        """
        Represents the method that will handle the error event of a Gurux component.

        sender : The source of the event.
        ex : An Exception object that contains the event data.
        """

    def onReceived(sender, e):
        """
        Media component sends received data through this method.

        sender : The source of the event.
        e : Event arguments.
        """

    def onMediaStateChange(sender, e):
        """
        Media component sends notification, when its state changes.

        sender : The source of the event.    
        e : Event arguments.
        """


    def onTrace(sender, e):
        """
        Called when the Media is sending or receiving data.

        sender : The source of the event.    
        e : Trace message.
        """

    def onPropertyChanged(sender, e):
        """
        Represents the method that will handle the System.ComponentModel.INotifyPropertyChanged.PropertyChanged
        event raised when a property is changed on a component.
    	sender : The source of the event.
    	e : A System.ComponentModel.PropertyChangedEventArgs that contains the event data.
        """    

Listener is registered calling addListener method.

cl.addListener(self)

Data can be also send as syncronous if needed.

with cl.getSynchronous():
    reply = ""
    p = ReceiveParameters()
    #End of Packet.
    p.eop = 0x10 
    #How long reply is waited.   
    p.waitTime = 1000
    cl.send("Hello World!")
    if not cl.receive(p):    
        raise Exception("Failed to receive response..")    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gurux_serial-1.0.4.tar.gz (16.7 kB view hashes)

Uploaded Source

Built Distribution

gurux_serial-1.0.4-py3-none-any.whl (28.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page