Skip to main content

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.

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

This example sends data to the serial port and waits reply. Change serial port before use.

import time
from gurux_common import ReceiveParameters
from gurux_common import IGXMediaListener
from gurux_common.enums.TraceLevel import TraceLevel
from gurux_serial import GXSerial

#pylint: disable=no-self-argument
class sampleclient(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 = eop
        try:
            #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.
            with media.getSynchronous():
                media.send("Hello world!")
                #Send EOP
                media.send('\r')
                ret = media.receive(r)
                if ret:
                    print(str(r.reply.decode("ascii")))
                else:
                    raise Exception("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)
        except Exception as ex:
            print(ex)
        media.close()
        media.removeListener(self)

    def onError(self, 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.
        """
        print("Error has occured. " + str(ex))

    def onReceived(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))

    def onMediaStateChange(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))

    def onTrace(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))

    def onPropertyChanged(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()

Release files for gurux-serial 1.0.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gurux-serial 1.0.21
File Size Uploaded
gurux_serial-1.0.21.tar.gz 24.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gurux-serial 1.0.21
File Interpreter ABI Platform
gurux_serial-1.0.21-py3-none-any.whl Python 3 none any Details

Total release size: 54.8 kB

Release files / gurux_serial-1.0.21.tar.gz

Download URL gurux_serial-1.0.21.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
97d55fa062b4d4d4bd65b0d886302754ffe87e4c22caff9f532bf3895d269bc9
BLAKE2b-256 checksum
How to use checksums
474c12dbd036a4b1a8c82a256061b9d1dd7823f83e043ac911816376ee4abe03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Release files / gurux_serial-1.0.21-py3-none-any.whl

Download URL gurux_serial-1.0.21-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39798af3451066cb9af3e87c8360b3aa16c6fdaf59117e336bea2b762a57959d
BLAKE2b-256 checksum
How to use checksums
a524f1455afa767b648bde0d97407bb90850e61347c161b1e8c2122e2fd24cd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Release history Release notifications | RSS feed

This release

1.0.21 This release

2 release files

1.0.20

2 release files

1.0.18

2 release files

1.0.17

2 release files

1.0.16

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page