thorlabs_apt_device.protocol.unpacker module

class thorlabs_apt_device.protocol.unpacker.Unpacker(file_like=None, on_error='continue')[source]

Bases: object

Create an Unpacker to decode a byte stream into Thorlabs APT protocol messages.

The file_like parameter should be an object which data can be sourced from. It should support the read() method.

The on_error parameter selects the action to take if invalid data is detected. If set to "continue" (the default), bytes will be discarded if the byte sequence does not appear to be a valid message. If set to "warn", the behaviour is identical, but a warning message will be emitted. To instead immediately abort the stream decoding and raise a RuntimeError, set to "raise".

Parameters:
  • file_like – A file-like object which data can be read() from.

  • on_error – Action to take if invalid data is detected.

feed(data: bytes)[source]

Add byte data to the input stream.

The input stream must support random access, if it does not, must be fed externally (e.g. serial port data).

Parameters:

data – Byte array containing data to add.