Skip to content

Library

Jules van der Toorn edited this page Jan 2, 2021 · 9 revisions

This section provides a reference and explanation of all techmanpy library functions. It is split into three subsections:

  1. Functions to interact with the TMFlow Server, used to get and set internal parameters
  2. Functions to query the Project Status
  3. Functions to send motion commands using the External Script interface

For an elaboration on the mentioned terms and concepts, consult the TMFlow manual.

This page will explain general characteristics of the library, and explain common concepts.

Setting up a techmanpy connection

The code for setting up a connection is the same for all different protocols:

#!/usr/bin/env python

import asyncio
import techmanpy
from techmanpy import TechmanException

async def main():
   try: 
      async with techmanpy.connect_<protocol>(<args>) as conn:
         # connection established
         ...
   except TechmanException as e: print(e) # connection could not be established

try: asyncio.run(main())
except KeyboardInterrupt: pass # user interrupted with Ctrl+C

Two important qualities can immediately be noticed:

  1. techmanpy uses asyncio for all communication. This means that it must run in an async function in which communication calls have to use the await' keyword.
  2. A connection object is created using an asynchronous context manager, characterized by the async with keywords. This ensures that all connections are gracefully shutdown, and not kept open if unnecessary.

Handling errors

As could be seen in the previous example, all techmanpy related errors can be catched as a TechmanException. It encapsulates connection, packet and protocol related errors. Specifically the following subexceptions exist:

  • TMConnectError, which is thrown when something went wrong with the socket connection
  • TMParseError, which is thrown when something went wrong with parsing the outgoing or incoming message
  • TMProtocolError, which is thrown when something in the communication protocol went wrong, such as an invalid operation
  • TMSVRError, which is thrown when something went wrong with the TMFlow Server protocol
  • TMSTAError, which is thrown when something went wrong with the Project Status protocol
  • TMSCTError, which is thrown when something went wrong with the External Script protocol

Use print(e) on the catched exception for more information.

Queue tags

TMFlow makes use of a queue when multiple commands are received. This means that when a new command is received while motion is ongoing, it will be appended to the command queue. Then, only once the initial motion is complete, will the new command be executed.
Queue tags make it possible to attach an identifier for a certain item in the queue. This tag can then later be used as a reference to query the execution status. The commands for setting a queue tag and obtaining its status are mentioned on the Project Status and External Script pages.