将SDK转换为Python

2024-09-30 22:15:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我在SWIG是一个新手,所以我绝对没有经验,但我真的想使用Riftek激光器的SDK(https://riftek.com/media/rit/SDK/RFDevice_SDK.zip)。你知道吗

SDK本身包含一些头文件、dll和def文件。到目前为止,我已经编写了以下SWIG文件:

/* rfdevice.i */
%module rfdevice
%{
#include <windows.i>
#include <typemaps.i>
#include "include/RF625Device.h"
#include "include/RF625Device_Legacy.h"
#include "include/RFDevice.h"
#include "include/RFEthernetDetector.h"
#include "include/RFEthernetDevice.h"
#include "include/RFQDPMotorDevice.h"
#include "include/RFSerialDevice.h"
#include "include/RFString.h"
#include "include/RFTypeDefs.h"
#include "include/serial.h"
%}
%include <windows.i>
%include <typemaps.i>

%apply void *INPUT {void *lpResultBuffer};
%apply float *OUTPUT {float *lpPointsBuffer};
%apply USHORT *OUTPUT {USHORT *lpCount};

%include "include/RFString.h"
%include "include/serial.h"
namespace RFDevice {
    %include "include/RFTypeDefs.h"
    %include "include/RFEthernetDetector.h"
    %include "include/RFDevice.h"
    %include "include/RFEthernetDevice.h"
    %include "include/RFQDPMotorDevice.h"
    %include "include/RFSerialDevice.h"
    %include "include/RF625Device_Legacy.h"
    %include "include/RF625Device.h"
}

我可以生成rfdevice\u wrap.c文件,但我无法编译它,因为我从编译器获得了大量未定义的引用。你知道吗

我的问题是: -我是否必须在I文件中包含dll或def文件? -有没有一种更快/更简单的方法让SDK使用Python?你知道吗

我正在使用g++在windows7 64位下用MinGW编译。你知道吗


到目前为止,我设法找出了我真正的问题。我根据现状修改了这个问题。你知道吗

其中一个头中有以下函数定义:

USHORT ConvertResultToPoints(void IN *lpResultBuffer, float OUT *lpPointsBuffer, USHORT OUT *lpCount, USHORT *lpMeasureCnt = NULL, USHORT *lpPacketCnt = NULL, BOOL bChecksumCheck = FALSE);

这里的“进”和“出”引起了一些问题。我不断收到以下编译器错误:

include\RF625Device_Legacy.h(259): Error: Syntax error in input(3).

在SWIG文档中的参数处理下,有可能解决这个问题。我已经把它包含在I文件中了,但是我一直得到编译器错误。你知道吗


Tags: 文件编译器includedefsdklegacyfloatswig
1条回答
网友
1楼 · 发布于 2024-09-30 22:15:35

你可以这样开始。我用CMake

这是我的CMakeLists.txt文件文件。到目前为止,我可以创建RFString对象

cmake_minimum_required(VERSION 2.8.9)

find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})

find_package(PythonLibs REQUIRED)

include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

set_source_files_properties(RFDevice_SDK.i PROPERTIES CPLUSPLUS ON)

set(DEPS_PREFIX ${CMAKE_SOURCE_DIR}/linux)

link_directories(${DEPS_PREFIX})

set(RFDEVICE_LIBS_NAMES RFDevice3)

foreach(lib ${RFDEVICE_LIBS_NAMES})
  find_library(
    ${lib}_LIB
    NAMES ${lib}
    PATHS ${DEPS_PREFIX}
    PATH_SUFFIXES i386 x86_64
  )
  set(RFDEVICE_LIBS ${RFDEVICE_LIBS} ${${lib}_LIB})
endforeach()

message(${RFDEVICE_LIBS})

set(swig_rfdevice_sdk_HEADERS
  ./include/linuxTypeDefs.h
  ./include/RFString.h
)

set(swig_rfdevice_sdk_SOURCES
)

swig_add_module(swig_rfdevice_sdk python RFDevice_SDK.i ${swig_rfdevice_sdk_HEADERS} ${swig_rfdevice_sdk_SOURCES})

swig_link_libraries(swig_rfdevice_sdk ${RFDEVICE_LIBS} ${PYTHON_LIBRARIES})

这是.o文件

%module(docstring="This is a Python wrapper for RFDevice3") swig_rfdevice_sdk
#pragma SWIG nowarn=320
%{

  #define SWIG_FILE_WITH_INIT
  // Try to ignore cast between pointer-to-function and pointer-to-object
  #include "stdint.h"
  #include "linuxTypeDefs.h"
  #include "RFString.h"
%}

#ifdef _SWIG_WIN32
%include "windows.i"
#endif

%include "carrays.i"
%array_class(char, charArrayClass);
%array_functions(char, charArray);

// Individual modules
%include "linuxTypeDefs.h"
%include "RFString.h"

我不得不安装一个旧版本的glibc++来让它工作。或者,您可以链接到glibc++的旧版本。你知道吗

相关问题 更多 >