eg.SerialThread

class eg.SerialThread(hFile=0)

Eased handling of serial port communication.

Close()

Closes the serial port and stops all event processing.

classmethod GetAllPorts()

Returns a list with all available serial ports.

GetBaudrate()

Returns the currently used baud rate as an integer.

GetMode()

Returns the currently used serial port mode setting as string.

See Open() for a complete description of the mode string.

Open(port=0, baudrate=9600, mode='8N1')

Opens the serial port. After the port is opened, you have to call Start() to start the actual event processing of this class.

Arguments :
port

The port to open as an integer starting at one (0 = COM1)

baudrate

The baudrate to use as an integer. Defaults to 9600.

mode

The serial port mode settings to use. This should be a string created by the joining of the following parts:

  1. byte size

    ‘5’, ‘6’, ‘7’ or ‘8’

  2. parity mode
    • ‘N’ for no parity,
    • ‘E’ for even parity,
    • ‘O’ for odd parity,
    • ‘M’ for mark parity,
    • ‘S’ for space parity
  3. stop bits
    • ‘1’ for one stop bit
    • ‘1.5’ for one and a half stop bit
    • ‘2’ for two stop bits

Example values: ‘8N1’ (default), ‘8E1’, ‘7N1.5’

Read(numBytes=1, timeout=0.0)

Reads data from the serial port.

ResumeReadEvents()

Resumes the receive event processing that was disabled before by SuspendReadEvents()

exception SerialError(msg=None)

Base class for SerialThread related exceptions.

SerialThread.SetBaudrate(baudrate)

Sets the baud rate to an integer value.

SerialThread.SetDtr(flag=True)

Sets DTR state.

SerialThread.SetMode(mode)

Sets the serial port mode setting from a string.

See Open() for a complete description of the mode string.

SerialThread.SetReadEventCallback(callback)

Sets a callback function for receive event processing. Should be called before Start(). The callback should have the form:

def HandleReceive(serialThread):
    ...

where serialThread will be the instance of this SerialThread class, so you can easily call Read() and Write() on this object.

SerialThread.SetRts(flag=True)

Sets RTS state.

SerialThread.Start()

Starts the event processing of this class.

SerialThread.Stop()

Stops the event processing of this class.

SerialThread.SuspendReadEvents()

Temporarily disables the receive event processing of this class. Call ResumeReadEvents() to resume processing.

SerialThread.Write(data)

Writes a string to the port.

Previous topic

eg.SerialPortChoice

Next topic

eg.SpinIntCtrl

This Page