Sending data via TCP from Matlab to c
Afficher commentaires plus anciens
Hi all I am trying to send data from matlab to c. In order to do so I am using the function fwrite.
My question is : how to send it as an struct ? for example
Msg.Size = int32(8);
Msg.Data = '12345678';
t = tcpip('10.1.4.34');
set(t, 'RemotePort', 55555)
set(t, 'InputBufferSize', 30000)
fopen(t)
It works OK When I execute the following
fwrite(t,Msg.Size,'int32');
fwrite(t,Msg.Data,'char');
How can I send the whole struct Msg ?
Any help will be appreciated.
Réponse acceptée
Plus de réponses (2)
Walter Roberson
le 16 Fév 2011
0 votes
You could loop through the fieldnames of the structure, detecting the type of the field and writing in the appropriate format, along with enough meta-information to be able to reconstruct it on the other side.
There are, however, some things that this cannot be applied to, such as certain kinds of objects. And sending a cell array of mixed data types gets you in to a mess.
Sometimes the easiest thing to do is to save() your data to a .mat file, transmit the .mat file as binary, write it out to disk, and load() it on the other side.
My understanding is that there are "serialize" methods for a number of objects, but it is not well documented as to how to access them.
zohar
le 16 Fév 2011
0 votes
Catégories
En savoir plus sur Instrument Control Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!