Skip to content

bertoramos/marvelmind_pylib

Repository files navigation


Logo

marvelmind_pylib

Python binding for Marvelmind C API
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contact


About The Project

Python binding for Marvelmind C API

(back to top)

Built With

(back to top)

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

Installation

$ python pip install https://github.com/bertoramos/marvelmind_pylib/releases/download/{version}/{so-version-file}.zip

Install from source

Building

Unix
  1. Create a python virtual environment and install pybind11

    $ python3 -m venv ./pybind_env
    $ source activate pybind_env/bin/activate
    (pybind_env) $ pip install pybind11
  2. In marvelmind_pylib folder create a build folder

    (pybind_env) $ cd marvelmind_pylib
    (pybind_env) $ mkdir build
  3. In build folder execute : cmake .. -Dpybind11_DIR=$(python -m pybind11 --cmakedir)

    (pybind_env) $ cd build
    (pybind_env) $ cmake .. -Dpybind11_DIR=$(python3 -m pybind11 --cmakedir)
    (pybind_env) $ make
  4. A file with extension .so must have been created.

Windows
  1. Install Visual Studio.

  2. Create a python virtual environment and install pybind11.

    $ python3 -m venv ./pybind_env
    $ pybind_env\Scripts\activate
    (pybind_env) $ pip install pybind11
  3. In marvelmind_pylib folder create a build folder.

    (pybind_env) $ cd marvelmind_pylib
    (pybind_env) $ mkdir build
  4. In build folder execute

    (pybind_env) $ cmake ..
    (pybind_env) $ cmake --build . --config Release --target marvelmind_pylib
  5. A file with extension .pyd must have been created. You can find it in Release folder.

Installation
  1. Deactivate environment. In this example we will install the marvelmind_pylib module in the global python3 installation. Choose where you want to install it and use that python executable instead.

    (pybind_env) $ deactivate # Deactivate pybind_env environment
  2. Copy the previously compiled .so/.pyd file in a new empty folder.

  3. Copy the setup.py file to the newly created folder.

  4. Modify setup.py file.

    Change line:

    package_data = {'': ['{dynamic file}']} # add dynamic file name

    to the name of the .so/.pyd file:

    package_data = {'': ['marvelmind_pylib.cpython-39-x86_64-linux-gnu.so']}
  5. Execute following command inside setup.py folder:

        $ python -m pip install .

(back to top)

Usage

This is an example of the use of the library.

import marvelmind_pylib

SERIAL_PORT = "COM5"

dev = marvelmind_pylib.MarvelMindDevice(SERIAL_PORT, True)
dev.start()

while True:
    try:
        mob_pos = dev.getMobileBeaconsPosition()
        stat_pos = dev.getStationaryBeaconsPosition()

        if len(mob_pos) > 0:
            print(mob_pos)
        if len(stat_pos) > 0:
            print(stat_pos)
    except KeyboardInterrupt:
        break

dev.close()

Portable usage

You can compile or download the dynamic .so/.pyd file and place it in the same folder as the python script that imports the marvelmind_pylib library.

(back to top)

Contact

Alberto Ramos Sánchez - alberto.ramos104@alu.ulpgc.es

(back to top)