-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add py interface * not working * Add cmake-build folder and *.zip files to .gitignore * Change Python directory, Set Enable BOOST macro and adjust the Boost/Python version in py_icl CMakeLists.txt * Change general_config to build all libraries (common_tools_lib, pugixml) static * Set Boost root dir and include folder in CMakeLists.txt * Statically link libc and libstdcc to python wrapper * Add additional constructor without logging to Keithley SMU class, implement error code enums * fix python version hardcode * fix python version hardcode * Add command to recursively checkout boost when folder does not exist * Update boost to master branch to allow checkout on .githubactions * Add include path to boost/stage/lib/python/include * Move boost python outside the WIN32 brakets * Add ls command in boost folder for test purposes * uncomment boost directory check to display the folder content for test purposes * Display Boost_ROOT for test purposes * Display Boost_ROOT/stage/lib/python for test purposes * Change include folder of python.hpp * Adjust the CMakeLists file additionally * Temporary disable pyhton interface to satisfy CI Co-authored-by: wuhao <[email protected]>
- Loading branch information
1 parent
fa16dcf
commit f46ac51
Showing
11 changed files
with
206 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ | |
[submodule "pugixml"] | ||
path = pugixml | ||
url = [email protected]:zeux/pugixml.git | ||
[submodule "boost"] | ||
path = boost | ||
url = https://github.com/boostorg/boost.git | ||
ignore = all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
cmake_minimum_required(VERSION 3.4) | ||
|
||
set(PROJECT_NAME "py_icl") | ||
set(LIBRARY_NAME "lib${PROJECT_NAME}") | ||
|
||
set(PYTHON_FOLDER "C:/Users/Administrator/AppData/Local/Programs/Python/Python310") | ||
|
||
find_package (Python REQUIRED) | ||
find_package(PythonLibs) | ||
|
||
add_definitions(/DBOOST_PYTHON_STATIC_LIB) | ||
set(PYTHON_VERSION ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) | ||
if (${Python_VERSION_MAJOR}) | ||
message(STATUS "Using python version: ${PYTHON_VERSION}") | ||
else() | ||
message(FATAL_ERROR "ERROR. Python not found.") | ||
endif() | ||
|
||
|
||
set(BOOST_BOOTSTRAP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boost/tools/build) | ||
|
||
message(${BOOST_BOOTSTRAP_DIR}) | ||
if (NOT IS_DIRECTORY ${BOOST_BOOTSTRAP_DIR}) | ||
message(FATAL_ERROR "Boost build directory not found. Run `git submodule update --init --recursive` First") | ||
set(BOOST_CHECKOUT powershell 'git submodule update --init --recursive') | ||
execute_process( | ||
COMMAND ${BOOST_CHECKOUT} | ||
WORKING_DIRECTORY ${BOOST_ROOT} | ||
) | ||
endif() | ||
|
||
# TODO: relocate | ||
set(BOOST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../boost) | ||
set(BOOST_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boost/build) | ||
|
||
if(WIN32) | ||
set(BOOST_BUILD_BINARY "${BOOST_BOOTSTRAP_DIR}/b2.exe") | ||
set(BOOST_BOOTSTRAP_COMMAND cmd /C ".\\bootstrap.bat gcc --with-python-version=${PYTHON_VERSION}") | ||
set(BOOST_BUILD_COMMAND cmd /C ".\\tools\\build\\b2.exe toolset=gcc --with-python --prefix=build variant=release") | ||
else() | ||
# TODO: BOOST_BUILD_BINARY | ||
set(BOOST_BOOTSTRAP_COMMAND "./bootstrap.sh --with-python-version=${PYTHON_VERSION}") | ||
endif() | ||
|
||
if (NOT EXISTS ${BOOST_BUILD_BINARY}) | ||
message(STATUS "Start to build boost build binary(b2) in: ${BOOST_BOOTSTRAP_DIR}") | ||
message(STATUS ${BOOST_BOOTSTRAP_COMMAND}) | ||
execute_process( | ||
COMMAND ${BOOST_BOOTSTRAP_COMMAND} | ||
WORKING_DIRECTORY ${BOOST_BOOTSTRAP_DIR} | ||
) | ||
endif() | ||
if (NOT IS_DIRECTORY ${BOOST_LIB_DIR} ) | ||
message(STATUS "Start to build BOOST.PYTHON") | ||
message(STATUS ${BOOST_BUILD_COMMAND}) | ||
execute_process( | ||
COMMAND ${BOOST_BUILD_COMMAND} | ||
WORKING_DIRECTORY ${BOOST_ROOT} | ||
) | ||
endif() | ||
|
||
|
||
if (NOT IS_DIRECTORY ${BOOST_LIB_DIR}) | ||
# message("Start to build Boost library") | ||
# message(${BOOST_BOOTSTRAP_COMMAND}) | ||
# execute_process( | ||
# COMMAND ${BOOST_BOOTSTRAP_COMMAND} | ||
# WORKING_DIRECTORY ${BOOST_ROOT} | ||
# OUTPUT_FILE bootstrap_boost.txt | ||
# ) | ||
# | ||
# message(${BOOST_BUILD_COMMAND}) | ||
# execute_process( | ||
# COMMAND ${BOOST_BUILD_COMMAND} | ||
# WORKING_DIRECTORY ${BOOST_ROOT} | ||
# OUTPUT_FILE build_boost.txt | ||
# ) | ||
else() | ||
message("Boost library built.") | ||
endif() | ||
|
||
link_directories(${BOOST_LIB_DIR}/lib "${PYTHON_FOLDER}" | ||
"${BOOST_ROOT}/stage/lib") | ||
add_library(${PROJECT_NAME} SHARED main.cpp) | ||
|
||
target_include_directories(${PROJECT_NAME} PRIVATE | ||
"${BOOST_ROOT}" | ||
"${BOOST_LIB_DIR}/include/boost-1_80" | ||
"${PYTHON_INCLUDE_PATH}" | ||
"/usr/include/python${PYTHON_VERSION}" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../include" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../boost" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../common_tools_lib/ErrorHandling/include" | ||
) | ||
|
||
|
||
set(BOOST_PYTHON_LIB "boost_python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}") | ||
target_link_directories(${PROJECT_NAME} PUBLIC "${BOOST_ROOT}\\stage\\lib") | ||
|
||
set(BOOST_PYTHON_LIB "boost_python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}-mgw11-mt-x64-1_80") | ||
message("BOOST PYTHON LIB ${BOOST_PYTHON_LIB}") | ||
target_link_directories(${PROJECT_NAME} PUBLIC "${BOOST_ROOT}/stage/lib/" | ||
"${BOOST_ROOT}/libs/python/include") | ||
|
||
target_link_libraries(${PROJECT_NAME} PUBLIC instrument_control_lib ${BOOST_PYTHON_LIB} ${PYTHON_LIBRARY}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".pyd") | ||
target_link_options(${PROJECT_NAME} PUBLIC -static -static-libgcc -static-libstdc++) | ||
|
||
configure_file(py_icl_test.py py_icl_test.py COPYONLY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Build python interface | ||
|
||
Run the following commands to build python interfaces lib | ||
|
||
In root directory | ||
``` | ||
instrument_control_lib$ git submodule update --init --recursive | ||
instrument_control_lib$ cd boost | ||
instrument_control_lib/boost$ ./bootstrap.sh --with-python-version=3.8 | ||
instrument_control_lib/boost$ .b2 --with-python | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "boost/python.hpp" | ||
#include "Device.h" | ||
#include "devices/types/DCPowerSupply.h" | ||
#include "devices/SPD1305.h" | ||
#include "devices/KEI2600.h" | ||
#include "ctlib/Logging.hpp" | ||
|
||
using namespace boost::python; | ||
|
||
BOOST_PYTHON_MODULE(libpy_icl) | ||
{ | ||
enum_<DCPowerSupply::DC_CHANNEL>("DC_CHANNEL") | ||
.value("CHANNEL_1", DCPowerSupply::DC_CHANNEL::CHANNEL_1) | ||
.value("CHANNEL_2", DCPowerSupply::DC_CHANNEL::CHANNEL_2); | ||
|
||
enum_<PIL_ERROR_CODE>("ERROR_CODE") | ||
.value("NO_ERROR", PIL_ERROR_CODE::PIL_NO_ERROR) | ||
.value("PIL_INVALID_ARGUMENTS", PIL_ERROR_CODE::PIL_INVALID_ARGUMENTS) | ||
.value("ERRNO", PIL_ERROR_CODE::PIL_ERRNO) | ||
.value("INTERFACE_CLOSED", PIL_ERROR_CODE::PIL_INTERFACE_CLOSED) | ||
.value("INVALID_BAUDRATE", PIL_ERROR_CODE::PIL_INVALID_BAUDRATE) | ||
.value("INSUFFICIENT_RESOURCES", PIL_ERROR_CODE::PIL_INSUFFICIENT_RESOURCES) | ||
.value("INSUFFICIENT_PERMISSIONS", PIL_ERROR_CODE::PIL_INSUFFICIENT_PERMISSIONS) | ||
.value("DEADLOCK_DETECTED", PIL_ERROR_CODE::PIL_DEADLOCK_DETECTED) | ||
.value("THREAD_NOT_JOINABLE", PIL_ERROR_CODE::PIL_THREAD_NOT_JOINABLE) | ||
.value("THREAD_NOT_FOUND", PIL_ERROR_CODE::PIL_THREAD_NOT_FOUND) | ||
.value("ONLY_PARTIALLY_READ_WRITTEN", PIL_ERROR_CODE::PIL_ONLY_PARTIALLY_READ_WRITTEN) | ||
.value("NO_SUCH_FILE", PIL_ERROR_CODE::PIL_NO_SUCH_FILE) | ||
.value("UNKNOWN_ERROR", PIL_ERROR_CODE::PIL_UNKNOWN_ERROR) | ||
.value("XML_PARSING_ERROR", PIL_ERROR_CODE::PIL_XML_PARSING_ERROR); | ||
|
||
|
||
|
||
class_<SPD1305>("SPD1305", init<char *, int>()) | ||
.def("Connect", &SPD1305::Connect) | ||
.def("setCurrent", &SPD1305::setCurrent) | ||
.def("getCurrent", &SPD1305::getCurrent) | ||
.def("Disconnect", &SPD1305::Disconnect); | ||
|
||
|
||
class_<KEI2600>("KEI2600", init<char *, int>()) | ||
.def("Connect", &KEI2600::Connect) | ||
.def("setCurrent", &KEI2600::Disconnect); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
from libpy_icl import * | ||
import os | ||
import sys | ||
|
||
os.add_dll_directory(os.getcwd()) | ||
|
||
|
||
def spd_test(): | ||
spd = SPD1305("132.231.14.176", 0) | ||
spd.Connect() | ||
spd.setCurrent(DC_CHANNEL.CHANNEL_1, 0.1) | ||
current = spd.getCurrent(DC_CHANNEL.CHANNEL_1) | ||
current == 0.1 | ||
spd.Disconnect() | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
doctest.testmod() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters