-
Notifications
You must be signed in to change notification settings - Fork 2
Library
This section provides a reference and explanation of all techmanpy
library functions. It is split into three subsections:
- Functions to interact with the TMFlow Server, used to get and set internal parameters
- Functions to query the Project Status
- 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.
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:
-
techmanpy
usesasyncio
for all communication. This means that it must run in anasync
function in which communication calls have to use theawait
' keyword. - 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.
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.
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.