- Define the structures in MATLAB using "libstruct"
- Create pointer to those structures using "libpointer"
- Now call the function with created pointers like
Using functions from C++ in MATLAB
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I'll start off by showing a function that I have in C++.
int __stdcall UDP_GigE_getData(unsigned char *packetType, T_GVSP_LEADER_PACKET *leader, T_GVSP_PAYLOAD_PACKET *payloads,
T_GVSP_TRAILER_PACKET *trailer, T_GVSP_ALL_IN_PACKET *allInOne)
You should know that all variables with type T_GVSP_... are struct types defined in C. Now, I want to use the calllib function in MATLAB to call the above function. Something like,
response = calllib( 'UDP_GigE' , 'UDP_GigE_getData' , packetType, leader, payloads, trailer, allInOne)
The problem is, I do not know how put those struct pointers in the calllib function, since MATLAB's pointer functionality is not to obvious to me. Does anyone have any ideas on how to put pointers into the calllib function correctly?
Thanks
0 Kommentare
Antworten (1)
Anjaneyulu Bairi
am 1 Nov. 2024
Hi,
To call a C++ function from MATLAB using "calllib", you need to ensure that the data types in MATLAB match those expected by the C++ function. In your case, you need to handle pointers to structures, which requires some setup in MATLAB.
calllib('UDP_GigE' , 'UDP_GigE_getData' , packetType, leaderptr, payloadsptr, trailerptr, allInOneptr)
You can refer the below documentation links to know more information on "libstruct","libpointer" and for few examples:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Call C from MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!