Read data from TCP/IP from labview

3 views (last 30 days)
g
g on 25 Feb 2014
Edited: Scotland on 27 Nov 2015
I send the data using a tcpip connetion in labview. The data I write looks like this(4 bytes): If I wanted to send decimal 16, it would send the string '0000 0010' in labview. Now I want to read this value ('0000 0010') in matlab. I have tried:
fread(Client,4)
So this would give a 4x1 array of [0;0;0;16].
I have found a way of converting this to the hex format and then into the decimal format i need, but i think there is a better way. any suggestions?
val = fread(Client,4);
val = dec2hex(val );
val = transpose(val );
val = reshape(val ,1,8);
val = val (find(~isspace(val )));
val = hex2dec(val );
I should mention that in labview if I want to receive the data all I do is use a typecast function (to convert the string into the equivalent decimal valule). I know there is cast and typecast in matlab, but I couldnt get the good results with them.
THanks!!

Answers (0)

Community Treasure Hunt

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

Start Hunting!