diff --git a/README.md b/README.md index c64c8915c4abbb3c5401ac60469f7d7951444bd5..87650fa1232480cc9596afe03f90735d5e7c7954 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ For building this project in both Windows and Linux the following tools must be - [cmake](https://cmake.org/download/): Download .msi file and execute it. - [swig](http://www.swig.org/survey.html): Download the .zip and unzip it. Include the folder into `path` environemnt variable. - [doxygen](https://www.doxygen.nl/download.html): Download .exe file and execute it. +- [python 3.7.9](https://www.python.org/downloads/release/python-379/): Download .msi file and execute it. ## Linux ``` @@ -21,6 +22,7 @@ sudo snap install cmake --classic sudo apt-get install swig sudo apt-get install doxygen sudo apt install graphviz +sudo apt-get install python3.7 ``` # Build project diff --git a/serial_port_class_api/CMakeLists.txt b/serial_port_class_api/CMakeLists.txt index b102babb8cf20e223959472bc6072036aa3b8709..e6263a29c61870fa105a73db6813826b78b8f94a 100644 --- a/serial_port_class_api/CMakeLists.txt +++ b/serial_port_class_api/CMakeLists.txt @@ -3,11 +3,13 @@ cmake_minimum_required(VERSION 3.14) project(class_api) add_subdirectory(src) +add_subdirectory(libreria_LQL) find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) set(NET_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/csharpwrapper") +set(PYTHON_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/pythonwrapper") set(CMAKE_SWIG_FLAGS "") @@ -15,12 +17,12 @@ set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i PROP swig_add_library(CLASS_SerialPort TYPE SHARED - LANGUAGE CSharp + LANGUAGE csharp SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i OUTPUT_DIR ${NET_PROJECT_DIR} OUTFILE_DIR ${NET_PROJECT_DIR} ) - swig_link_libraries(CLASS_SerialPort class_serial_port) +swig_link_libraries(CLASS_SerialPort class_serial_port) set_target_properties(CLASS_SerialPort PROPERTIES @@ -30,6 +32,27 @@ set_target_properties(CLASS_SerialPort INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ) +find_package(PythonInterp) +find_package(PythonLibs REQUIRED) + +include_directories(${PYTHON_INCLUDE_DIRS}) +include_directories(${PYTHON_INCLUDE_PATH}) + +swig_add_library(CLASS_SerialPortPython + TYPE SHARED + LANGUAGE python + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i + OUTPUT_DIR ${PYTHON_PROJECT_DIR} + OUTFILE_DIR ${PYTHON_PROJECT_DIR}) + +swig_link_libraries(CLASS_SerialPortPython class_serial_port ${PYTHON_LIBRARIES}) +set_target_properties(CLASS_SerialPortPython + PROPERTIES SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PYTHON_PROJECT_DIR} + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PYTHON_PROJECT_DIR} + LIBRARY_OUTPUT_DIRECTORY ${PYTHON_PROJECT_DIR}) + + option(BUILD_DOC "Build documentation" ON) message(STATUS "Build documentation: ${BUILD_DOC}") if (BUILD_DOC) diff --git a/serial_port_class_api/README.md b/serial_port_class_api/README.md index a3e4b9da741ca2f7a74a82528df872e9cf72a2f6..87650fa1232480cc9596afe03f90735d5e7c7954 100644 --- a/serial_port_class_api/README.md +++ b/serial_port_class_api/README.md @@ -1,7 +1,47 @@ -# Project structure -Project is structured with the following folders: - * docs : documentation is automatically produced from comments by doxygen once a built is done, it will be found in docs/documentation/index.html. - * include : it contains header files for the API. - * src : contains API functions in CLASS_SerialPort.cpp and main.cpp file as example of how to use those funtions. - * wrappers : wrappers are automatically produced by swig. It generates files to be used in C# scripts. +This repo contains the source code to communicate with CLASS device through serial port. +For building this project in both Windows and Linux the following tools must be installed: + +- Building tools +- cmake: for building the project +- swig: for the generation of wrappers +- doxygen: for the generation of the documentation +- graphviz: required by doxygen + +## Windows +- [this](https://aka.ms/vs/15/release/vs_buildtools.exe) Build tools for Visual Studio (2017), needed for compiling C++. +- [cmake](https://cmake.org/download/): Download .msi file and execute it. +- [swig](http://www.swig.org/survey.html): Download the .zip and unzip it. Include the folder into `path` environemnt variable. +- [doxygen](https://www.doxygen.nl/download.html): Download .exe file and execute it. +- [python 3.7.9](https://www.python.org/downloads/release/python-379/): Download .msi file and execute it. + +## Linux +``` +sudo apt-get install build-essential +sudo snap install cmake --classic +sudo apt-get install swig +sudo apt-get install doxygen +sudo apt install graphviz +sudo apt-get install python3.7 +``` + +# Build project +This code has been programmed in C++. Wrappers for C# are generated automatically by swig. +## C++ building with CMake +* Create a build folder and enter the folder +* Execute the following commands to configure the platform + + + -Windows + + + cmake -G "Visual Studio 15 2017 Win64" CMAKE_BUILD_TYPE=Release ../ + + cmake --build . --target ALL_BUILD --config Release + + + -Linux + + cmake ../ + + make diff --git a/serial_port_class_api/src/CMakeLists.txt b/serial_port_class_api/src/CMakeLists.txt index 4e2d4154590b5ae080a1ad85916310f84dcb83de..e6263a29c61870fa105a73db6813826b78b8f94a 100644 --- a/serial_port_class_api/src/CMakeLists.txt +++ b/serial_port_class_api/src/CMakeLists.txt @@ -1,19 +1,60 @@ - cmake_minimum_required(VERSION 3.14) -project (class_serial_port VERSION 0.1.0) -add_executable(class_api_exe - CLASS_SerialPort.cpp - main.cpp) +project(class_api) + +add_subdirectory(src) +add_subdirectory(libreria_LQL) + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +set(NET_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/csharpwrapper") +set(PYTHON_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/pythonwrapper") + +set(CMAKE_SWIG_FLAGS "") + +set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i PROPERTY CPLUSPLUS ON) + +swig_add_library(CLASS_SerialPort + TYPE SHARED + LANGUAGE csharp + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i + OUTPUT_DIR ${NET_PROJECT_DIR} + OUTFILE_DIR ${NET_PROJECT_DIR} + ) +swig_link_libraries(CLASS_SerialPort class_serial_port) + +set_target_properties(CLASS_SerialPort + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${NET_PROJECT_DIR} + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${NET_PROJECT_DIR} + LIBRARY_OUTPUT_DIRECTORY ${NET_PROJECT_DIR} + INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} + ) -target_link_libraries(class_api_exe ${CMAKE_CURRENT_SOURCE_DIR}/../commands.lib) +find_package(PythonInterp) +find_package(PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIRS}) +include_directories(${PYTHON_INCLUDE_PATH}) -set(class_files_local ${CMAKE_CURRENT_SOURCE_DIR}/CLASS_SerialPort.cpp) +swig_add_library(CLASS_SerialPortPython + TYPE SHARED + LANGUAGE python + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i + OUTPUT_DIR ${PYTHON_PROJECT_DIR} + OUTFILE_DIR ${PYTHON_PROJECT_DIR}) -set(class_files ${class_files_local} PARENT_SCOPE) +swig_link_libraries(CLASS_SerialPortPython class_serial_port ${PYTHON_LIBRARIES}) +set_target_properties(CLASS_SerialPortPython + PROPERTIES SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PYTHON_PROJECT_DIR} + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PYTHON_PROJECT_DIR} + LIBRARY_OUTPUT_DIRECTORY ${PYTHON_PROJECT_DIR}) -add_library(class_serial_port ${class_files_local}) -target_link_libraries(class_serial_port ${CMAKE_CURRENT_SOURCE_DIR}/../commands.lib) -set_target_properties(class_serial_port PROPERTIES FOLDER class) +option(BUILD_DOC "Build documentation" ON) +message(STATUS "Build documentation: ${BUILD_DOC}") +if (BUILD_DOC) + add_subdirectory(docs) +endif() \ No newline at end of file diff --git a/serial_port_class_api/src/main.cpp b/serial_port_class_api/src/main.cpp index 83ae980f7f60d299d39e59ea698421b946c8a162..a4779757c008fa57dc1d014ab8b80c623f78e46d 100644 --- a/serial_port_class_api/src/main.cpp +++ b/serial_port_class_api/src/main.cpp @@ -26,12 +26,6 @@ int main(void) cout << "Port Status :"; cout << port_status <<endl; - - - - - - if(port_status == 1) {