Created
December 9, 2017 14:37
-
-
Save nag92/cf6d47dff49db2f5af2730a047e16fdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear all | |
obj = udp('localhost',9876) ; | |
obj.ByteOrder = 'littleEndian'; | |
fopen(obj) | |
data = zeros(15,1,'single'); | |
time = 100; | |
for i = 1:2 | |
packet = single2bytes(37,data); | |
fwrite(obj,packet,'uint8'); | |
tic | |
A = fread(obj,1) | |
toc | |
end | |
function thing = single2bytes(code, val) | |
% Create the array of bytes | |
returnArray=uint8(zeros((length(val)+1)*4,1)); | |
%Create the 4 byte control code | |
tmp1 = typecast(int32(code), 'uint8'); | |
for j=1:4 | |
returnArray(j)=tmp1(j); | |
end | |
%disp('Code: ') | |
%disp(code) | |
%disp(tmp1) | |
for i=1:length(val) | |
%Convert value to a 4 byte array | |
tmp = typecast(single(val(i)), 'uint8'); | |
%Copy 4 byte data to the main array | |
for j=1:4 | |
returnArray((i*4)+j)=tmp(j); | |
end | |
end | |
thing = returnArray; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment