Skip to main content

Wrapper for the nqc executable

Project description

pynqc NQC wrapper

pynqc is a python wrapper for the NQC executable. It utilizes the subprocess module for communitcation with NQC. The wrapper is not complete, but should be easy to update.

Requirements

The package does not include the NQC executeable it has to be built and installed from https://github.com/jverne/nqc/

There is also Dockerfile in this repo which downloads source and a patch to enable usb support for nqc.

https://github.com/jverne/nqc/ also provides the firmware needed to be flashed onto the RCX device for running progams. The Dockerfile in the repo downloads those aswell.

Layout

pynqc consists of two modules:

  • nqc and the Nqc class
  • raw_functions and the RawFunctions class, enables us to execute op_codes on
  • the rcx from the host. It does so by generating the instruction and calls the Nqc objects exec_raw which essentially executes nqc -Susb:/some/path/to/legotower -raw

Example usage

import time

import pynqc
from pynqc import raw_functions as rf

compilation_flags = ["-DOVERRIDE", f"-DVERSION={1}", f"-DID={189}"]

# An nqc instance requires knowledge of where it can find the lego IR tower
nqc = pynqc.Nqc(serial_type="usb", device="/dev/usb/legousbtower0")

# Raw functions also requires access to the lego IR tower
# Therefore the nqc module has utility function which provides
# an initialized raw_functions object

raw_func = nqc.get_raw_functions()

try:
    _ = raw_func.is_alive()
except IOError as err:
    if err.errno == 255:
        print(err.strerror)
else:
    _ = nqc.flash_firmware("./firm0309.lgo")
    _ = nqc.flash_and_exec_application("../tests/test.nqc", compilation_flags)
    time.sleep(1)
    raw_func.set_motor_state(rf.MOTOR_A, rf.IMMEDIATE, rf.MOTOR_ON)
    time.sleep(1)
    raw_func.set_motor_state(rf.MOTOR_A, rf.IMMEDIATE, rf.MOTOR_OFF)

Credit

Kekoa Proudfoot : http://www.mralligator.com/rcx/ This site helped a lot when implementing the raw functions from the documented op_codes.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynqc-0.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file pynqc-0.1-py3-none-any.whl.

File metadata

  • Download URL: pynqc-0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 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/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for pynqc-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da5e5489377c0f9e033d8fcdd3263eea769a5f39fefdde64081b358632b36440
MD5 995bcc25610d10fa9f258984af8217a3
BLAKE2b-256 a64864ad11cca8a63dc8560fb4030fa6aad78fc54335ec95155cd64d905a8384

See more details on using hashes here.

Supported by

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