eg.SerialThread

class eg.SerialThread(hFile=0)[source]

Eased handling of serial port communication.

Close()[source]

Closes the serial port and stops all event processing.

classmethod GetAllPorts()[source]

Returns a list with all available serial ports.

GetBaudrate()[source]

Returns the currently used baud rate as an integer.

GetMode()[source]

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')[source]

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)[source]

Reads data from the serial port.

ResumeReadEvents()[source]

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

exception SerialError(msg=None)

Base class for SerialThread related exceptions.

SetBaudrate(baudrate)[source]

Sets the baud rate to an integer value.

SetDtr(flag=True)[source]

Sets DTR state.

SetMode(mode)[source]

Sets the serial port mode setting from a string.

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

SetReadEventCallback(callback)[source]

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.

SetRts(flag=True)[source]

Sets RTS state.

Start()[source]

Starts the event processing of this class.

Stop()[source]

Stops the event processing of this class.

SuspendReadEvents()[source]

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

Write(data)[source]

Writes a string to the port.