How can I send and receive data to MATLAB from a C++ application?

10 visualizaciones (últimos 30 días)
Eric
Eric el 20 de En. de 2011
I need to send data and receive data from a C++ application from MATLAB (and later use that code in Simulink). The C++ program use a API to control a drone to handle the WiFi connection. All the common are done by the API, seen command, read sensor etc. But it MUST use a multi-threaded architecture to work.
I think .mex file won't work for that type of application, if I understand it only call subroutine, but I might be wrong.
I have also looked at the Engine API that allow a C++ program to call MATLAB code. But I need the MATLAB code to control the iteration. I am not sure if it can work well with Simulink or if it will just be really ugly.
At last I have think of using TCP/IP to communicate with the C++ application.
Anyone have suggestion to how to implement that?

Respuestas (2)

Seth Popinchalk
Seth Popinchalk el 22 de En. de 2011
To start, write a MATLAB MEX function that you can call to send and receive commands from MATLAB to the C++ program through whatever API might be available. Once this is working, you should be able to incorporate similar code into an S-function. The S-function can then run as part of a Simulink model to control the drone through the C++ program.
  1 comentario
Seth Popinchalk
Seth Popinchalk el 22 de En. de 2011
This is a high-level answer. If you need further help with implementation, try asking smaller questions about the details.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 7 de Feb. de 2011
Matlab has a single control thread; even if you were to use the Parallel Processing Toolkit, it is doubtful that it would be considered a "multi-threaded architecture" for your purposes.
In order to use TCP/IP with Matlab, you need the Instrument Control Toolbox, or else you need to use the Matlab File Exchange contribution "tcpudpip" (which uses the Netcat libraries.) When I look around a bit, I do not find confirmation that Netcat is multi-threaded; the source would have to be examined.

Categorías

Más información sobre Application Deployment en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by