How can I send and receive data to MATLAB from a C++ application?
8 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
Seth Popinchalk
2011-1-22
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 个评论
Seth Popinchalk
2011-1-22
This is a high-level answer. If you need further help with implementation, try asking smaller questions about the details.
Walter Roberson
2011-2-7
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!