Skip to main content

Functional implementation of the thorlabs APT protocol

Project description

Thorlabs APT protocol

A functional implementation of the Thorlabs APT protocol

Outgoing messages

Outgoing messages are python functions in the top level namespace. Each function has parameters relevant to the particular message, all messages have source and dest parameters. The function names are lower-cased from the names in the documentation and the "MGMSG_" has been omitted. These functions return bytes, they do not send the message over the transport layer

For example:

>>> import thorlabs_apt_protocol as apt
>>> 
>>> apt.mot_move_home(source=1, dest=0x50 ,chan_ident=1)
b'C\x04\x01\x00P\x01'
>>> apt.mot_move_absolute(source=1, dest=0x50, chan_ident=1, position=2048)
b'S\x04\x06\x00\xd0\x01\x01\x00\x00\x08\x00\x00'

Incoming messages

Functions which allow for parsing bytes into dictionaries are also provided, but are not imported into the top level namespace by default. The recommended way of parsing is to use the provided Unpacker object.

This object takes a file-like object (such as a pyserial Serial instance) and provides a generator to parse the incomming messages. If no file object is provided, and internal BytesIO instance is used, and can be provided with bytes via the feed method. The generator yields namedtuple instances.

Usage with pyserial:

>>> import thorlabs_apt_protocol as apt
>>> import serial
>>> 
>>> port = serial.Serial("/dev/ttyUSB0", 115200, rtscts=True)
>>> port.rts = True
>>> port.reset_input_buffer()
>>> port.reset_output_buffer()
>>> port.rts = False
>>> port.write(apt.hw_no_flash_programming(source=1, dest=0x50))
>>> unpacker = apt.Unpacker(port)
>>> for msg in unpacker:
...     print(msg)
... 
>>> 

On Windows, you must toggle a driver setting to make the COM port appear:

Within Device Manager, right click on the APT device (under USB devices), and go to Properties. On the Advanced tab, check the box that says Load VCP (VCP stands for Virtual COM Port). Unplug and replug the USB cable to make it load the COM Port.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thorlabs-apt-protocol-25.0.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

thorlabs_apt_protocol-25.0.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file thorlabs-apt-protocol-25.0.0.tar.gz.

File metadata

  • Download URL: thorlabs-apt-protocol-25.0.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for thorlabs-apt-protocol-25.0.0.tar.gz
Algorithm Hash digest
SHA256 37df81fb501a8bf85d89d9bf00913c12679dea0505b76b9b3681e6c9eef0e02c
MD5 1f5bc932932c4fa3ad7bfa56e4c1cdfb
BLAKE2b-256 329693e41d5e03654b1109bbe56a74cdf83e9e48dfe28048e73a527abc76cfd1

See more details on using hashes here.

File details

Details for the file thorlabs_apt_protocol-25.0.0-py3-none-any.whl.

File metadata

  • Download URL: thorlabs_apt_protocol-25.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for thorlabs_apt_protocol-25.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06685fe33959e6c30c5f8abd62e798ca4d221e3231519742bfd49538f48bc06d
MD5 85b9cbcf4753f3159d19d1f90fd42b91
BLAKE2b-256 25b1879e1da5592a1b7e3efc0bcc5088a4471d0b5dcea9be7ce7ba75292efa71

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page