3

I have a sensor value which can be read using the C++ only because it was implemented using it , I want to pass location value (two float variable) of one sensor to Python. I have been reading a lot and I found shared memory , piping and more any idea what is the best way to do it ?

1
  • What device are you working with? Maybe there's a python lib somewhere that will do the task just like the C++ one does? Commented Aug 14, 2016 at 16:31

3 Answers 3

4

It's not clear from your question whether this is a standalone C++ program or a library.

If it's a standalone program, use the subprocess module to invoke it and read its output.

If it's a library, use Cython to construct a Python extension module that wraps the library. (It is not necessary to use Cython; Python extensions can be written by hand. But it will make the task significantly easier.)

Sign up to request clarification or add additional context in comments.

Comments

0

@ramtha Z28 with the limited information you provided... do you have access to the C++ code itself or are you calling a DLL? You can wrap a function in Cython easily to communicate between Python and C++ if you have the source code. Wrap all the C++ blocks in cpdef statements which are accessible from Python and C++. Example files are here which show you how to include a C program in Cython and interact with Python: https://github.com/cythonbook/examples/tree/master/07-wrapping-c/01-wrapping-c-functions-mt-random

If it is a DLL you have to declare all the constants, functions, return values. Actually this example may be something like what you're using already: http://people.seas.harvard.edu/~krussell/html-tutorial/wrap_dll.html

Comments

0

I'm not familiar with python however, a simple approach is to use some communication protocols such as serial ports or udp which is a network protocol. For real-time applications, UDP protocol is a preferable choice.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.