Skip to content
module

pylnlib.Interface

Classes
  • Interface Handles thread safe sending and receiving LocoNet messages on a serial interface.</>
Functions
  • timeDiff(a, b) (float) Return the total number of seconds between a and b.</>
class

pylnlib.Interface.Interface(port, baud=57600, fast=False, dummy=False)

Handles thread safe sending and receiving LocoNet messages on a serial interface.

Parameters
  • port (str) serial port, on Linux typically something like /dev/ttyACM0
  • baud (int, optional) the baudrate. Defaults to 57600.
  • fast (bool, optional) if false it uses timestamp message in the input data to replay a realistic speed. Defaults to False.
  • dummy (bool, optional) if true it will not write anyhting on the serial port. Defaults to False.
Example
interface = Interface()
scrollkeeper = Scrollkeeper(interface)
interface.receiver_handler.append(scrollkeeper.messageListener)
Thread(target=interface.run, daemon=True).start()

It will gracefully exit if it receives a SIGINT or SIGTERM signal, i.e. terminate the thread that handle the input and output queues.

Methods
  • run(delay) Start processing input and output.</>
  • run_in_background(delay) Start processing input and output and return immediately.</>
  • sendMessage(msg) Put a message on the internal output queue.</>
method

run(delay=0.0)

Start processing input and output.

This will continue until an external SIGINT or SIGKILL signal is received.

Parameters
  • delay (float, optional) Time in seconds to wait between incoming messages. Defaults to 0.
Returns

only returns upon receiving an external signal.

method

run_in_background(delay=0.0)

Start processing input and output and return immediately.

Processing will continue until an external SIGINT or SIGKILL signal is received.

Parameters
  • delay (float, optional) Time in seconds to wait between incoming messages. Defaults to 0.
Returns

immediately.

method

sendMessage(msg)

Put a message on the internal output queue.

Parameters
  • msg (Message) A LocoNet Message
function

pylnlib.Interface.timeDiff(a, b)

Return the total number of seconds between a and b.

b MUST be later than a, so the difference between a = 23:55:49 and b = 00:05:49 will be correctly reported as 10 minutes.

Parameters
  • a (datetime) earlier timestamp
  • b (datetime) later timestamp
Returns (float)

the total number of seconds between a and b