summaryrefslogtreecommitdiffstats
path: root/pywrap
diff options
context:
space:
mode:
Diffstat (limited to 'pywrap')
-rw-r--r--pywrap/CMakeLists.txt15
-rw-r--r--pywrap/pcipywrap.c160
-rw-r--r--pywrap/test_pcipywrap.py4
3 files changed, 91 insertions, 88 deletions
diff --git a/pywrap/CMakeLists.txt b/pywrap/CMakeLists.txt
index f77c2ff..b00fdb0 100644
--- a/pywrap/CMakeLists.txt
+++ b/pywrap/CMakeLists.txt
@@ -2,26 +2,29 @@ include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/pcilib
+ ${CMAKE_SOURCE_DIR}/pywrap
${CMAKE_BINARY_DIR}/pcilib
${LIBXML2_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIR}
${UTHASH_INCLUDE_DIRS}
)
-set(HEADERS pcipywrap.h)
-
-#Creating python wrapping
include(${SWIG_USE_FILE})
-include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+set(HEADERS pcipywrap.h)
set(CMAKE_SWIG_FLAGS "")
swig_add_module(pcipywrap python pcipywrap.i pcipywrap.c)
swig_link_libraries(pcipywrap ${PYTHON_LIBRARIES} pcilib)
+
#install pcilib python wrapper into Python site packages folder
execute_process ( COMMAND python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
+
install(TARGETS ${SWIG_MODULE_pcipywrap_REAL_NAME} DESTINATION ${PYTHON_SITE_PACKAGES})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pcipywrap.py DESTINATION ${PYTHON_SITE_PACKAGES})
-configure_file(server.py server.py)
-configure_file(test_pcipywrap.py test_pcipywrap.py)
+if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/server.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test_pcipywrap.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+endif(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
diff --git a/pywrap/pcipywrap.c b/pywrap/pcipywrap.c
index dca5973..391bdf4 100644
--- a/pywrap/pcipywrap.c
+++ b/pywrap/pcipywrap.c
@@ -281,7 +281,7 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist
{
PyObject* values = PyList_New(0);
-
+
for (int j = 0; listItem.values[j].name; j++)
{
PyObject* valuesItem = PyDict_New();
@@ -306,9 +306,9 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist
if(listItem.values[j].description)
{
pcilib_pydict_set_item(valuesItem,
- PyString_FromString("description"),
- PyString_FromString(listItem.values[j].description));
-
+ PyString_FromString("description"),
+ PyString_FromString(listItem.values[j].description));
+
}
pcilib_pylist_append(values, valuesItem);
}
@@ -319,7 +319,7 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist
}
return pylistItem;
-
+
}
Pcipywrap *new_Pcipywrap(const char* fpga_device, const char* model)
@@ -512,101 +512,101 @@ PyObject* Pcipywrap_get_property_list(Pcipywrap *self, const char* branch)
PyObject* Pcipywrap_read_dma(Pcipywrap *self, unsigned char dma, size_t size)
{
- int err;
- void* buf = NULL;
- size_t real_size;
-
- err = pcilib_read_dma(self->ctx, dma, (uintptr_t)NULL, size, buf, &real_size);
- if(err)
- {
- set_python_exception("Failed pcilib_read_dma", err);
- return NULL;
- }
-
-
- PyObject* py_buf = PyByteArray_FromStringAndSize((const char*)buf, real_size);
- if(buf)
- free(buf);
-
- return py_buf;
+ int err;
+ void* buf = NULL;
+ size_t real_size;
+
+ err = pcilib_read_dma(self->ctx, dma, (uintptr_t)NULL, size, buf, &real_size);
+ if(err)
+ {
+ set_python_exception("Failed pcilib_read_dma", err);
+ return NULL;
+ }
+
+
+ PyObject* py_buf = PyByteArray_FromStringAndSize((const char*)buf, real_size);
+ if(buf)
+ free(buf);
+
+ return py_buf;
}
PyObject* Pcipywrap_lock_global(Pcipywrap *self)
{
- int err;
-
- err = pcilib_lock_global(self->ctx);
- if(err)
- {
- set_python_exception("Failed pcilib_lock_global");
- return NULL;
- }
-
- return PyInt_FromLong((long)1);
+ int err;
+
+ err = pcilib_lock_global(self->ctx);
+ if(err)
+ {
+ set_python_exception("Failed pcilib_lock_global");
+ return NULL;
+ }
+
+ return PyInt_FromLong((long)1);
}
void Pcipywrap_unlock_global(Pcipywrap *self)
{
- pcilib_unlock_global(self->ctx);
- return;
+ pcilib_unlock_global(self->ctx);
+ return;
}
-PyObject* Pcipywrap_lock(Pcipywrap *self, const char *lock_id)
-{
- pcilib_lock_t* lock = pcilib_get_lock(self->ctx,
- PCILIB_LOCK_FLAGS_DEFAULT,
- lock_id);
- if(!lock)
- {
- set_python_exception("Failed pcilib_get_lock");
- return NULL;
- }
-
-
- int err = pcilib_lock(lock);
- if(err)
- {
- set_python_exception("Failed pcilib_lock");
- return NULL;
- }
-
- return PyInt_FromLong((long)1);
+PyObject* Pcipywrap_lock(Pcipywrap *self, const char *lock_id)
+{
+ pcilib_lock_t* lock = pcilib_get_lock(self->ctx,
+ PCILIB_LOCK_FLAGS_DEFAULT,
+ lock_id);
+ if(!lock)
+ {
+ set_python_exception("Failed pcilib_get_lock");
+ return NULL;
+ }
+
+
+ int err = pcilib_lock(lock);
+ if(err)
+ {
+ set_python_exception("Failed pcilib_lock");
+ return NULL;
+ }
+
+ return PyInt_FromLong((long)1);
}
PyObject* Pcipywrap_try_lock(Pcipywrap *self, const char *lock_id)
{
- pcilib_lock_t* lock = pcilib_get_lock(self->ctx,
- PCILIB_LOCK_FLAGS_DEFAULT,
- lock_id);
+ pcilib_lock_t* lock = pcilib_get_lock(self->ctx,
+ PCILIB_LOCK_FLAGS_DEFAULT,
+ lock_id);
if(!lock)
- {
- set_python_exception("Failed pcilib_get_lock");
- return NULL;
- }
-
- int err = pcilib_try_lock(lock);
- if(err)
- {
- set_python_exception("Failed pcilib_try_lock");
- return NULL;
- }
-
- return PyInt_FromLong((long)1);
+ {
+ set_python_exception("Failed pcilib_get_lock");
+ return NULL;
+ }
+
+ int err = pcilib_try_lock(lock);
+ if(err)
+ {
+ set_python_exception("Failed pcilib_try_lock");
+ return NULL;
+ }
+
+ return PyInt_FromLong((long)1);
}
PyObject* Pcipywrap_unlock(Pcipywrap *self, const char *lock_id)
{
- pcilib_lock_t* lock = pcilib_get_lock(self->ctx,
- PCILIB_LOCK_FLAGS_DEFAULT,
- lock_id);
+ pcilib_lock_t* lock = pcilib_get_lock(self->ctx,
+ PCILIB_LOCK_FLAGS_DEFAULT,
+ lock_id);
if(!lock)
- {
- set_python_exception("Failed pcilib_get_lock");
- return NULL;
- }
-
- pcilib_unlock(lock);
- return PyInt_FromLong((long)1);
+ {
+ set_python_exception("Failed pcilib_get_lock");
+ return NULL;
+ }
+
+ pcilib_unlock(lock);
+ return PyInt_FromLong((long)1);
}
diff --git a/pywrap/test_pcipywrap.py b/pywrap/test_pcipywrap.py
index 91780ec..809a81a 100644
--- a/pywrap/test_pcipywrap.py
+++ b/pywrap/test_pcipywrap.py
@@ -87,10 +87,10 @@ class test_pcipywrap():
print self.pcilib.get_property_list(self.branch)
print self.pcilib.get_register_info(self.register)
print self.pcilib.get_registers_list();
- print self.pcilib.read_register(self.register)
print self.pcilib.write_register(val, self.register)
- print self.pcilib.get_property(self.prop)
+ print self.pcilib.read_register(self.register)
print self.pcilib.set_property(val, self.prop)
+ print self.pcilib.get_property(self.prop)
except KeyboardInterrupt:
print 'testing done'
pass