Serial interface

class SerialInterface(serialName: str)

Abstract base class from which the data and command interfaces are derived.

connect(serialName: Optional[str] = None) None

Connect to a serial interface.

This method opens a serial interface.

Parameters

serialName – Name of the serial interface.

Returns

True if it connected, else false. Prints to the console if the connection is not possible.

isConnected() bool

Check if there is a connection to a serial interface.

Returns

True if it is connected, else False.

write(data: ByteString) None

Write to the serial interface.

Parameters

data – The data as bytearray().

close() None

Close the connection

writeLog(data: ByteString, direction: str) None

Write to the log.

The time stamp is calculated automatically.

Parameters
  • data – The data as bytearray().

  • direction – The direction as string.

getDebugString(withTime: bool = False, direction: Optional[str] = None) str

Read the log. This function is intended as debug output. To control what was sent when to the device and what the response was.

Parameters
  • withTime – Output of the time points. True means with time.

  • direction – The direction as string, which one you want to read. None means all.

_startTelegramListener() None

Private method which starts the receive thread.

_stopTelegramListener() None

Private method which stopps the receive thread.

abstract _telegramListenerJob() None

Private method which is called as receive thread. This must be implemented by the class that implements the abstract base class.

In the function must be stayed until _receiving_worker_is_running is False.

class SerialCommandInterface(serialName: str)

Class which implements the command interface.

Parameters

serialName – Name of the serial interface.

waitForReplyString(commandType: CommandType, timeout: Optional[float] = None) str

Waiting for the reply string.

Parameters
  • commandType (CommandType) – Type of the command.

  • timeout – The timeout for reading, None for blocking.

Returns

The answer string.

sendStringAndWaitForReplyString(string: str, commandType: CommandType = CommandType.COMMAND) str

Sending a string and waiting for the response.

Parameters

string – The string to send.

Returns

The answer string.

_telegramListenerJob() None

Method in which the receive thread runs.

More doku is in the function.

class SerialDataInterface(serialName: str)

Class which implements the data interface.

Parameters

serialName – Name of the serial interface.

_telegramListenerJob() None

Method in which the receive thread runs.

availableBytes() int

Returns the available bytes.

Returns

The available bytes.

readBytes(numberOfBytes: int, timeout: Optional[float] = None) ByteString

Read bytesRead from the interface.

Parameters
  • numberOfBytes – The number of bytesRead to read.

  • timeout – The timeout for reading, None for blocking.

Returns

The bytesRead read.

Return type

bytearray

enum CommandType(value)

Class for the two different command types.

Valid values are as follows:

COMMAND = <CommandType.COMMAND: 1>
CONTROL = <CommandType.CONTROL: 2>