Python binding for Marvelmind C API
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
Python binding for Marvelmind C API
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.
- Python 3
- Marvelmind IPS
$ python pip install https://github.com/bertoramos/marvelmind_pylib/releases/download/{version}/{so-version-file}.zip
-
Create a python virtual environment and install pybind11
$ python3 -m venv ./pybind_env $ source activate pybind_env/bin/activate (pybind_env) $ pip install pybind11
-
In marvelmind_pylib folder create a build folder
(pybind_env) $ cd marvelmind_pylib (pybind_env) $ mkdir build
-
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
-
A file with extension .so must have been created.
-
Install Visual Studio.
-
Create a python virtual environment and install pybind11.
$ python3 -m venv ./pybind_env $ pybind_env\Scripts\activate (pybind_env) $ pip install pybind11
-
In marvelmind_pylib folder create a build folder.
(pybind_env) $ cd marvelmind_pylib (pybind_env) $ mkdir build
-
In build folder execute
(pybind_env) $ cmake .. (pybind_env) $ cmake --build . --config Release --target marvelmind_pylib
-
A file with extension .pyd must have been created. You can find it in Release folder.
-
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
-
Copy the previously compiled .so/.pyd file in a new empty folder.
-
Copy the setup.py file to the newly created folder.
-
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']}
-
Execute following command inside setup.py folder:
$ python -m pip install .
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()
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.
Alberto Ramos Sánchez - alberto.ramos104@alu.ulpgc.es