This is a wrapper around the Rugged Science SDK with the only difference being that exceptions are automatically thrown. There are no getLastError or getLastErrorString functions.
The package can be installed either by compiling the sources or installing via python -m pip install rssdk.
from rssdk import RsDio, OutputMode
dio = RsDio()
try:
dio.setXmlFile("ecs9000.xml")
except Exception as e:
print(e)
exit(1)
dio.setOutputMode(1, OutputMode.Source)
dio.digitalRead(1, 1)
dio.digitalWrite(1, 11, True)from rssdk import RsPoe, PoeState
poe = RsPoe()
try:
poe.setXmlFile("ecs9000.xml")
except Exception as e:
print(e)
exit(1)
poe.getPortState(3)
poe.setPortState(PoeState.StateDisabled)The Python bindings are built against the standard C++ SDK libraries using pybind11. There are two ways to compile them. Either using Python's build system or by using cmake directly. Both options assume you have have already cloned the repository as shown in the step below.
NOTE: It is best to enable long paths in Windows when compiling using the Python build system.
git clone https://github.com/ruggedscience/SDK
cd SDKUsing Python's build system is the recommended way to build the bindings. It will produce a wheel that can be installed using pip and handles the installation of the required build modules. It will install all of the modules inside an isolated virtual environment that will be deleted after compilation is finished.
-
Install the Python build module.
python -m pip install build -
Build the source distribution and wheel.
python -m build -
Install the newly built wheel.
python -m pip install ./dist/<name of wheel file>.whl
The cmake build process isn't quite as straightforward but offers more flexibility. Since multiple dependencies are required it is suggested that you create a virtual environment for the build process to use. Note that the resulting package will be installed into that virtual environment. Information on how to do this can be found in the official Python docs.
-
Install requirements
python -m pip install pybind11 setuptools_scm mypyNote: mypy is optional and used to generate stub files. This allows IDEs to offer code completion.
-
Create build folder
mkdir build cd build
-
Configure cmake
cmake -DBUILD_PYTHON_BINDINGS=ON -DINSTALL_PYTHON_BINDINGS=ON -DBUILD_SHARED_LIBS=OFF -DINSTALL_XML=OFF -DINSTALL_UTILITIES=OFF -DINSTALL_SDK=OFF ..Note: On Linux the build type should be set to release using
-DBUILD_TYPE=Release. -
Build and install
cmake --build . --target installNote: On Windows the build type should be set to release using
--config Release.