Is it possible to send different types of data via UDP?

2 views (last 30 days)
I am trying to send an array of data composed of both double() and uint32() values via UDP as the receiving application requires such a configuration. The size of the data packet should become 40 bytes eventually (4 doubles and 2 ints) However when I inspect the data packets manually the length of the data in the UDP packet drops to 24 bytes when I try to send both types of data.
Does Matlab automatically convert all the data into uint32() data as soon as I try to send both data types?
Thank you all in advance, Bas

Answers (1)

Bas Holten
Bas Holten on 7 Feb 2017
I found a (rather sloppy) workaround myself by creating a dummy double precision value to fool the receiving application.
I1 = uint32(x);
I2 = uint32(y);
% Create two 8 hexadecimal byte strings for each of them
I1_hex = dec2hex(I1,8);
I2_hex = dec2hex(I2,8);
% Combine them into a single 16 hexadecimal byte string
hex_string = strcat(I2_hex,I1_hex); % switched order of the ints to comply with the endianness of the readout
% Create a dummy value to send via UDP
dummy = hex2num(hex_string);
This seems to work for the application. As this interface only serves as a testing application it is not terrible that it uses a workaround rather than a solution.
  2 Comments
Dmitriy Makovkin
Dmitriy Makovkin on 10 May 2018
Bas, thanks for answering your own question - it has helped me with my own application. Do you know whether it matters if I1 & I2 are declared as uint32? It looks like no matter the type, the dec2hex(I1,8) command will always produce a 16 byte variable. Also, in your example, what is the significance of using 2 variables of the same type? How would the code change if I were interested in sending a uint32, uint16, and a uint8 in one string instead of 2 uint32s?
Walter Roberson
Walter Roberson on 10 May 2018
dec2hex requires that its input have positive integral value (but not necessarily positive integer data type), and it outputs the hex representation of that integer.

Sign in to comment.

Categories

Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!