Skip to main content

Communicate asynchronously with DGT boards

Project description

asyncdgt uses asyncio to communicate asynchronously with a DGT electronic chess board. View reference documentation.

https://badge.fury.io/py/asyncdgt.svg https://travis-ci.org/niklasf/python-asyncdgt.svg

Example

Create an event loop and a connection to the DGT board.

import asyncio

loop = asyncio.get_event_loop()
dgt = asyncdgt.auto_connect(["/dev/ttyACM*"], loop)

Register some pyee event handlers. They will be called whenever a board gets connected, disconnected or the position changed.

@dgt.on("connected")
def on_connected(port):
    print("Board connected to {0}!".format(port))

@dgt.on("disconnected")
def on_disconnected():
    print("Board disconnected!")

@dgt.on("board")
def on_board(board):
    print("Position changed:")
    print(board)
    print()

Get some information outside of an event handler using the coroutine get_version().

print("Version:", loop.run_until_complete(dgt.get_version()))

Run the event loop.

try:
    loop.run_forever()
except KeyboardInterrupt:
    pass
finally:
    dgt.close()
    loop.close()

See asyncdgt/__main__.py for the complete example. Run with python -m asyncdgt /dev/ttyACM0.

Hardware

Tested with the following boards:

  • DGT e-Board 3.1

  • DGT e-Board 3.1 Bluetooth

Clocks:

  • DGT Clock 3000

Dependencies

pip install -r requirements.txt

License

python-asyncdtg is licensed under the GPL3. See the LICENSE.txt file for the full license text.

Project details


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